#include "RTE_GPIO.h"
#include "Key.h"
#include "Display_Info.h"
#include "Check_Ctrl.h"
#include "CAN_APP.h"
#include "Task.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!=11))
        {
            change--;
            UUIDX =UUIDX-10;
        }
        else if(change==11)
        {
            change=8;
            UUIDX=90;
            
        }
        else
        {
            change = 20;
            UUIDX = 200;
        }      
        
    }
    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((change>11) &&(change<21))
        {
            if(UIDNumber2[change-12] < 9)
            {
                UIDNumber2[change-12]++;
            }
            else
            {
                UIDNumber2[change-12] = 0;
            }
        }
        else if((change>0) && (change<9) && (change!=6) && (change!=5)&&(change!=1))
        {
            if(HWBUFF[change-1]<9)
            {
                 HWBUFF[change-1]++;
            }
            else
            {
                 HWBUFF[change-1]=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 )
    {
       uint8_t s=1;
    }
    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 )
    {
        
       uint8_t s=1;

    }
    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 )
    {
       writeflag = 1;
        writebeing = 1;
        idflag=1;
        Display_TFT_Clear_UID2();
        
    }
    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_SUB( );
        }  
    }
    else
    {
    }
}
void Key_Operation_SW1(Key_Event_en_t enKeyEvent)
{
        /*清零ODO*/
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
       
            MENU_CHECK_STEP_ADD( );
    }
    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)
{
        /*清零ODO*/
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
       
        Key3_flag=1;
    }
    else if ( enKeyEvent == KEY_EVENT_LONG_PRESS )
    {
    }
    else if ( enKeyEvent == KEY_EVENT_SUPER_LONG_PRESS )
    {
    }
    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 ( 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;
}

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;
}

/*---------------------------------------------------------------------------------------*/
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_sw3, Key_Operation_SW3},    //SW1+


};
