#include "RTE_GPIO.h"
#include "Key.h"
#include "Display_Info.h"
#include "Check_Ctrl.h"
#include "CAN_APP.h"
extern uint8_t resetflag;
void Key_Operation_SW5(Key_Event_en_t enKeyEvent)
{
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
        // Display_Add( );
        // Display_TFT_Clear( );  
        Display_TFT_Clear_UID();
        if(change > 0)
        {
            change--;
            UUIDX -= 10;
        }
        else
        {
            change = 13;
            UUIDX = 197;
        }
        // Display_TFT_Clear();
    }
    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_Add( );
            // Display_TFT_Clear( );  
        }  
             
        
    }
    else
    {
    }
}
void Key_Operation_SW4(Key_Event_en_t enKeyEvent)
{
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
        
        if(UIDNumber2[change] < 9)
        {
            UIDNumber2[change]++;
        }
        else
        {
            UIDNumber2[change] = 0;
        }
        // if ( (LED_Waring == 1) || (UDS_Warning_Voltage ==1))
        // {
        //     ;
        // }
        // else
        // {
        //     // Display_Sub( );
        //     // Display_TFT_Clear( );  
        // }  
             
    }
    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 )
    {
    }
    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 )
    {
        
        
    }
    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)
{
        /*清零ODO*/
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
        // MENU_CHECK_STEP_ADD( );
        // if(MENU_CHECK_STEP >= 16)
        // {
        //     MENU_CHECK_STEP = 0;
        // }
        // else
        // {
        //     MENU_CHECK_STEP++;
        // }

        if(MENU_CHECK_STEP == 0)
        {
            MENU_CHECK_STEP = 16;
        }
        else if(MENU_CHECK_STEP == 16)
        {
            MENU_CHECK_STEP = 1;
        }
        else
        {
            MENU_CHECK_STEP++;
        }
    }
    else if ( enKeyEvent == KEY_EVENT_LONG_PRESS )
    {
    }
    else if ( enKeyEvent == KEY_EVENT_SUPER_LONG_PRESS )
    {
        if ( LED_Waring == 1 || (UDS_Warning_Voltage ==1))
        {
            ;
        }
        else
        {
            MENU_CHECK_STEP_ADD( );
        }  
    }
    else
    {
    }
}
void Key_Operation_SW1(Key_Event_en_t enKeyEvent)
{
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
        writeflag = 1;
        zhenduanstep = 11;
        UIDStep = 0;
        writebeing = 1;
        // if(UIDNumber2[change] < 9)
        // {
        //     UIDNumber2[change]++;
        // }
        // else
        // {
        //     UIDNumber2[change] = 0;
        // }
        Display_TFT_Clear_UID2();
    }
    else if (( enKeyEvent == KEY_EVENT_LONG_PRESS ) && (MENU_CHECK_STEP == 10))
    {

    }
}

/*-------------------------------------------------*/
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 ( SW4 == 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;
}

/*---------------------------------------------------------------------------------------*/
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+

};
