#include "RTE_GPIO.h"
#include "Key.h"
#include "Display_Info.h"
#include "Check_Ctrl.h"
#include "Barcode_Scanner.h"
#include "Task.h"
#include "string.h"
void Key_Operation_SW5(Key_Event_en_t enKeyEvent)
{
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
        // if ( (LED_Waring == 1) || (UDS_Warning_Voltage ==1))
        // {
        //     ;
        // }
        // else
        // {
        //     Display_Add( );
        //     Display_TFT_Clear( );  
        // }  
        if(firstpowerflag == 2)
        {
            MENU_CHECK_STEP_ADD( );   
        }
              
          
        
    }
    else if ( enKeyEvent == KEY_EVENT_LONG_PRESS )
    {
        
        if(firstpowerflag == 2)
        {
            if(AutoFlag == 1)
            {
                AutoFlag = 0;
            }
            else
            {
                AutoFlag = 1;
            }
        }
    }
    // else if ( enKeyEvent == KEY_EVENT_SUPER_LONG_PRESS )
    // {
    //     if ( (LED_Waring == 1) || (UDS_Warning_Voltage ==1))
    //     {
    //         ;
    //     }
    //     else
    //     {
    //         Display_Add( );
    //         Display_TFT_Clear( );  
    //     }  
             
        
    // }
    else
    {
    }
}
void Key_Operation_SW4(Key_Event_en_t enKeyEvent)
{
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
        // if ( (LED_Waring == 1) || (UDS_Warning_Voltage ==1))
        // {
        //     ;
        // }
        // else
        // {
        //     Display_Sub( );
        //     Display_TFT_Clear( );  
        // }  
        if(firstpowerflag == 2)
        {
            MENU_CHECK_STEP_SUB();
        }
    }
    else if ( enKeyEvent == KEY_EVENT_LONG_PRESS )
    {
        
    }
    else if ( enKeyEvent == KEY_EVENT_SUPER_LONG_PRESS )
    {
        if ( (LED_Waring == 1) || (UDS_Warning_Voltage == 1))
        {
            ;
        }
        else
        {
            Display_Sub( );
            Display_TFT_Clear( );  
        }  
             
        
    }
    else
    {
    }
}
void Key_Operation_SW7(Key_Event_en_t enKeyEvent)
{
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
       
        if(firstpowerflag == 2)
        {    
            if(zhenduanflag != 2 && zhenduanflag != 3)
            {
                    zhenduanflag = 2;
            }
            else
            {
                    zhenduanflag = 0;
            }
        }
       
    }
    else if ( enKeyEvent == KEY_EVENT_LONG_PRESS )
    {
    }
    else if ( enKeyEvent == KEY_EVENT_SUPER_LONG_PRESS )
    {
    }
    else
    {
    }
}
void Key_Operation_SW8(Key_Event_en_t enKeyEvent)
{
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
        if(firstpowerflag == 2)
        {
             if(zhenduanflag  != 1)
            {
                zhenduanflag = 1;
            }
            else
            {
                zhenduanflag = 0;
                LINE_OUT_NEG_01 = 1;
                LINE_OUT_NEG_02 = 1;
                LINE_OUT_NEG_03 = 1;
                LINE_OUT_NEG_04 = 1;
                zhenduansendStep = 0;
                // memset(barcode_Msg,0,sizeof(barcode_Msg));

            }
            RS485_TX_finish = 0;
        }
        
    }
    else if ( enKeyEvent == KEY_EVENT_LONG_PRESS )
    {
    }
    else if ( enKeyEvent == KEY_EVENT_SUPER_LONG_PRESS )
    {
    }
    else
    {
    }
}
void Key_Operation_SW2(Key_Event_en_t enKeyEvent)
{
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {

        if(firstpowerflag == 2)
        {
            if(LINE_OUT_NEG_01 == 1U)
            {
                LINE_OUT_NEG_01 = 0U;
                Auto_ONOFF = 3;
            }
            else
            {
                LINE_OUT_NEG_01 = 1U;
                Auto_ONOFF == 0;
            }
        }
    }
    else if ( enKeyEvent == KEY_EVENT_LONG_PRESS )
    {
    }
    else if ( enKeyEvent == KEY_EVENT_SUPER_LONG_PRESS )
    {
    }
    else
    {
    }
}
void Key_Operation_SW3(Key_Event_en_t enKeyEvent)
{
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
        // if(Get_Display_Type( ) == 2)
        // {
        //     MENU_CHECK_STEP_SUB( ); 
        // }
        if(firstpowerflag == 2)
        {
            if(clearOdoFlag == 0)
            {
                clearOdoFlag = 1;
                
            }
            RS485_TX_finish = 0;
            // else
            // {
            //     clearOdoFlag = 0;
            // }
            // queren = 0;
        }
    }
    else if ( enKeyEvent == KEY_EVENT_LONG_PRESS )
    {
    }
    else if ( enKeyEvent == KEY_EVENT_SUPER_LONG_PRESS )
    {
        if(Get_Display_Type( ) == 2)
        {
            MENU_CHECK_STEP_SUB( ); 
        }
    }
    else
    {
    }
}
void Key_Operation_SW1(Key_Event_en_t enKeyEvent)
{
        /*清零ODO*/
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
        if(firstpowerflag == 2)
        {
            if(Auto_ONOFF != 0)
            {
                Auto_ONOFF = 0;
            }
            else
            {
                Auto_ONOFF = 1;
            }
        }
        
    }
    else if ( enKeyEvent == KEY_EVENT_LONG_PRESS )
    {
    }
    else if ( enKeyEvent == KEY_EVENT_SUPER_LONG_PRESS )
    {
        if(Get_Display_Type( ) == 2)
        {
            MENU_CHECK_STEP_ADD( );
        }
    }
    else
    {
    }
}

