Skip to content

Commit 5356ee8

Browse files
committed
[fix] 修复 combos 单次的歧义,愿意是想用作连击,但与组合歧义,因此替换为 multiple click
Signed-off-by: zhaojuntao <d2014zjt@163.com>
1 parent 292c8ad commit 5356ee8

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

Diff for: README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static void common_btn_evt_cb(void *arg)
142142
{
143143
flex_button_t *btn = (flex_button_t *)arg;
144144
145-
rt_kprintf("id: [%d - %s] event: [%d - %30s] combos: %d\n",
145+
rt_kprintf("id: [%d - %s] event: [%d - %30s] repeat: %d\n",
146146
btn->id, enum_btn_id_string[btn->id],
147147
btn->event, enum_event_string[btn->event],
148148
btn->click_cnt);
@@ -194,7 +194,7 @@ typedef struct flex_button
194194
195195
uint16_t scan_cnt;
196196
uint16_t click_cnt;
197-
uint16_t max_combos_click_solt;
197+
uint16_t max_multiple_clicks_interval;
198198
199199
uint16_t debounce_tick;
200200
uint16_t short_press_start_tick;
@@ -215,7 +215,7 @@ typedef struct flex_button
215215
| 3 | cb || 设置按键事件回调,用于应用层对按键事件的分类处理 |
216216
| 4 | scan_cnt || 用于记录扫描次数,按键按下是开始从零计数 |
217217
| 5 | click_cnt || 记录单击次数,用于判定单击、连击 |
218-
| 6 | max_combos_click_solt || 连击间隙,用于判定是否结束连击计数,有默认值 `MAX_COMBOS_CLICK_SOLT` |
218+
| 6 | max_multiple_clicks_interval || 连击间隙,用于判定是否结束连击计数,有默认值 `MAX_MULTIPLE_CLICKS_INTERVAL` |
219219
| 7 | debounce_tick || 消抖时间,暂未使用,依靠扫描间隙进行消抖 |
220220
| 8 | short_press_start_tick || 设置短按事件触发的起始 tick |
221221
| 9 | long_press_start_tick || 设置长按事件触发的起始 tick |
@@ -225,7 +225,7 @@ typedef struct flex_button
225225
| 13 | event || 用于记录当前按键事件 |
226226
| 14 | status || 用于记录当前按键的状态,用于内部状态机 |
227227

228-
注意,在使用 `max_combos_click_solt``debounce_tick``short_press_start_tick``long_press_start_tick``long_hold_start_tick` 的时候,注意需要使用宏 `**FLEX_MS_TO_SCAN_CNT(ms)**` 将毫秒值转换为扫描次数。因为按键库基于扫描次数运转。示例如下:
228+
注意,在使用 `max_multiple_clicks_interval``debounce_tick``short_press_start_tick``long_press_start_tick``long_hold_start_tick` 的时候,注意需要使用宏 `**FLEX_MS_TO_SCAN_CNT(ms)**` 将毫秒值转换为扫描次数。因为按键库基于扫描次数运转。示例如下:
229229

230230
```
231231
user_button[1].short_press_start_tick = FLEX_MS_TO_SCAN_CNT(1500); // 1500 毫秒

Diff for: flexible_button.c

+16-16
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* Date Author Notes
2525
* 2018-09-29 MurphyZhao First add
2626
* 2019-08-02 MurphyZhao Migrate code to github.com/murphyzhao account
27-
* 2019-12-26 MurphyZhao Refactor code and implement combos
27+
* 2019-12-26 MurphyZhao Refactor code and implement multiple clicks
2828
*
2929
*/
3030

@@ -54,7 +54,7 @@ enum FLEX_BTN_STAGE
5454
{
5555
FLEX_BTN_STAGE_DEFAULT = 0,
5656
FLEX_BTN_STAGE_DOWN = 1,
57-
FLEX_BTN_STAGE_COMBOS = 2
57+
FLEX_BTN_STAGE_MULTIPLE_CLICK = 2
5858
};
5959

6060
typedef uint32_t btn_type_t;
@@ -103,7 +103,7 @@ int8_t flex_button_register(flex_button_t *button)
103103
{
104104
if(curr == button)
105105
{
106-
return -1; //already exist.
106+
return -1; /* already exist. */
107107
}
108108
curr = curr->next;
109109
}
@@ -117,7 +117,7 @@ int8_t flex_button_register(flex_button_t *button)
117117
button->event = FLEX_BTN_PRESS_NONE;
118118
button->scan_cnt = 0;
119119
button->click_cnt = 0;
120-
button->max_combos_click_solt = MAX_COMBOS_CLICK_SOLT;
120+
button->max_multiple_clicks_interval = MAX_MULTIPLE_CLICKS_INTERVAL;
121121
btn_head = button;
122122

123123
/**
@@ -179,8 +179,8 @@ static void flex_button_process(void)
179179

180180
switch (target->status)
181181
{
182-
case FLEX_BTN_STAGE_DEFAULT: // stage: default(button up)
183-
if (BTN_IS_PRESSED(i)) // is pressed
182+
case FLEX_BTN_STAGE_DEFAULT: /* stage: default(button up) */
183+
if (BTN_IS_PRESSED(i)) /* is pressed */
184184
{
185185
target->scan_cnt = 0;
186186
target->click_cnt = 0;
@@ -196,12 +196,12 @@ static void flex_button_process(void)
196196
}
197197
break;
198198

199-
case FLEX_BTN_STAGE_DOWN: // stage: button down
200-
if (BTN_IS_PRESSED(i)) // is pressed
199+
case FLEX_BTN_STAGE_DOWN: /* stage: button down */
200+
if (BTN_IS_PRESSED(i)) /* is pressed */
201201
{
202-
if (target->click_cnt > 0) // combos
202+
if (target->click_cnt > 0) /* multiple click */
203203
{
204-
if (target->scan_cnt > target->max_combos_click_solt)
204+
if (target->scan_cnt > target->max_multiple_clicks_interval)
205205
{
206206
EVENT_SET_AND_EXEC_CB(target,
207207
target->click_cnt < FLEX_BTN_PRESS_REPEAT_CLICK ?
@@ -236,7 +236,7 @@ static void flex_button_process(void)
236236
}
237237
}
238238
}
239-
else // is up
239+
else /* button up */
240240
{
241241
if (target->scan_cnt >= target->long_hold_start_tick)
242242
{
@@ -255,23 +255,23 @@ static void flex_button_process(void)
255255
}
256256
else
257257
{
258-
/* swtich to combos stage */
259-
target->status = FLEX_BTN_STAGE_COMBOS;
258+
/* swtich to multiple click stage */
259+
target->status = FLEX_BTN_STAGE_MULTIPLE_CLICK;
260260
target->click_cnt ++;
261261
}
262262
}
263263
break;
264264

265-
case FLEX_BTN_STAGE_COMBOS: // stage: combos
266-
if (BTN_IS_PRESSED(i)) // is pressed
265+
case FLEX_BTN_STAGE_MULTIPLE_CLICK: /* stage: multiple click */
266+
if (BTN_IS_PRESSED(i)) /* is pressed */
267267
{
268268
/* swtich to button down stage */
269269
target->status = FLEX_BTN_STAGE_DOWN;
270270
target->scan_cnt = 0;
271271
}
272272
else
273273
{
274-
if (target->scan_cnt > target->max_combos_click_solt)
274+
if (target->scan_cnt > target->max_multiple_clicks_interval)
275275
{
276276
EVENT_SET_AND_EXEC_CB(target,
277277
target->click_cnt < FLEX_BTN_PRESS_REPEAT_CLICK ?

Diff for: flexible_button.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* Date Author Notes
2525
* 2018-09-29 MurphyZhao First add
2626
* 2019-08-02 MurphyZhao Migrate code to github.com/murphyzhao account
27-
* 2019-12-26 MurphyZhao Refactor code and implement combos
27+
* 2019-12-26 MurphyZhao Refactor code and implement multiple clicks
2828
*
2929
*/
3030

@@ -36,8 +36,8 @@
3636
#define FLEX_BTN_SCAN_FREQ_HZ 50 // How often flex_button_scan () is called
3737
#define FLEX_MS_TO_SCAN_CNT(ms) (ms / (1000 / FLEX_BTN_SCAN_FREQ_HZ))
3838

39-
/* Combos slot, default 300ms */
40-
#define MAX_COMBOS_CLICK_SOLT (FLEX_MS_TO_SCAN_CNT(300))
39+
/* Multiple clicks interval, default 300ms */
40+
#define MAX_MULTIPLE_CLICKS_INTERVAL (FLEX_MS_TO_SCAN_CNT(300))
4141

4242
typedef void (*flex_button_response_callback)(void*);
4343

@@ -81,8 +81,8 @@ typedef enum
8181
* Internal use, user read-only.
8282
* Number of button clicks
8383
*
84-
* @member max_combos_click_solt
85-
* Combo slot. Default 'MAX_COMBOS_CLICK_SOLT'.
84+
* @member max_multiple_clicks_interval
85+
* Multiple click interval. Default 'MAX_MULTIPLE_CLICKS_INTERVAL'.
8686
* Need to use FLEX_MS_TO_SCAN_CNT to convert milliseconds into scan cnts.
8787
*
8888
* @member debounce_tick
@@ -128,7 +128,7 @@ typedef struct flex_button
128128

129129
uint16_t scan_cnt;
130130
uint16_t click_cnt;
131-
uint16_t max_combos_click_solt;
131+
uint16_t max_multiple_clicks_interval;
132132

133133
uint16_t debounce_tick;
134134
uint16_t short_press_start_tick;

Diff for: flexible_button_demo.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static void common_btn_evt_cb(void *arg)
114114
{
115115
flex_button_t *btn = (flex_button_t *)arg;
116116

117-
rt_kprintf("id: [%d - %s] event: [%d - %30s] combos: %d\n",
117+
rt_kprintf("id: [%d - %s] event: [%d - %30s] repeat: %d\n",
118118
btn->id, enum_btn_id_string[btn->id],
119119
btn->event, enum_event_string[btn->event],
120120
btn->click_cnt);

0 commit comments

Comments
 (0)