#define POWER_KEY_PORT GPIOA
#define POWER_KEY_PIN GPIO_Pin_1
#define GET_POWER_KEY GPIO_ReadInputDataBit(POWER_KEY_PORT, POWER_KEY_PIN)
#define FUN_KEY_PORT GPIOA
#define FUN_KEY_PIN GPIO_Pin_6
#define GET_FUN_KEY GPIO_ReadInputDataBit(FUN_KEY_PORT, FUN_KEY_PIN)
#define MEM_KEY_PORT GPIOA
#define MEM_KEY_PIN GPIO_Pin_7
#define GET_MEM_KEY GPIO_ReadInputDataBit(MEM_KEY_PORT, MEM_KEY_PIN)
//
#define CNT_SHORT 5
#define CNT_LONG 50
#define NONE_PRESS 0x00
#define POWER_PRESS 0x01
#define FUN_PRESS 0x02
#define MEM_PRESS 0x04
//
struct MeasSet_type MeasSet;
struct StoreSet_type StoreSet;
struct LookStoreSet_type LookStoreSet;
struct RpmValue_type RpmValue;
//
enum KeyStatus_type
{
RESET_KEY_CHECK = 0,
POWER_LONG_CHECK,
FUN_LONG_CHECK,
MEM_LONG_CHECK,
ERROR_KEY
}key_status;
static struct
{
unsigned ShortPower : 1;
unsigned LongPower : 1;
unsigned ReleasePower : 1;
unsigned ShortMeas0 : 1;
unsigned ReleaseMeas0 : 1;
unsigned ShortMeas1 : 1;
unsigned ReleaseMeas1 : 1;
unsigned ShortMode : 1;
unsigned LongMode : 1;
unsigned ShortMaxMin : 1;
unsigned LongMaxMin : 1;
unsigned ShortStore : 1;
unsigned LongStore : 1;
unsigned ShortUnit : 1;
unsigned LongUnit : 1;
}KeyFlag;
//
//static enum KeyStatus_type key_status;
void KEY_SCAN(void)
{
unsigned char buff_key;
static unsigned char cnt_press[3];
static unsigned int cnt_auto_off;
buff_key = NONE_PRESS;
if(GET_POWER_KEY == 0)
{
buff_key |= POWER_PRESS;
}
if(GET_FUN_KEY == 0)
{
buff_key |= FUN_PRESS;
}
if(GET_MEM_KEY == 0)
{
buff_key |= MEM_PRESS;
}
switch(key_status)
{
case RESET_KEY_CHECK:
{
if(buff_key == POWER_PRESS)
{
if(++cnt_press[0] >= CNT_SHORT)
{
cnt_press[0] = 0;
key_status = POWER_LONG_CHECK;
KeyFlag.ShortPower = 1;
}
}
else if(buff_key == FUN_PRESS)
{
if(++cnt_press[1] >= CNT_SHORT)
{
cnt_press[1] = 0;
key_status = FUN_LONG_CHECK;
KeyFlag.ShortMode = 1;
}
}
else if(buff_key == MEM_PRESS)
{
if(++cnt_press[2] >= CNT_SHORT)
{
cnt_press[2] = 0;
key_status = MEM_LONG_CHECK;
KeyFlag.ShortMaxMin = 1;
}
}
else
{
cnt_press[0] = 0;
cnt_press[1] = 0;
cnt_press[2] = 0;
}
}break;
case POWER_LONG_CHECK:
{
if(buff_key == POWER_PRESS)
{
if(cnt_press[0] < CNT_LONG)
{
cnt_press[0] ++;
if(cnt_press[0] == CNT_LONG)
{
KeyFlag.LongPower = 1;
}
}
}
else if(buff_key == NONE_PRESS)
{
if(cnt_press[0] < CNT_LONG)
{
}
cnt_press[0] = 0;
key_status = RESET_KEY_CHECK;
KeyFlag.ReleasePower = 1;
}
else
{
key_status = ERROR_KEY;
}
}break;
case FUN_LONG_CHECK:
{
if(buff_key == FUN_PRESS)
{
if(cnt_press[1] < CNT_LONG)
{
cnt_press[1] ++;
if(cnt_press[1] == CNT_LONG)
{
}
}
}
else if(buff_key == NONE_PRESS)
{
if(cnt_press[1] < CNT_LONG)
{
}
cnt_press[1] = 0;
key_status = RESET_KEY_CHECK;
}
else
{
key_status = ERROR_KEY;
}
}break;
case MEM_LONG_CHECK:
{
if(buff_key == MEM_PRESS)
{
if(cnt_press[2] < CNT_LONG)
{
cnt_press[2] ++;
if(cnt_press[2] == CNT_LONG)
{
}
}
}
else if(buff_key == NONE_PRESS)
{
if(cnt_press[2] < CNT_LONG)
{
}
cnt_press[2] = 0;
key_status = RESET_KEY_CHECK;
}
else
{
key_status = ERROR_KEY;
}
}break;
case ERROR_KEY:
{
if(buff_key == NONE_PRESS)
{
key_status = RESET_KEY_CHECK;
}
}break;
default: key_status = RESET_KEY_CHECK; break;
}
// if(buff_key == NONE_PRESS)
// {
// if(++cnt_auto_off >= 7500)
// {
// cnt_auto_off = 0;
// POWER_OFF;
// }
// }
// else
// {
// cnt_auto_off = 0;
// }
} |