Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
add skip function.
  • Loading branch information
smartmx committed Jul 15, 2023
1 parent fd46375 commit b5bc941
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 21 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,13 @@ extern void mfbd_group_scan(const mfbd_group_t *_pbtn_group);
```c
extern void mfbd_group_reset(const mfbd_group_t *_pbtn_group);
```
### 如果一段时间没有调用按键检测,可以使用SKIP的API来跳过一段时间

可以在睡眠时调用此函数,此函数不会上报键值,只是更新计数时间,使用按键当前的状态直接进行计数`times`次时间。`tbtn`由于状态只有按下弹起,所以不支持此功能。

```c
extern void mfbd_group_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times);
```
## MFBD段定义
Expand Down
2 changes: 1 addition & 1 deletion mfbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* 2022-08-05 smartmx add reset params function.
* 2023-03-15 smartmx add state declaration.
* 2023-07-03 smartmx add Section Definition option.
* 2023-07-15 smartmx add skip function.
* 2023-07-15 smartmx add skip function, to reduce calling of scan functions.
*
*/

Expand Down
2 changes: 1 addition & 1 deletion mfbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* 2022-09-07 smartmx add default define apis.
* 2023-03-15 smartmx add state declaration.
* 2023-07-03 smartmx add Section Definition option.
* 2023-07-15 smartmx add skip function.
* 2023-07-15 smartmx add skip function, to reduce calling of scan functions.
*
*/

Expand Down
124 changes: 124 additions & 0 deletions mfbd_sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2023-07-03 smartmx the first version, Multi-Function Button Dectection with Section Definition.
* 2023-07-15 smartmx add skip function, to reduce calling of scan functions.
*
*/

Expand Down Expand Up @@ -236,6 +237,60 @@ void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_nbtn_info_t *_pb
}
}

/**
* @brief skip some times of mfbd_btn_count_t with last state.
*
* @param _pbtn_group is a pointer of mfbd_group_t.
* @param times is times need to skip.
*
* @return None.
*/
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)
{
const mfbd_nbtn_info_t *_pbtn_info = _pbtn_info_start;

while (1)
{
if (_pbtn_info_end <= _pbtn_info)
{
break;
}
if(_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN)
{
if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn_info->btn_long_code != 0))
{
/* if long_time is 0 or long_code is 0, disable long and repeat check. */
if (_pbtn_info->btn->long_count < (MFBD_LONG_TIME_IN_FUC))
{
if(((MFBD_LONG_TIME_IN_FUC) - 1 - _pbtn_info->btn->long_count) > times)
{
_pbtn_info->btn->long_count = _pbtn_info->btn->long_count + times;
}
else
{
_pbtn_info->btn->long_count = MFBD_LONG_TIME_IN_FUC - 1;
}
}
}
}
else if(_pbtn_info->btn->state == MFBD_BTN_STATE_LONG)
{
if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[0] != 0))
{
if(((MFBD_REPEAT_TIME_IN_FUC) - 1 - _pbtn_info->btn->repeat_count) > times)
{
_pbtn_info->btn->repeat_count = _pbtn_info->btn->repeat_count + times;
}
else
{
_pbtn_info->btn->repeat_count = MFBD_REPEAT_TIME_IN_FUC - 1;
}
}
}
_pbtn_info++;
}
}

/**
* @brief reset all normal buttons' params.
*
Expand Down Expand Up @@ -408,6 +463,75 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb
}
}

/**
* @brief skip some times of mfbd_btn_count_t with last state.
*
* @param _pbtn_group is a pointer of mfbd_group_t.
* @param times is times need to skip.
*
* @return None.
*/
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)
{
const mfbd_mbtn_info_t *_pbtn_info = _pbtn_info_start;
while (1)
{
if(_pbtn_info->btn->state == MFBD_BTN_STATE_UP)
{
if (_pbtn_info->btn->multiclick_state != 0)
{
if (_pbtn_info->btn->multiclick_count < (MFBD_MULTICLICK_TIME_IN_FUC))
{
if(((MFBD_MULTICLICK_TIME_IN_FUC) - _pbtn_info->btn->multiclick_count) > times)
{
_pbtn_info->btn->multiclick_count = _pbtn_info->btn->multiclick_count + times;
}
else
{
_pbtn_info->btn->multiclick_state = 0;
}
}
}
}
else if(_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN)
{
if (_pbtn_info->btn->multiclick_state == 0)
{
if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn_info->btn_long_code != 0))
{
/* if long_time is 0 or long_code is 0, disable long and repeat check. */
if (_pbtn_info->btn->long_count < (MFBD_LONG_TIME_IN_FUC))
{
if(((MFBD_LONG_TIME_IN_FUC) - 1 - _pbtn_info->btn->long_count) > times)
{
_pbtn_info->btn->long_count = _pbtn_info->btn->long_count + times;
}
else
{
_pbtn_info->btn->long_count = MFBD_LONG_TIME_IN_FUC - 1;
}
}
}
}
}
else if(_pbtn_info->btn->state == MFBD_BTN_STATE_LONG)
{
if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[0] != 0))
{
if(((MFBD_REPEAT_TIME_IN_FUC) - 1 - _pbtn_info->btn->repeat_count) > times)
{
_pbtn_info->btn->repeat_count = _pbtn_info->btn->repeat_count + times;
}
else
{
_pbtn_info->btn->repeat_count = MFBD_REPEAT_TIME_IN_FUC - 1;
}
}
}
_pbtn_info++;
}
}

/**
* @brief reset all multi-function buttons' params.
*
Expand Down
Loading

0 comments on commit b5bc941

Please sign in to comment.