mirror of
https://github.com/murphyzhao/FlexibleButton.git
synced 2023-11-24 09:39:02 +08:00
[fix] 修复 combos 单次的歧义,愿意是想用作连击,但与组合歧义,因此替换为 multiple click
Signed-off-by: zhaojuntao <d2014zjt@163.com>
This commit is contained in:
parent
292c8adab5
commit
5356ee8cc5
@ -142,7 +142,7 @@ static void common_btn_evt_cb(void *arg)
|
||||
{
|
||||
flex_button_t *btn = (flex_button_t *)arg;
|
||||
|
||||
rt_kprintf("id: [%d - %s] event: [%d - %30s] combos: %d\n",
|
||||
rt_kprintf("id: [%d - %s] event: [%d - %30s] repeat: %d\n",
|
||||
btn->id, enum_btn_id_string[btn->id],
|
||||
btn->event, enum_event_string[btn->event],
|
||||
btn->click_cnt);
|
||||
@ -194,7 +194,7 @@ typedef struct flex_button
|
||||
|
||||
uint16_t scan_cnt;
|
||||
uint16_t click_cnt;
|
||||
uint16_t max_combos_click_solt;
|
||||
uint16_t max_multiple_clicks_interval;
|
||||
|
||||
uint16_t debounce_tick;
|
||||
uint16_t short_press_start_tick;
|
||||
@ -215,7 +215,7 @@ typedef struct flex_button
|
||||
| 3 | cb | 是 | 设置按键事件回调,用于应用层对按键事件的分类处理 |
|
||||
| 4 | scan_cnt | 否 | 用于记录扫描次数,按键按下是开始从零计数 |
|
||||
| 5 | click_cnt | 否 | 记录单击次数,用于判定单击、连击 |
|
||||
| 6 | max_combos_click_solt | 是 | 连击间隙,用于判定是否结束连击计数,有默认值 `MAX_COMBOS_CLICK_SOLT` |
|
||||
| 6 | max_multiple_clicks_interval | 是 | 连击间隙,用于判定是否结束连击计数,有默认值 `MAX_MULTIPLE_CLICKS_INTERVAL` |
|
||||
| 7 | debounce_tick | 否 | 消抖时间,暂未使用,依靠扫描间隙进行消抖 |
|
||||
| 8 | short_press_start_tick | 是 | 设置短按事件触发的起始 tick |
|
||||
| 9 | long_press_start_tick | 是 | 设置长按事件触发的起始 tick |
|
||||
@ -225,7 +225,7 @@ typedef struct flex_button
|
||||
| 13 | event | 否 | 用于记录当前按键事件 |
|
||||
| 14 | status | 否 | 用于记录当前按键的状态,用于内部状态机 |
|
||||
|
||||
注意,在使用 `max_combos_click_solt`、`debounce_tick`、`short_press_start_tick`、`long_press_start_tick`、`long_hold_start_tick` 的时候,注意需要使用宏 `**FLEX_MS_TO_SCAN_CNT(ms)**` 将毫秒值转换为扫描次数。因为按键库基于扫描次数运转。示例如下:
|
||||
注意,在使用 `max_multiple_clicks_interval`、`debounce_tick`、`short_press_start_tick`、`long_press_start_tick`、`long_hold_start_tick` 的时候,注意需要使用宏 `**FLEX_MS_TO_SCAN_CNT(ms)**` 将毫秒值转换为扫描次数。因为按键库基于扫描次数运转。示例如下:
|
||||
|
||||
```
|
||||
user_button[1].short_press_start_tick = FLEX_MS_TO_SCAN_CNT(1500); // 1500 毫秒
|
||||
|
@ -24,7 +24,7 @@
|
||||
* Date Author Notes
|
||||
* 2018-09-29 MurphyZhao First add
|
||||
* 2019-08-02 MurphyZhao Migrate code to github.com/murphyzhao account
|
||||
* 2019-12-26 MurphyZhao Refactor code and implement combos
|
||||
* 2019-12-26 MurphyZhao Refactor code and implement multiple clicks
|
||||
*
|
||||
*/
|
||||
|
||||
@ -54,7 +54,7 @@ enum FLEX_BTN_STAGE
|
||||
{
|
||||
FLEX_BTN_STAGE_DEFAULT = 0,
|
||||
FLEX_BTN_STAGE_DOWN = 1,
|
||||
FLEX_BTN_STAGE_COMBOS = 2
|
||||
FLEX_BTN_STAGE_MULTIPLE_CLICK = 2
|
||||
};
|
||||
|
||||
typedef uint32_t btn_type_t;
|
||||
@ -103,7 +103,7 @@ int8_t flex_button_register(flex_button_t *button)
|
||||
{
|
||||
if(curr == button)
|
||||
{
|
||||
return -1; //already exist.
|
||||
return -1; /* already exist. */
|
||||
}
|
||||
curr = curr->next;
|
||||
}
|
||||
@ -117,7 +117,7 @@ int8_t flex_button_register(flex_button_t *button)
|
||||
button->event = FLEX_BTN_PRESS_NONE;
|
||||
button->scan_cnt = 0;
|
||||
button->click_cnt = 0;
|
||||
button->max_combos_click_solt = MAX_COMBOS_CLICK_SOLT;
|
||||
button->max_multiple_clicks_interval = MAX_MULTIPLE_CLICKS_INTERVAL;
|
||||
btn_head = button;
|
||||
|
||||
/**
|
||||
@ -179,8 +179,8 @@ static void flex_button_process(void)
|
||||
|
||||
switch (target->status)
|
||||
{
|
||||
case FLEX_BTN_STAGE_DEFAULT: // stage: default(button up)
|
||||
if (BTN_IS_PRESSED(i)) // is pressed
|
||||
case FLEX_BTN_STAGE_DEFAULT: /* stage: default(button up) */
|
||||
if (BTN_IS_PRESSED(i)) /* is pressed */
|
||||
{
|
||||
target->scan_cnt = 0;
|
||||
target->click_cnt = 0;
|
||||
@ -196,12 +196,12 @@ static void flex_button_process(void)
|
||||
}
|
||||
break;
|
||||
|
||||
case FLEX_BTN_STAGE_DOWN: // stage: button down
|
||||
if (BTN_IS_PRESSED(i)) // is pressed
|
||||
case FLEX_BTN_STAGE_DOWN: /* stage: button down */
|
||||
if (BTN_IS_PRESSED(i)) /* is pressed */
|
||||
{
|
||||
if (target->click_cnt > 0) // combos
|
||||
if (target->click_cnt > 0) /* multiple click */
|
||||
{
|
||||
if (target->scan_cnt > target->max_combos_click_solt)
|
||||
if (target->scan_cnt > target->max_multiple_clicks_interval)
|
||||
{
|
||||
EVENT_SET_AND_EXEC_CB(target,
|
||||
target->click_cnt < FLEX_BTN_PRESS_REPEAT_CLICK ?
|
||||
@ -236,7 +236,7 @@ static void flex_button_process(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
else // is up
|
||||
else /* button up */
|
||||
{
|
||||
if (target->scan_cnt >= target->long_hold_start_tick)
|
||||
{
|
||||
@ -255,15 +255,15 @@ static void flex_button_process(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* swtich to combos stage */
|
||||
target->status = FLEX_BTN_STAGE_COMBOS;
|
||||
/* swtich to multiple click stage */
|
||||
target->status = FLEX_BTN_STAGE_MULTIPLE_CLICK;
|
||||
target->click_cnt ++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case FLEX_BTN_STAGE_COMBOS: // stage: combos
|
||||
if (BTN_IS_PRESSED(i)) // is pressed
|
||||
case FLEX_BTN_STAGE_MULTIPLE_CLICK: /* stage: multiple click */
|
||||
if (BTN_IS_PRESSED(i)) /* is pressed */
|
||||
{
|
||||
/* swtich to button down stage */
|
||||
target->status = FLEX_BTN_STAGE_DOWN;
|
||||
@ -271,7 +271,7 @@ static void flex_button_process(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (target->scan_cnt > target->max_combos_click_solt)
|
||||
if (target->scan_cnt > target->max_multiple_clicks_interval)
|
||||
{
|
||||
EVENT_SET_AND_EXEC_CB(target,
|
||||
target->click_cnt < FLEX_BTN_PRESS_REPEAT_CLICK ?
|
||||
|
@ -24,7 +24,7 @@
|
||||
* Date Author Notes
|
||||
* 2018-09-29 MurphyZhao First add
|
||||
* 2019-08-02 MurphyZhao Migrate code to github.com/murphyzhao account
|
||||
* 2019-12-26 MurphyZhao Refactor code and implement combos
|
||||
* 2019-12-26 MurphyZhao Refactor code and implement multiple clicks
|
||||
*
|
||||
*/
|
||||
|
||||
@ -36,8 +36,8 @@
|
||||
#define FLEX_BTN_SCAN_FREQ_HZ 50 // How often flex_button_scan () is called
|
||||
#define FLEX_MS_TO_SCAN_CNT(ms) (ms / (1000 / FLEX_BTN_SCAN_FREQ_HZ))
|
||||
|
||||
/* Combos slot, default 300ms */
|
||||
#define MAX_COMBOS_CLICK_SOLT (FLEX_MS_TO_SCAN_CNT(300))
|
||||
/* Multiple clicks interval, default 300ms */
|
||||
#define MAX_MULTIPLE_CLICKS_INTERVAL (FLEX_MS_TO_SCAN_CNT(300))
|
||||
|
||||
typedef void (*flex_button_response_callback)(void*);
|
||||
|
||||
@ -81,8 +81,8 @@ typedef enum
|
||||
* Internal use, user read-only.
|
||||
* Number of button clicks
|
||||
*
|
||||
* @member max_combos_click_solt
|
||||
* Combo slot. Default 'MAX_COMBOS_CLICK_SOLT'.
|
||||
* @member max_multiple_clicks_interval
|
||||
* Multiple click interval. Default 'MAX_MULTIPLE_CLICKS_INTERVAL'.
|
||||
* Need to use FLEX_MS_TO_SCAN_CNT to convert milliseconds into scan cnts.
|
||||
*
|
||||
* @member debounce_tick
|
||||
@ -128,7 +128,7 @@ typedef struct flex_button
|
||||
|
||||
uint16_t scan_cnt;
|
||||
uint16_t click_cnt;
|
||||
uint16_t max_combos_click_solt;
|
||||
uint16_t max_multiple_clicks_interval;
|
||||
|
||||
uint16_t debounce_tick;
|
||||
uint16_t short_press_start_tick;
|
||||
|
@ -114,7 +114,7 @@ static void common_btn_evt_cb(void *arg)
|
||||
{
|
||||
flex_button_t *btn = (flex_button_t *)arg;
|
||||
|
||||
rt_kprintf("id: [%d - %s] event: [%d - %30s] combos: %d\n",
|
||||
rt_kprintf("id: [%d - %s] event: [%d - %30s] repeat: %d\n",
|
||||
btn->id, enum_btn_id_string[btn->id],
|
||||
btn->event, enum_event_string[btn->event],
|
||||
btn->click_cnt);
|
||||
|
Loading…
x
Reference in New Issue
Block a user