#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"

uint8_t Confirmkeycount;
void Key_Operation_SW5(Key_Event_en_t enKeyEvent)       //下一步
{
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
        if(firstpowerflag == 2)
        {
            if(saomafinish == 3)
            { 
                zhenduansendStep = 0;
                zhenduanflag = 0;
                MENU_CHECK_STEP = 0;
                saomafinish = 4;
            }
            else if(saomafinish == 4)
            {
                MENU_CHECK_STEP_ADD();
            }
        }
    }
    else if ( enKeyEvent == KEY_EVENT_LONG_PRESS )
    {
        
        if(firstpowerflag == 2)
        {
            if(AutoFlag == 1)
            {
                AutoFlag = 0;
            }
            else
            {
                AutoFlag = 1;
            }
        }
    }
    else
    {
    }
}
void Key_Operation_SW4(Key_Event_en_t enKeyEvent)       //上一步
{
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
        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 )
    {
        // upkeyflag = 1;      //按键加
        if(firstpowerflag == 2)
        {
            // if(zhenduanflag == 1)
            // {
            if(saomafinish == 0)
            {
                zhenduansendStep = 5;
                zhenduanflag = 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 )
    {
        // zhenduanflag = 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 )
    {
        if(LINE_OUT_NEG_01 == 1U)       //上下ACC电
        {
            LINE_OUT_NEG_01 = 0U;
            Auto_ONOFF = 3;
        }
        else
        {
            LINE_OUT_NEG_01 = 1U;
            Auto_ONOFF = 0;
        }
        // downkeyflag = 1;        //数字减
    }
    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(MENU_CHECK_STEP == 14)
        // {
        //     Confirmkeyflag = 1;     //确认
        //     Confirmkeycount++;
        //     if(Confirmkeycount >= 5)
        //     {
        //         mimayanzhengjieguo = 1;
        //         Confirmkeycount = 0;
        //         MENU_CHECK_STEP_ADD();
        //     }
        // }
        // else
        // {
        //     Confirmkeycount == 0;
        //     mimayanzhengjieguo = 0;
        // }
        if(firstpowerflag == 2)
        {
            if(clearOdoFlag == 0)
            {
                clearOdoFlag = 1;
            }
            else
            {
                queren = 1;
            }
        }
    }
    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
    {
    }
}

void Key_Operation_SW6(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
    {

    }
}

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

Key_Real_Status_en_t Key_Real_sw6(void)
{

    Key_Real_Status_en_t enKeyRealStatus = KEY_LINE_LOOSEN;

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

void Key_Operation_SW10(Key_Event_en_t enKeyEvent)
{
        /*清零ODO*/
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
        if(BlueTooth == 0)
        {
            BlueTooth = 1;
        }
        else
        {
            BlueTooth = 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+
    {KEY_TYPE_LINE, Key_Real_sw6, Key_Operation_SW6},    //SW1+
};
