|
@@ -12,14 +12,57 @@ uint8 task_btn_id;
|
|
|
#define KEY_DEMO_CYCLE_TIMER 0x0002
|
|
|
|
|
|
int last_release_btn_ind = -1;
|
|
|
+bool isLongCheck = false;
|
|
|
|
|
|
+int temp = 2500;
|
|
|
+int light = 100;
|
|
|
void evt_press_release(int i){
|
|
|
- // 短按抬起
|
|
|
- osal_start_timerEx(task_btn_id, BTN_EVT_TIME_CHECK, TIME_CHECK_TEMP * 3);
|
|
|
- // 500ms 后检测是否
|
|
|
+ // 短按抬起 400ms 后检测是否还处于按下状态
|
|
|
+ if ( isLongCheck = true)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ osal_start_timerEx(task_btn_id, BTN_EVT_TIME_CHECK, TIME_CHECK_TEMP * 4);
|
|
|
last_release_btn_ind = i;
|
|
|
}
|
|
|
|
|
|
+void changeTemp(int i)
|
|
|
+{
|
|
|
+ switch (i)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ temp = temp + 50;
|
|
|
+ if (temp > 6500){ temp = 6500;}
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ temp = temp - 50;
|
|
|
+ if (temp < 2500){ temp = 2500;}
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ temp_set(temp);
|
|
|
+}
|
|
|
+
|
|
|
+void changeLight(int i)
|
|
|
+{
|
|
|
+ switch (i)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ light = light + 5;
|
|
|
+ if (light > 100){ light = 100;}
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ light = light - 5;
|
|
|
+ if (light < 0){ light = 0;}
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ light_set(light);
|
|
|
+}
|
|
|
|
|
|
static void key_press_evt(uint8_t i,key_evt_t key_evt)
|
|
|
{
|
|
@@ -33,10 +76,14 @@ static void key_press_evt(uint8_t i,key_evt_t key_evt)
|
|
|
if (last_release_btn_ind == i)
|
|
|
{
|
|
|
// 按下后再次按下
|
|
|
-
|
|
|
+ isLongCheck = true;
|
|
|
}
|
|
|
- }else {
|
|
|
- osal_stop_timeEx(task_btn_id, BTN_EVT_TIME_CHECK)
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ osal_stop_timerEx(task_btn_id, BTN_EVT_TIME_CHECK);
|
|
|
+ isLongCheck = false;
|
|
|
+ last_release_btn_ind = -1;
|
|
|
+ changeLight(i);
|
|
|
}
|
|
|
|
|
|
#ifdef HAL_KEY_SUPPORT_LONG_PRESS
|
|
@@ -52,6 +99,7 @@ static void key_press_evt(uint8_t i,key_evt_t key_evt)
|
|
|
#ifdef HAL_KEY_SUPPORT_LONG_PRESS
|
|
|
case HAL_KEY_EVT_LONG_RELEASE:
|
|
|
LOG("key(long press release)\n");
|
|
|
+ isLongCheck = false;
|
|
|
break;
|
|
|
#endif
|
|
|
|
|
@@ -125,9 +173,21 @@ uint16 Key_ProcessEvent( uint8 task_id, uint16 events )
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
- if( events & EVT_TIME_CHECK){
|
|
|
- LOG("EVT_TIME_CHECK\n");
|
|
|
- return (events ^ EVT_TIME_CHECK);
|
|
|
+ if( events & BTN_EVT_TIME_CHECK){
|
|
|
+
|
|
|
+ if(last_release_btn_ind != -1 && isLongCheck)
|
|
|
+ {
|
|
|
+ if (
|
|
|
+ key_state.key[last_release_btn_ind].state == HAL_KEY_EVT_PRESS ||
|
|
|
+ key_state.key[last_release_btn_ind].state == HAL_KEY_EVT_LONG_PRESS
|
|
|
+ )
|
|
|
+ {
|
|
|
+ LOG("长按 \n");
|
|
|
+ changeTemp(last_release_btn_ind);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return (events ^ BTN_EVT_TIME_CHECK);
|
|
|
}
|
|
|
|
|
|
return 0;
|