/*-------------------------------------------------*/
Key_Real_Status_en_t Key_Real_sw5(void)
{

    Key_Real_Status_en_t enKeyRealStatus = KEY_LINE_LOOSEN;
    if ( SW5 == 0U )
    {
        enKeyRealStatus = KEY_LINE_PRESS;
    }
    else
    {
        enKeyRealStatus = KEY_LINE_LOOSEN;
    }
    return enKeyRealStatus;
}
Key_Real_Status_en_t Key_Real_sw4(void)
{

    Key_Real_Status_en_t enKeyRealStatus = KEY_LINE_LOOSEN;

    if ( SW4 == 0U )
    {
        enKeyRealStatus = KEY_LINE_PRESS;
    }
    return enKeyRealStatus;
}
Key_Real_Status_en_t Key_Real_sw7(void)
{

    Key_Real_Status_en_t enKeyRealStatus = KEY_LINE_LOOSEN;

    if ( SW7 == 0U )
    {
        enKeyRealStatus = KEY_LINE_PRESS;
    }
    else
    {
        enKeyRealStatus = KEY_LINE_LOOSEN;
    }
    return enKeyRealStatus;
}
Key_Real_Status_en_t Key_Real_sw8(void)
{

    Key_Real_Status_en_t enKeyRealStatus = KEY_LINE_LOOSEN;

    if ( SW8 == 0U )
    {
        enKeyRealStatus = KEY_LINE_PRESS;
    }
    return enKeyRealStatus;
}
Key_Real_Status_en_t Key_Real_sw2(void)
{

    Key_Real_Status_en_t enKeyRealStatus = KEY_LINE_LOOSEN;

    if ( SW2 == 0U )
    {
        enKeyRealStatus = KEY_LINE_PRESS;
    }
    return enKeyRealStatus;
}
Key_Real_Status_en_t Key_Real_sw1(void)
{

    Key_Real_Status_en_t enKeyRealStatus = KEY_LINE_LOOSEN;

    if ( SW1 == 0U )
    {
        enKeyRealStatus = KEY_LINE_PRESS;
    }
    return enKeyRealStatus;
}

Key_Real_Status_en_t Key_Real_sw3(void)
{

    Key_Real_Status_en_t enKeyRealStatus = KEY_LINE_LOOSEN;

    if ( SW3 == 0U )
    {
        enKeyRealStatus = KEY_LINE_PRESS;
    }
    return enKeyRealStatus;
}

Key_Real_Status_en_t Key_Real_sw10(void)
{

    Key_Real_Status_en_t enKeyRealStatus = KEY_LINE_LOOSEN;

    if ( SW10 == 0U )
    {
        enKeyRealStatus = KEY_LINE_PRESS;
    }
    return enKeyRealStatus;
}

void Key_Operation_SW10(Key_Event_en_t enKeyEvent)
{
        /*清零ODO*/
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
        
        if(firstpowerflag == 2)
        {
            Display_TFT_Clear();
            if(connectbleFlag == 0)
            {
                connectbleFlag = 1;
                name1= (devicename) & 0xFF;
                name2 = (devicename >> 8) & 0xFF;
            }
            else
            {
                name1= (devicename) & 0xFF;
                name2 = (devicename >> 8) & 0xFF;
                startONfalg = 0;
                send0x42time = 0;
                bleOFFtoONtime = 0;
                startONfalg = 0;
                startIGONtime = 0;
                recvflag111 = 0;
            }
        }
    }
    else if ( enKeyEvent == KEY_EVENT_LONG_PRESS )
    {
    }
    else if ( enKeyEvent == KEY_EVENT_SUPER_LONG_PRESS )
    {
        connectbleFlag = 0;
    }
    else
    {
    }
}
/*---------------------------------------------------------------------------------------*/
const Key_Attribute_st_t stKeyAttribute [ KEY_NUM_MAX ] = {
    {KEY_TYPE_LINE, Key_Real_sw5, Key_Operation_SW5},    //SW5
    {KEY_TYPE_LINE, Key_Real_sw4, Key_Operation_SW4},    //SW4
    {KEY_TYPE_LINE, Key_Real_sw7, Key_Operation_SW7},
    {KEY_TYPE_LINE, Key_Real_sw8, Key_Operation_SW8},
    {KEY_TYPE_LINE, Key_Real_sw2, Key_Operation_SW2},      //SW2-
    {KEY_TYPE_LINE, Key_Real_sw1, Key_Operation_SW1},    //SW1+
    {KEY_TYPE_LINE, Key_Real_sw10, Key_Operation_SW10},
    {KEY_TYPE_LINE, Key_Real_sw3, Key_Operation_SW3},    //SW1+

};
