#include "RTE_GPIO.h"
#include "Key.h"
#include "Display_Info.h"
#include "Check_Ctrl.h"
#include "CAN_APP.h"

uint8_t rightkey;
uint8_t rightkeytime;
uint8_t clear_odo;
void Key_Operation_SW5(Key_Event_en_t enKeyEvent)
{
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
        if(clear_odo == 0)
        {
            key_right = 1;
            rightkey = 1;
        }
    }
    else if ( enKeyEvent == KEY_EVENT_LONG_PRESS )
    {

    }
    else if ( enKeyEvent == KEY_EVENT_SUPER_LONG_PRESS )
    {

    }
    else
    {
        if(clear_odo == 0)
        {
            if(rightkey)
            {
                if(rightkeytime < 10)
                {
                    ;
                }
                else
                {
                    rightkey = 0;
                    rightkeytime = 0;
                }
            }
            else
            {
                key_right = 0;
            }
        }
    }
}
uint8_t leftkey;
uint8_t leftkeytime;
void Key_Operation_SW4(Key_Event_en_t enKeyEvent)
{
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
        if(clear_odo == 0)
        {
            key_left = 1;
            leftkey = 1;
        }
    }
    else if ( enKeyEvent == KEY_EVENT_LONG_PRESS )
    {

    }
    else if ( enKeyEvent == KEY_EVENT_SUPER_LONG_PRESS )
    {

    }
    else
    {
        if(clear_odo == 0)
        {
            if(leftkey)
            {
                if(leftkeytime < 10)
                {
                    ;
                }
                else
                {
                    leftkey = 0;
                    leftkeytime = 0;
                }
            }
            else
            {
                key_left = 0;
            }
        }
    }
}
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
    {
    }
}

uint8_t middlekey;
uint8_t middlekeytime;
void Key_Operation_SW2(Key_Event_en_t enKeyEvent)
{
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
        if(clear_odo == 0)
        {
            key_middle = 1;
            middlekey = 1;
        }
    }
    else if ( enKeyEvent == KEY_EVENT_LONG_PRESS )
    {
        if(MENU_CHECK_STEP == 9)
        {
            clear_odo = 1;
        }
    }
    else if ( enKeyEvent == KEY_EVENT_SUPER_LONG_PRESS )
    {

    }
    else
    {
        if(clear_odo == 0)
        {
            if(middlekey)
            {
                if(middlekeytime < 10)
                {
                    ;
                }
                else
                {
                    middlekey = 0;
                    middlekeytime = 0;
                }
            }
            else
            {
                key_middle = 0;
            }
        }
    }
}
void Key_Operation_SW1(Key_Event_en_t enKeyEvent)
{
    if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
    {
        Meterfieldstep = 0;
        MENU_CHECK_STEP_ADD( );
    }
    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;
}

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

};
