/***************************************
* function : check key value
* input: key_table index key_step press_10ms_cnt
*
***************************************/
/* 按键表格 */
const mower_key_struct key_table[KEY_NUM_MAX]=
{
/* 0*/{K_POWER, KEY_ATTR_LONG1, K_POWER},
/* 1*/{K_NUM_0, KEY_ATTR_CONTINUE, K_NULL},
/* 2*/{K_NUM_1, KEY_ATTR_SHORT, K_NULL},
/* 3*/{K_NUM_2, KEY_ATTR_SHORT, K_NULL},
/* 4*/{K_NUM_3, KEY_ATTR_SHORT, K_NULL},
/* 5*/{K_NUM_4, KEY_ATTR_SHORT, K_NULL},
/* 6*/{K_NUM_5, KEY_ATTR_SHORT, K_NULL},
/* 7*/{K_NUM_6, KEY_ATTR_SHORT, K_NULL},
/* 8*/{K_NUM_7, KEY_ATTR_SHORT, K_NULL},
/* 9*/{K_NUM_8, KEY_ATTR_SHORT, K_NULL},
/*10*/{K_NUM_9, KEY_ATTR_SHORT, K_NULL},
/*11*/{K_HOME, KEY_ATTR_SHORT, K_NULL},
/*12*/{K_RETURN, KEY_ATTR_SHORT, K_NULL},
/*13*/{K_SETUP, KEY_ATTR_SHORT, K_NULL},
/*14*/{K_OK, KEY_ATTR_SHORT, K_NULL},
/*15*/{K_UP, KEY_ATTR_SHORT, K_NULL},
/*16*/{K_DOWN, KEY_ATTR_SHORT, K_NULL},
/*17*/{K_DOWN, KEY_ATTR_SHORT, K_NULL},
/*18*/{K_DOWN, KEY_ATTR_SHORT, K_NULL},
/*19*/{K_DOWN, KEY_ATTR_SHORT, K_NULL},
/*20*/{K_DOWN, KEY_ATTR_SHORT, K_NULL},
/*21*/{K_DOWN, KEY_ATTR_SHORT, K_NULL},
/*22*/{K_DOWN, KEY_ATTR_SHORT, K_NULL},
/*23*/{K_DOWN, KEY_ATTR_SHORT, K_NULL},
/*24*/{K_DOWN, KEY_ATTR_SHORT, K_NULL},
};
u8 key_check(const mower_key_struct *key_table,u8 *pre_index,u8 index,u8 *key_step,volatile u16 *press_10ms_cnt)
{
u8 key_value = K_NULL;
key_long_flag = 0;
if(index != INDEX_CURRENT_INVALID)
{
if((*pre_index == INDEX_CURRENT_INVALID) || *pre_index != index)
{
*press_10ms_cnt = 0;
*key_step = 0;
*pre_index = index;
}
else if(*press_10ms_cnt != KEY_PRESS_TIME_LOCK)
{
if(((mower_key_struct *)key_table)[*pre_index].attribute == KEY_ATTR_SHORT)
{
if(*press_10ms_cnt >= KEY_PRESS_TIME_SHORT)
{
key_value = ((mower_key_struct *)key_table)[*pre_index].short_value;
*press_10ms_cnt = KEY_PRESS_TIME_LOCK;
#ifdef CUSTOMER_SERIAL_DEBUG
rt_kprintf("\r\n...Key press short..key_value=0x%2x...",key_value);
rt_kprintf("\r\n...Key press short..*press_10ms_cnt=0x%2x...",*press_10ms_cnt);
#endif
}
}
else if(((mower_key_struct *)key_table)[*pre_index].attribute == KEY_ATTR_CONTINUE)
{
if(*key_step == 0)
{
if(*press_10ms_cnt >= KEY_PRESS_TIME_SHORT)
{
key_value = ((mower_key_struct *)key_table)[*pre_index].short_value;
*press_10ms_cnt = 0;
*key_step = 1;
#ifdef CUSTOMER_SERIAL_DEBUG
rt_kprintf("\r\n...Key press continue 0..key_value=0x%2x...",key_value);
#endif
}
}
else if(*key_step == 1)
{
if(*press_10ms_cnt >= KEY_PRESS_TIME_CONTINUE)
{
key_value = ((mower_key_struct *)key_table)[*pre_index].short_value;
*press_10ms_cnt = 0;
*key_step = 2;
#ifdef CUSTOMER_SERIAL_DEBUG
rt_kprintf("\r\n...Key press continue 1..key_value=0x%2x...",key_value);
#endif
}
}
else if(*key_step == 2)
{
if(*press_10ms_cnt >= KEY_PRESS_TIME_CONTINUE_SECOND)
{
key_value = ((mower_key_struct *)key_table)[*pre_index].short_value;
*press_10ms_cnt = 0;
// 连续按着就会一直进这里赋值按键值
//*key_step = 2;
#ifdef CUSTOMER_SERIAL_DEBUG
rt_kprintf("\r\n...Key press continue 2..key_value=0x%2x...",key_value);
#endif
}
}
}
else if(((mower_key_struct *)key_table)[*pre_index].attribute == KEY_ATTR_LONG1)
{
if(*press_10ms_cnt >= KEY_PRESS_TIME_LONG1)
{
key_value = ((mower_key_struct *)key_table)[*pre_index].short_value;
*press_10ms_cnt = KEY_PRESS_TIME_LOCK;
key_long_flag = 1;
#ifdef CUSTOMER_SERIAL_DEBUG
rt_kprintf("\r\n...Key long press 1..key_value=0x%2x...",key_value);
#endif
}
}
else if(((mower_key_struct *)key_table)[*pre_index].attribute == KEY_ATTR_LONG2)
{
if(*press_10ms_cnt >= KEY_PRESS_TIME_LONG2)
{
key_value = ((mower_key_struct *)key_table)[*pre_index].short_value;
*press_10ms_cnt = KEY_PRESS_TIME_LOCK;
key_long_flag = 1;
#ifdef CUSTOMER_SERIAL_DEBUG
rt_kprintf("\r\n...Key long press 2..key_value=0x%2x...",key_value);
rt_kprintf("\r\n...Key long press 2..*press_10ms_cnt=0x%2x...",*press_10ms_cnt);
#endif
}
}
}
}
else
{
if((*pre_index != INDEX_CURRENT_INVALID) && *press_10ms_cnt != KEY_PRESS_TIME_LOCK)
{
if(((mower_key_struct *)key_table)[*pre_index].attribute == KEY_ATTR_LONG1
|| ((mower_key_struct *)key_table)[*pre_index].attribute == KEY_ATTR_LONG2)
{
if(*press_10ms_cnt >= KEY_PRESS_TIME_SHORT)
{
key_value = ((mower_key_struct *)key_table)[*pre_index].short_value;
#ifdef CUSTOMER_SERIAL_DEBUG
rt_kprintf("\r\n...Key release..key_value=0x%2x...",key_value);
#endif
}
}
}
*press_10ms_cnt = 0;
*key_step = 0;
*pre_index = INDEX_CURRENT_INVALID;
}
return key_value;
}
评论12