Skip to content

Commit b5bc941

Browse files
committed
update
add skip function.
1 parent fd46375 commit b5bc941

File tree

5 files changed

+206
-21
lines changed

5 files changed

+206
-21
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,13 @@ extern void mfbd_group_scan(const mfbd_group_t *_pbtn_group);
421421
```c
422422
extern void mfbd_group_reset(const mfbd_group_t *_pbtn_group);
423423
```
424+
### 如果一段时间没有调用按键检测,可以使用SKIP的API来跳过一段时间
425+
426+
可以在睡眠时调用此函数,此函数不会上报键值,只是更新计数时间,使用按键当前的状态直接进行计数`times`次时间。`tbtn`由于状态只有按下弹起,所以不支持此功能。
427+
428+
```c
429+
extern void mfbd_group_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times);
430+
```
424431
425432
## MFBD段定义
426433

mfbd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* 2022-08-05 smartmx add reset params function.
1212
* 2023-03-15 smartmx add state declaration.
1313
* 2023-07-03 smartmx add Section Definition option.
14-
* 2023-07-15 smartmx add skip function.
14+
* 2023-07-15 smartmx add skip function, to reduce calling of scan functions.
1515
*
1616
*/
1717

mfbd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* 2022-09-07 smartmx add default define apis.
1414
* 2023-03-15 smartmx add state declaration.
1515
* 2023-07-03 smartmx add Section Definition option.
16-
* 2023-07-15 smartmx add skip function.
16+
* 2023-07-15 smartmx add skip function, to reduce calling of scan functions.
1717
*
1818
*/
1919

mfbd_sd.c

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2023-07-03 smartmx the first version, Multi-Function Button Dectection with Section Definition.
9+
* 2023-07-15 smartmx add skip function, to reduce calling of scan functions.
910
*
1011
*/
1112

@@ -236,6 +237,60 @@ void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_nbtn_info_t *_pb
236237
}
237238
}
238239

240+
/**
241+
* @brief skip some times of mfbd_btn_count_t with last state.
242+
*
243+
* @param _pbtn_group is a pointer of mfbd_group_t.
244+
* @param times is times need to skip.
245+
*
246+
* @return None.
247+
*/
248+
void mfbd_nbtn_skip(const mfbd_group_t *_pbtn_group, const mfbd_nbtn_info_t *_pbtn_info_start, const mfbd_nbtn_info_t *_pbtn_info_end, mfbd_btn_count_t times)
249+
{
250+
const mfbd_nbtn_info_t *_pbtn_info = _pbtn_info_start;
251+
252+
while (1)
253+
{
254+
if (_pbtn_info_end <= _pbtn_info)
255+
{
256+
break;
257+
}
258+
if(_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN)
259+
{
260+
if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn_info->btn_long_code != 0))
261+
{
262+
/* if long_time is 0 or long_code is 0, disable long and repeat check. */
263+
if (_pbtn_info->btn->long_count < (MFBD_LONG_TIME_IN_FUC))
264+
{
265+
if(((MFBD_LONG_TIME_IN_FUC) - 1 - _pbtn_info->btn->long_count) > times)
266+
{
267+
_pbtn_info->btn->long_count = _pbtn_info->btn->long_count + times;
268+
}
269+
else
270+
{
271+
_pbtn_info->btn->long_count = MFBD_LONG_TIME_IN_FUC - 1;
272+
}
273+
}
274+
}
275+
}
276+
else if(_pbtn_info->btn->state == MFBD_BTN_STATE_LONG)
277+
{
278+
if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[0] != 0))
279+
{
280+
if(((MFBD_REPEAT_TIME_IN_FUC) - 1 - _pbtn_info->btn->repeat_count) > times)
281+
{
282+
_pbtn_info->btn->repeat_count = _pbtn_info->btn->repeat_count + times;
283+
}
284+
else
285+
{
286+
_pbtn_info->btn->repeat_count = MFBD_REPEAT_TIME_IN_FUC - 1;
287+
}
288+
}
289+
}
290+
_pbtn_info++;
291+
}
292+
}
293+
239294
/**
240295
* @brief reset all normal buttons' params.
241296
*
@@ -408,6 +463,75 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb
408463
}
409464
}
410465

466+
/**
467+
* @brief skip some times of mfbd_btn_count_t with last state.
468+
*
469+
* @param _pbtn_group is a pointer of mfbd_group_t.
470+
* @param times is times need to skip.
471+
*
472+
* @return None.
473+
*/
474+
void mfbd_mbtn_skip(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd_mbtn_info_t *_pbtn_info_end, mfbd_btn_count_t times)
475+
{
476+
const mfbd_mbtn_info_t *_pbtn_info = _pbtn_info_start;
477+
while (1)
478+
{
479+
if(_pbtn_info->btn->state == MFBD_BTN_STATE_UP)
480+
{
481+
if (_pbtn_info->btn->multiclick_state != 0)
482+
{
483+
if (_pbtn_info->btn->multiclick_count < (MFBD_MULTICLICK_TIME_IN_FUC))
484+
{
485+
if(((MFBD_MULTICLICK_TIME_IN_FUC) - _pbtn_info->btn->multiclick_count) > times)
486+
{
487+
_pbtn_info->btn->multiclick_count = _pbtn_info->btn->multiclick_count + times;
488+
}
489+
else
490+
{
491+
_pbtn_info->btn->multiclick_state = 0;
492+
}
493+
}
494+
}
495+
}
496+
else if(_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN)
497+
{
498+
if (_pbtn_info->btn->multiclick_state == 0)
499+
{
500+
if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn_info->btn_long_code != 0))
501+
{
502+
/* if long_time is 0 or long_code is 0, disable long and repeat check. */
503+
if (_pbtn_info->btn->long_count < (MFBD_LONG_TIME_IN_FUC))
504+
{
505+
if(((MFBD_LONG_TIME_IN_FUC) - 1 - _pbtn_info->btn->long_count) > times)
506+
{
507+
_pbtn_info->btn->long_count = _pbtn_info->btn->long_count + times;
508+
}
509+
else
510+
{
511+
_pbtn_info->btn->long_count = MFBD_LONG_TIME_IN_FUC - 1;
512+
}
513+
}
514+
}
515+
}
516+
}
517+
else if(_pbtn_info->btn->state == MFBD_BTN_STATE_LONG)
518+
{
519+
if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[0] != 0))
520+
{
521+
if(((MFBD_REPEAT_TIME_IN_FUC) - 1 - _pbtn_info->btn->repeat_count) > times)
522+
{
523+
_pbtn_info->btn->repeat_count = _pbtn_info->btn->repeat_count + times;
524+
}
525+
else
526+
{
527+
_pbtn_info->btn->repeat_count = MFBD_REPEAT_TIME_IN_FUC - 1;
528+
}
529+
}
530+
}
531+
_pbtn_info++;
532+
}
533+
}
534+
411535
/**
412536
* @brief reset all multi-function buttons' params.
413537
*

0 commit comments

Comments
 (0)