diff --git a/README.md b/README.md index fa67d23..36dd9ad 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,16 @@ typedef uint32_t mfbd_btn_index_t; /* set MFBD_MULTICLICK_STATE_AUTO_RESET to 1 will auto set multiclick state to 0 when reach to max multicick state. */ #define MFBD_MULTICLICK_STATE_AUTO_RESET 1 +/* set MFBD_MBTN_CONTINUE_LONG_COUNT to 1 will continue count to change state to long after when multiclick state is not 0. */ +#define MFBD_MBTN_CONTINUE_LONG_COUNT 0 + +/* + * @Note: + * MFBD_MBTN_MULTICLICK_LONG_EVT only valid when MFBD_MBTN_CONTINUE_LONG_COUNT is not 0. + * When MFBD_MBTN_MULTICLICK_LONG_EVT is 1, it will still report long code and repeat downcodes after multiclick. + */ +#define MFBD_MBTN_MULTICLICK_LONG_EVT 0 + ``` `mfbd_btn_code_t`:按键键值的类型。 @@ -92,6 +102,10 @@ typedef uint32_t mfbd_btn_index_t; `MFBD_MULTICLICK_STATE_AUTO_RESET`:当mbtn达到最大连击次数时,连击次数是否自动返回未连击状态。为`1`,则自动返回0状态,下次连击则返回按键连击0按键码,为`0`,则必须等带连击释放时间达到后,才会自动返回0状态,下次连击则返回按键连击最高状态按键码。 +`MFBD_MBTN_CONTINUE_LONG_COUNT`:当mbtn触发连击后,是否继续进行长按检测,为`1`,则会继续检测长按状态,为`0`,则不会继续检测。 + +`MFBD_MBTN_MULTICLICK_LONG_EVT`:本宏只在`MFBD_MBTN_CONTINUE_LONG_COUNT`为`1`时生效。为`1`,则会继续上报多击长按后继续上报按键值,长按上报长按键值后,继续计数在重复事件发生后,会上报本次连击的按键值;为`0`,则不会上报按键值,只会改变按键状态,而且mbtn的重复事件被禁用。 + ## MFBD按键事件 ### 单击事件 @@ -112,6 +126,7 @@ typedef uint32_t mfbd_btn_index_t; 连击事件中,每次按键按下后,都会上报指定次数的连击按键值。 其实连击事件是不应该由按键驱动层进行检测的,但是嵌入式环境资源紧张,不可以像电脑那样交给应用层处理。 **注意:多次连击事件和长按事件是冲突的,当长按事件发生,不会进行多次连击的检测。当触发多次连击检测后,也不会进行长按事件的检测** +在1.0.5版本后,可以通过配置宏`MFBD_MBTN_CONTINUE_LONG_COUNT`为1,和`MFBD_MBTN_MULTICLICK_LONG_EVT`为1,可以实现连击和长按的共存。 ## MFBD按键组结构体 @@ -322,6 +337,8 @@ mfbd_btn_code_t MFBD_DOWN_CODES_DEF(mbtn)[4] = {0x1501, 0x1511, 0x1521, 0x1531}; 在读取按键状态的函数中,如果按键按下了,应当返回`MFBD_BTN_STATE_DOWN`,否则返回`MFBD_BTN_STATE_UP`。 +针对在矩阵键盘中鬼键,还有另一个状态`MFBD_BTN_STATE_SKIP`,当函数返回`MFBD_BTN_STATE_SKIP`后,MFBD会直接跳过对该按键的检测。 + ```c unsigned char bsp_btn_check(mfbd_btn_index_t btn_index) { @@ -501,19 +518,19 @@ GUN gcc工程需要在工程的ld文件中找到`rodata`的初始化链接代码 /* this is for tbtn in test_btns. */ . = ALIGN(4); PROVIDE(test_btns_tbtn_start = .); - KEEP(*(test_btns_tbtn*)) + KEEP (*(SORT(test_btns_tbtn*))) PROVIDE(test_btns_tbtn_end = .); /* this is for nbtn in test_btns. */ . = ALIGN(4); PROVIDE(test_btns_nbtn_start = .); - KEEP(*(test_btns_nbtn*)) + KEEP (*(SORT(test_btns_nbtn*))) PROVIDE(test_btns_nbtn_end = .); /* this is for mbtn in test_btns. */ . = ALIGN(4); PROVIDE(test_btns_mbtn_start = .); - KEEP(*(test_btns_mbtn*)) + KEEP (*(SORT(test_btns_mbtn*))) PROVIDE(test_btns_mbtn_end = .); *(.rodata) diff --git a/mfbd.c b/mfbd.c index fca465b..8e30e07 100644 --- a/mfbd.c +++ b/mfbd.c @@ -5,13 +5,15 @@ * * Change Logs: * Date Author Notes - * 2022-02-22 smartmx the first version - * 2022-03-15 smartmx each mbtn has it's own max multi-click times + * 2022-02-22 smartmx the first version. + * 2022-03-15 smartmx each mbtn has it's own max multi-click times. * 2022-04-16 smartmx drop list definitions, use arraylist, each group has all btn types. * 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, to reduce calling of scan functions. + * 2023-07-22 smartmx add MFBD_MBTN_MULTICLICK_LONG_EVT and MFBD_MBTN_CONTINUE_LONG_COUNT option. + * 2023-09-19 smartmx improve performance, add MFBD_BTN_STATE_SKIP. * */ @@ -19,6 +21,9 @@ #if (MFBD_USE_SECTION_DEFINITION == 0) +#define MFBD_BTN_IN_FUC (_pbtn) +#define MFBD_BTN_INFO_IN_FUC (_pbtn->btn_info) + #if MFBD_PARAMS_SAME_IN_GROUP /* filter_time */ @@ -33,15 +38,15 @@ #else /* filter_time */ - #define MFBD_FILTER_TIME_IN_FUC (_pbtn->btn_info->filter_time) + #define MFBD_FILTER_TIME_IN_FUC (MFBD_BTN_INFO_IN_FUC->filter_time) /* long_time */ - #define MFBD_LONG_TIME_IN_FUC (_pbtn->btn_info->long_time) + #define MFBD_LONG_TIME_IN_FUC (MFBD_BTN_INFO_IN_FUC->long_time) /* repeat_time */ - #define MFBD_REPEAT_TIME_IN_FUC (_pbtn->btn_info->repeat_time) + #define MFBD_REPEAT_TIME_IN_FUC (MFBD_BTN_INFO_IN_FUC->repeat_time) /* multiclick_time */ - #define MFBD_MULTICLICK_TIME_IN_FUC (_pbtn->btn_info->multiclick_time) + #define MFBD_MULTICLICK_TIME_IN_FUC (MFBD_BTN_INFO_IN_FUC->multiclick_time) -#endif /*MFBD_PARAMS_SAME_IN_GROUP*/ +#endif /* MFBD_PARAMS_SAME_IN_GROUP */ #if MFBD_USE_TINY_BUTTON @@ -56,51 +61,56 @@ void mfbd_tbtn_scan(const mfbd_group_t *_pbtn_group) { mfbd_tbtn_t **_ppbtn = _pbtn_group->tbtns; mfbd_tbtn_t *_pbtn = *_ppbtn; + MFBD_BTN_STATE_t btn_state; - while (_pbtn != NULL) + while (MFBD_BTN_IN_FUC != NULL) { - if (_pbtn_group->is_btn_down_func(_pbtn->btn_info->btn_index) != MFBD_BTN_STATE_UP) + btn_state = _pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->btn_index); + if (btn_state == MFBD_BTN_STATE_DOWN) { - if (_pbtn->filter_count < (MFBD_FILTER_TIME_IN_FUC)) - { - _pbtn->filter_count = (MFBD_FILTER_TIME_IN_FUC); - } - else if (_pbtn->filter_count < ((MFBD_FILTER_TIME_IN_FUC) * 2)) - { - _pbtn->filter_count++; - } - else + if(MFBD_BTN_IN_FUC->filter_count >= ((MFBD_FILTER_TIME_IN_FUC) * 2)) { /* it means the button is down for over filter_time. */ - if (_pbtn->state == MFBD_BTN_STATE_UP) + if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_UP) { - if (_pbtn->btn_info->btn_down_code > 0) + if (MFBD_BTN_INFO_IN_FUC->btn_down_code > 0) { - _pbtn_group->btn_value_report(_pbtn->btn_info->btn_down_code); + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code); } - _pbtn->state = MFBD_BTN_STATE_DOWN; + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_DOWN; } } - } - else - { - if (_pbtn->filter_count > (MFBD_FILTER_TIME_IN_FUC)) + else if(MFBD_BTN_IN_FUC->filter_count >= (MFBD_FILTER_TIME_IN_FUC)) { - _pbtn->filter_count = (MFBD_FILTER_TIME_IN_FUC); + MFBD_BTN_IN_FUC->filter_count++; } - else if (_pbtn->filter_count != 0) + else { - _pbtn->filter_count--; + MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC); } - else + } + else if (btn_state == MFBD_BTN_STATE_UP) + { + if (MFBD_BTN_IN_FUC->filter_count == 0) { - if (_pbtn->state != MFBD_BTN_STATE_UP) + if (MFBD_BTN_IN_FUC->state != MFBD_BTN_STATE_UP) { - if (_pbtn->btn_info->btn_up_code > 0) + if (MFBD_BTN_INFO_IN_FUC->btn_up_code > 0) { - _pbtn_group->btn_value_report(_pbtn->btn_info->btn_up_code); + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_up_code); } - _pbtn->state = MFBD_BTN_STATE_UP; + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP; + } + } + else + { + if (MFBD_BTN_IN_FUC->filter_count > (MFBD_FILTER_TIME_IN_FUC)) + { + MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC); + } + else if (MFBD_BTN_IN_FUC->filter_count != 0) + { + MFBD_BTN_IN_FUC->filter_count--; } } } @@ -120,16 +130,16 @@ void mfbd_tbtn_reset(const mfbd_group_t *_pbtn_group) { mfbd_tbtn_t **_ppbtn = _pbtn_group->tbtns; mfbd_tbtn_t *_pbtn = *_ppbtn; - while (_pbtn != NULL) + while (MFBD_BTN_IN_FUC != NULL) { - _pbtn->filter_count = 0; - _pbtn->state = MFBD_BTN_STATE_UP; + MFBD_BTN_IN_FUC->filter_count = 0; + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP; _ppbtn++; _pbtn = *_ppbtn; } } -#endif +#endif /* MFBD_USE_TINY_BUTTON */ #if MFBD_USE_NORMAL_BUTTON @@ -145,84 +155,109 @@ void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group) { mfbd_nbtn_t **_ppbtn = _pbtn_group->nbtns; mfbd_nbtn_t *_pbtn = *_ppbtn; + MFBD_BTN_STATE_t btn_state; - while (_pbtn != NULL) + while (MFBD_BTN_IN_FUC != NULL) { - if (_pbtn_group->is_btn_down_func(_pbtn->btn_info->btn_index) != MFBD_BTN_STATE_UP) + btn_state = _pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->btn_index); + if (btn_state == MFBD_BTN_STATE_DOWN) { - if (_pbtn->filter_count < (MFBD_FILTER_TIME_IN_FUC)) - { - _pbtn->filter_count = (MFBD_FILTER_TIME_IN_FUC); + if(MFBD_BTN_IN_FUC->filter_count >= ((MFBD_FILTER_TIME_IN_FUC) * 2)) + { + /* it means the button is down for over filter_time. */ + if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) + { + /* MFBD_BTN_STATE_LONG */ + if (MFBD_BTN_IN_FUC->repeat_count > 0) + { + MFBD_BTN_IN_FUC->repeat_count++; + if (MFBD_BTN_IN_FUC->repeat_count > (MFBD_REPEAT_TIME_IN_FUC)) + { + /* repeat event has happened, reset repeat_count to 1. */ + MFBD_BTN_IN_FUC->repeat_count = 1; + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code); + } + } + } + else if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) + { + if (MFBD_BTN_IN_FUC->long_count > 0) + { + /* if long_time is 0 or long_code is 0, disable long and repeat check. */ + if (MFBD_BTN_IN_FUC->long_count <= (MFBD_LONG_TIME_IN_FUC)) + { + MFBD_BTN_IN_FUC->long_count++; + if (MFBD_BTN_IN_FUC->long_count > (MFBD_LONG_TIME_IN_FUC)) + { + /* it means the button is down for over long_time. */ + if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (MFBD_BTN_INFO_IN_FUC->btn_down_code != 0)) + { + /* repeat event is enabled in this btn. */ + MFBD_BTN_IN_FUC->repeat_count = 1; + } + else + { + /* repeat event is disabled in this btn. */ + MFBD_BTN_IN_FUC->repeat_count = 0; + } + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_long_code); + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_LONG; + } + } + } + } + else + { + /* MFBD_BTN_STATE_UP */ + /* clear long_count. */ + if (((MFBD_LONG_TIME_IN_FUC) > 0) && (MFBD_BTN_INFO_IN_FUC->btn_long_code != 0)) + { + /* long event is enabled in this btn. */ + MFBD_BTN_IN_FUC->long_count = 1; + } + else + { + /* long event is disabled in this btn. */ + MFBD_BTN_IN_FUC->long_count = 0; + } + if (MFBD_BTN_INFO_IN_FUC->btn_down_code > 0) + { + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code); + } + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_DOWN; + } } - else if (_pbtn->filter_count < ((MFBD_FILTER_TIME_IN_FUC) * 2)) + else if(MFBD_BTN_IN_FUC->filter_count >= (MFBD_FILTER_TIME_IN_FUC)) { - _pbtn->filter_count++; + MFBD_BTN_IN_FUC->filter_count++; } else { - /* it means the button is down for over filter_time. */ - if (_pbtn->state == MFBD_BTN_STATE_UP) - { - /* clear long_count. */ - _pbtn->long_count = 0; - if (_pbtn->btn_info->btn_down_code > 0) - { - _pbtn_group->btn_value_report(_pbtn->btn_info->btn_down_code); - } - _pbtn->state = MFBD_BTN_STATE_DOWN; - } - else - { - if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_long_code != 0)) - { - /* if long_time is 0 or long_code is 0, disable long and repeat check. */ - if (_pbtn->long_count < (MFBD_LONG_TIME_IN_FUC)) - { - _pbtn->long_count++; - if (_pbtn->long_count >= (MFBD_LONG_TIME_IN_FUC)) - { - /* it means the button is down for over long_time. */ - _pbtn->repeat_count = 0; /* long event has happened, clear repeat_count. */ - _pbtn_group->btn_value_report(_pbtn->btn_info->btn_long_code); - _pbtn->state = MFBD_BTN_STATE_LONG; - } - } - else - { - if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_down_code != 0)) - { - _pbtn->repeat_count++; - if (_pbtn->repeat_count >= (MFBD_REPEAT_TIME_IN_FUC)) - { - /* repeat event has happened, clear repeat_count. */ - _pbtn->repeat_count = 0; - _pbtn_group->btn_value_report(_pbtn->btn_info->btn_down_code); - } - } - } - } - } + MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC); } } - else + else if (btn_state == MFBD_BTN_STATE_UP) { - if (_pbtn->filter_count > (MFBD_FILTER_TIME_IN_FUC)) + if (MFBD_BTN_IN_FUC->filter_count == 0) { - _pbtn->filter_count = (MFBD_FILTER_TIME_IN_FUC); - } - else if (_pbtn->filter_count != 0) - { - _pbtn->filter_count--; + if (MFBD_BTN_IN_FUC->state != MFBD_BTN_STATE_UP) + { + if (MFBD_BTN_INFO_IN_FUC->btn_up_code > 0) + { + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_up_code); + } + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP; + } } else { - if (_pbtn->state != MFBD_BTN_STATE_UP) + if (MFBD_BTN_IN_FUC->filter_count > (MFBD_FILTER_TIME_IN_FUC)) { - if (_pbtn->btn_info->btn_up_code > 0) - { - _pbtn_group->btn_value_report(_pbtn->btn_info->btn_up_code); - } - _pbtn->state = MFBD_BTN_STATE_UP; + MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC); + } + else if (MFBD_BTN_IN_FUC->filter_count != 0) + { + MFBD_BTN_IN_FUC->filter_count--; } } } @@ -244,37 +279,33 @@ void mfbd_nbtn_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times) mfbd_nbtn_t **_ppbtn = _pbtn_group->nbtns; mfbd_nbtn_t *_pbtn = *_ppbtn; - while (_pbtn != NULL) + while (MFBD_BTN_IN_FUC != NULL) { - if(_pbtn->state == MFBD_BTN_STATE_DOWN) + if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) { - if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_long_code != 0)) + if ((MFBD_BTN_IN_FUC->long_count > 0) && (MFBD_BTN_IN_FUC->long_count < (MFBD_LONG_TIME_IN_FUC))) { - /* if long_time is 0 or long_code is 0, disable long and repeat check. */ - if (_pbtn->long_count < (MFBD_LONG_TIME_IN_FUC)) + if(((MFBD_LONG_TIME_IN_FUC) - MFBD_BTN_IN_FUC->long_count) > times) { - if(((MFBD_LONG_TIME_IN_FUC) - 1 - _pbtn->long_count) > times) - { - _pbtn->long_count = _pbtn->long_count + times; - } - else - { - _pbtn->long_count = MFBD_LONG_TIME_IN_FUC - 1; - } + MFBD_BTN_IN_FUC->long_count = MFBD_BTN_IN_FUC->long_count + times; + } + else + { + MFBD_BTN_IN_FUC->long_count = MFBD_LONG_TIME_IN_FUC; } } } - else if(_pbtn->state == MFBD_BTN_STATE_LONG) + else if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) { - if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_down_code != 0)) + if ((MFBD_BTN_IN_FUC->repeat_count > 0) && (MFBD_BTN_IN_FUC->repeat_count < (MFBD_REPEAT_TIME_IN_FUC))) { - if(((MFBD_REPEAT_TIME_IN_FUC) - 1 - _pbtn->repeat_count) > times) + if(((MFBD_REPEAT_TIME_IN_FUC) - MFBD_BTN_IN_FUC->repeat_count) > times) { - _pbtn->repeat_count = _pbtn->repeat_count + times; + MFBD_BTN_IN_FUC->repeat_count = MFBD_BTN_IN_FUC->repeat_count + times; } else { - _pbtn->repeat_count = MFBD_REPEAT_TIME_IN_FUC - 1; + MFBD_BTN_IN_FUC->repeat_count = MFBD_REPEAT_TIME_IN_FUC; } } } @@ -295,18 +326,18 @@ void mfbd_nbtn_reset(const mfbd_group_t *_pbtn_group) { mfbd_nbtn_t **_ppbtn = _pbtn_group->nbtns; mfbd_nbtn_t *_pbtn = *_ppbtn; - while (_pbtn != NULL) + while (MFBD_BTN_IN_FUC != NULL) { - _pbtn->filter_count = 0; - _pbtn->long_count = 0; - _pbtn->repeat_count = 0; - _pbtn->state = MFBD_BTN_STATE_UP; + MFBD_BTN_IN_FUC->filter_count = 0; + MFBD_BTN_IN_FUC->long_count = 0; + MFBD_BTN_IN_FUC->repeat_count = 0; + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP; _ppbtn++; _pbtn = *_ppbtn; } } -#endif +#endif /* MFBD_USE_NORMAL_BUTTON */ #if MFBD_USE_MULTIFUCNTION_BUTTON @@ -322,123 +353,226 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group) { mfbd_mbtn_t **_ppbtn = _pbtn_group->mbtns; mfbd_mbtn_t *_pbtn = *_ppbtn; - while (_pbtn != NULL) + MFBD_BTN_STATE_t btn_state; + + while (MFBD_BTN_IN_FUC != NULL) { - if (_pbtn_group->is_btn_down_func(_pbtn->btn_info->btn_index) != MFBD_BTN_STATE_UP) + btn_state = _pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->btn_index); + if (btn_state == MFBD_BTN_STATE_DOWN) { - if (_pbtn->filter_count < (MFBD_FILTER_TIME_IN_FUC)) - { - _pbtn->filter_count = (MFBD_FILTER_TIME_IN_FUC); - } - else if (_pbtn->filter_count < ((MFBD_FILTER_TIME_IN_FUC) * 2)) - { - _pbtn->filter_count++; - } - else + if(MFBD_BTN_IN_FUC->filter_count >= ((MFBD_FILTER_TIME_IN_FUC) * 2)) { /* it means the button is down for over filter_time. */ - if (_pbtn->state == MFBD_BTN_STATE_UP) +#if MFBD_MBTN_CONTINUE_LONG_COUNT +#if MFBD_MBTN_MULTICLICK_LONG_EVT + if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) { - _pbtn->state = MFBD_BTN_STATE_DOWN; - /* clear long_count. */ - _pbtn->long_count = 0; - if (_pbtn->btn_info->btn_down_code[_pbtn->multiclick_state] > 0) + /* MFBD_BTN_STATE_LONG */ + if (MFBD_BTN_IN_FUC->repeat_count > 0) { - _pbtn_group->btn_value_report(_pbtn->btn_info->btn_down_code[_pbtn->multiclick_state]); + MFBD_BTN_IN_FUC->repeat_count++; + if (MFBD_BTN_IN_FUC->repeat_count > (MFBD_REPEAT_TIME_IN_FUC)) + { + /* repeat event has happened, clear repeat_count. */ + MFBD_BTN_IN_FUC->repeat_count = 1; + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code[MFBD_BTN_IN_FUC->multiclick_state]); + } } } - else + else if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) { - if (_pbtn->multiclick_state == 0) + if (MFBD_BTN_IN_FUC->long_count > 0) { - if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_long_code != 0)) + /* if long_time is 0 or long_code is 0, disable long and repeat check. */ + if (MFBD_BTN_IN_FUC->long_count <= (MFBD_LONG_TIME_IN_FUC)) { - /* if long_time is 0 or long_code is 0, disable long and repeat check. */ - if (_pbtn->long_count < (MFBD_LONG_TIME_IN_FUC)) + MFBD_BTN_IN_FUC->long_count++; + if (MFBD_BTN_IN_FUC->long_count > (MFBD_LONG_TIME_IN_FUC)) { - _pbtn->long_count++; - if (_pbtn->long_count >= (MFBD_LONG_TIME_IN_FUC)) + /* it means the button is down for over long_time. */ + if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (MFBD_BTN_INFO_IN_FUC->btn_down_code[MFBD_BTN_IN_FUC->multiclick_state] != 0)) { - /* it means the button is down for over long_time. */ - _pbtn->repeat_count = 0; /* long event has happened, clear repeat_count. */ - _pbtn_group->btn_value_report(_pbtn->btn_info->btn_long_code); - _pbtn->state = MFBD_BTN_STATE_LONG; + /* repeat event is enabled in this btn. */ + MFBD_BTN_IN_FUC->repeat_count = 1; } + else + { + /* repeat event is disabled in this btn. */ + MFBD_BTN_IN_FUC->repeat_count = 0; + } + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_long_code); + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_LONG; } - else + } + } + } +#else + if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) + { + /* we don't support repeat event here.*/ + } + else if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) + { + if (MFBD_BTN_IN_FUC->long_count > 0) + { + /* if long_time is 0 or long_code is 0, disable long and repeat check. */ + if (MFBD_BTN_IN_FUC->long_count <= (MFBD_LONG_TIME_IN_FUC)) + { + MFBD_BTN_IN_FUC->long_count++; + if (MFBD_BTN_IN_FUC->long_count > (MFBD_LONG_TIME_IN_FUC)) { - if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_down_code[0] != 0)) + /* it means the button is down for over long_time. */ + if (MFBD_BTN_IN_FUC->multiclick_state == 0) { - _pbtn->repeat_count++; - if (_pbtn->repeat_count >= (MFBD_REPEAT_TIME_IN_FUC)) - { - /* repeat event has happened, clear repeat_count. */ - _pbtn->repeat_count = 0; - _pbtn_group->btn_value_report(_pbtn->btn_info->btn_down_code[0]); - } + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_long_code); } + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_LONG; } } } } - } - } - else - { - if (_pbtn->filter_count > (MFBD_FILTER_TIME_IN_FUC)) - { - _pbtn->filter_count = (MFBD_FILTER_TIME_IN_FUC); - } - else if (_pbtn->filter_count != 0) - { - _pbtn->filter_count--; - } - else - { - if (_pbtn->state != MFBD_BTN_STATE_UP) +#endif /* MFBD_MBTN_MULTICLICK_LONG_EVT */ +#else + if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) { -#if MFBD_MULTICLICK_STATE_AUTO_RESET - /* if multiclick_state is not 0 and less than max_multiclick_state, inc multiclick_state */ - if (((MFBD_MULTICLICK_TIME_IN_FUC) != 0) \ - && (_pbtn->multiclick_state < _pbtn->btn_info->max_multiclick_state) \ - && (_pbtn->state == MFBD_BTN_STATE_DOWN)) + /* MFBD_BTN_STATE_LONG */ + if (MFBD_BTN_IN_FUC->repeat_count > 0) { - _pbtn->multiclick_state++; - _pbtn->multiclick_count = 0; + MFBD_BTN_IN_FUC->repeat_count++; + if (MFBD_BTN_IN_FUC->repeat_count > (MFBD_REPEAT_TIME_IN_FUC)) + { + /* repeat event has happened, clear repeat_count. */ + MFBD_BTN_IN_FUC->repeat_count = 1; + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code[0]); + } } -#else - /* if multiclick_state is not 0 and less than max_multiclick_state, inc multiclick_state */ - if (((MFBD_MULTICLICK_TIME_IN_FUC) != 0) \ - && (_pbtn->state == MFBD_BTN_STATE_DOWN)) + } + else if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) + { + if (MFBD_BTN_IN_FUC->multiclick_state == 0) { - if(_pbtn->multiclick_state < _pbtn->btn_info->max_multiclick_state) + if (MFBD_BTN_IN_FUC->long_count > 0) { - _pbtn->multiclick_state++; + /* if long_time is 0 or long_code is 0, disable long and repeat check. */ + if (MFBD_BTN_IN_FUC->long_count <= (MFBD_LONG_TIME_IN_FUC)) + { + MFBD_BTN_IN_FUC->long_count++; + if (MFBD_BTN_IN_FUC->long_count > (MFBD_LONG_TIME_IN_FUC)) + { + /* it means the button is down for over long_time. */ + if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (MFBD_BTN_INFO_IN_FUC->btn_down_code[0] != 0)) + { + /* repeat event is enabled in this btn. */ + MFBD_BTN_IN_FUC->repeat_count = 1; + } + else + { + /* repeat event is disabled in this btn. */ + MFBD_BTN_IN_FUC->repeat_count = 0; + } + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_long_code); + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_LONG; + } + } } - _pbtn->multiclick_count = 0; } -#endif + } +#endif /* MFBD_MBTN_CONTINUE_LONG_COUNT */ + else + { + /* MFBD_BTN_STATE_UP */ + /* clear long_count. */ + if (((MFBD_LONG_TIME_IN_FUC) > 0) && (MFBD_BTN_INFO_IN_FUC->btn_long_code != 0)) + { + /* long event is enabled in this btn. */ + MFBD_BTN_IN_FUC->long_count = 1; + } else { - /* over max multi-click times or (long event and repeat event) happened, reset to 0. */ - _pbtn->multiclick_state = 0; + /* long event is disabled in this btn. */ + MFBD_BTN_IN_FUC->long_count = 0; } - if (_pbtn->btn_info->btn_up_code > 0) + if (MFBD_BTN_INFO_IN_FUC->btn_down_code[MFBD_BTN_IN_FUC->multiclick_state] > 0) { - _pbtn_group->btn_value_report(_pbtn->btn_info->btn_up_code); + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code[MFBD_BTN_IN_FUC->multiclick_state]); } - _pbtn->state = MFBD_BTN_STATE_UP; + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_DOWN; } - else + } + else if(MFBD_BTN_IN_FUC->filter_count >= (MFBD_FILTER_TIME_IN_FUC)) + { + MFBD_BTN_IN_FUC->filter_count++; + } + else + { + MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC); + } + } + else if (btn_state == MFBD_BTN_STATE_UP) + { + if (MFBD_BTN_IN_FUC->filter_count == 0) + { + if (MFBD_BTN_IN_FUC->state != MFBD_BTN_STATE_UP) + { +#if MFBD_MULTICLICK_STATE_AUTO_RESET + /* if multiclick_state is not 0 and less than max_multiclick_state, inc multiclick_state */ + if (((MFBD_MULTICLICK_TIME_IN_FUC) != 0) + && (MFBD_BTN_IN_FUC->multiclick_state < MFBD_BTN_INFO_IN_FUC->max_multiclick_state) +#if (MFBD_MBTN_CONTINUE_LONG_COUNT==0) + && (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) +#endif /* (MFBD_MBTN_CONTINUE_LONG_COUNT==0) */ + ) + { + MFBD_BTN_IN_FUC->multiclick_state++; + MFBD_BTN_IN_FUC->multiclick_count = 0; + } +#else + /* if multiclick_state is not 0 and less than max_multiclick_state, inc multiclick_state */ + if (((MFBD_MULTICLICK_TIME_IN_FUC) != 0) +#if (MFBD_MBTN_CONTINUE_LONG_COUNT==0) + && (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) +#endif /* (MFBD_MBTN_CONTINUE_LONG_COUNT==0) */ + ) + { + if(MFBD_BTN_IN_FUC->multiclick_state < MFBD_BTN_INFO_IN_FUC->max_multiclick_state) + { + MFBD_BTN_IN_FUC->multiclick_state++; + } + MFBD_BTN_IN_FUC->multiclick_count = 0; + } +#endif /* MFBD_MULTICLICK_STATE_AUTO_RESET */ + else + { + /* over max multi-click times or (long event and repeat event) happened, reset to 0. */ + MFBD_BTN_IN_FUC->multiclick_state = 0; + } + if (MFBD_BTN_INFO_IN_FUC->btn_up_code > 0) + { + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_up_code); + } + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP; + } + else + { + if (MFBD_BTN_IN_FUC->multiclick_state != 0) + { + MFBD_BTN_IN_FUC->multiclick_count++; + if (MFBD_BTN_IN_FUC->multiclick_count >= (MFBD_MULTICLICK_TIME_IN_FUC)) + { + MFBD_BTN_IN_FUC->multiclick_state = 0; + } + } + } + } + else + { + if (MFBD_BTN_IN_FUC->filter_count > (MFBD_FILTER_TIME_IN_FUC)) { - if (_pbtn->multiclick_state != 0) - { - _pbtn->multiclick_count++; - if (_pbtn->multiclick_count >= (MFBD_MULTICLICK_TIME_IN_FUC)) - { - _pbtn->multiclick_state = 0; - } - } + MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC); + } + else if (MFBD_BTN_IN_FUC->filter_count != 0) + { + MFBD_BTN_IN_FUC->filter_count--; } } } @@ -460,61 +594,109 @@ void mfbd_mbtn_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times) mfbd_mbtn_t **_ppbtn = _pbtn_group->mbtns; mfbd_mbtn_t *_pbtn = *_ppbtn; - while (_pbtn != NULL) + while (MFBD_BTN_IN_FUC != NULL) { - if(_pbtn->state == MFBD_BTN_STATE_UP) + if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_UP) { - if (_pbtn->multiclick_state != 0) + if (MFBD_BTN_IN_FUC->multiclick_state != 0) { - if (_pbtn->multiclick_count < (MFBD_MULTICLICK_TIME_IN_FUC)) + if (MFBD_BTN_IN_FUC->multiclick_count < (MFBD_MULTICLICK_TIME_IN_FUC)) { - if(((MFBD_MULTICLICK_TIME_IN_FUC) - _pbtn->multiclick_count) > times) + if(((MFBD_MULTICLICK_TIME_IN_FUC) - MFBD_BTN_IN_FUC->multiclick_count) > times) { - _pbtn->multiclick_count = _pbtn->multiclick_count + times; + MFBD_BTN_IN_FUC->multiclick_count = MFBD_BTN_IN_FUC->multiclick_count + times; } else { - _pbtn->multiclick_state = 0; + MFBD_BTN_IN_FUC->multiclick_state = 0; } } } } - else if(_pbtn->state == MFBD_BTN_STATE_DOWN) +#if MFBD_MBTN_CONTINUE_LONG_COUNT +#if MFBD_MBTN_MULTICLICK_LONG_EVT + else if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) { - if (_pbtn->multiclick_state == 0) + if ((MFBD_BTN_IN_FUC->long_count > 0) && (MFBD_BTN_IN_FUC->long_count < (MFBD_LONG_TIME_IN_FUC))) { - if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_long_code != 0)) + if(((MFBD_LONG_TIME_IN_FUC) - MFBD_BTN_IN_FUC->long_count) > times) { - /* if long_time is 0 or long_code is 0, disable long and repeat check. */ - if (_pbtn->long_count < (MFBD_LONG_TIME_IN_FUC)) - { - if(((MFBD_LONG_TIME_IN_FUC) - 1 - _pbtn->long_count) > times) - { - _pbtn->long_count = _pbtn->long_count + times; - } - else - { - _pbtn->long_count = MFBD_LONG_TIME_IN_FUC - 1; - } - } + MFBD_BTN_IN_FUC->long_count = MFBD_BTN_IN_FUC->long_count + times; + } + else + { + MFBD_BTN_IN_FUC->long_count = MFBD_LONG_TIME_IN_FUC; } } } - else if(_pbtn->state == MFBD_BTN_STATE_LONG) + else { - if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_down_code[0] != 0)) + /* MFBD_BTN_STATE_LONG, if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) */ + if ((MFBD_BTN_IN_FUC->repeat_count > 0) && (MFBD_BTN_IN_FUC->repeat_count < (MFBD_REPEAT_TIME_IN_FUC))) { - if(((MFBD_REPEAT_TIME_IN_FUC) - 1 - _pbtn->repeat_count) > times) + if(((MFBD_REPEAT_TIME_IN_FUC) - MFBD_BTN_IN_FUC->repeat_count) > times) { - _pbtn->repeat_count = _pbtn->repeat_count + times; + MFBD_BTN_IN_FUC->repeat_count = MFBD_BTN_IN_FUC->repeat_count + times; } else { - _pbtn->repeat_count = MFBD_REPEAT_TIME_IN_FUC - 1; + MFBD_BTN_IN_FUC->repeat_count = MFBD_REPEAT_TIME_IN_FUC; } } } - +#else + else if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) + { + if ((MFBD_BTN_IN_FUC->long_count > 0) && (MFBD_BTN_IN_FUC->long_count < (MFBD_LONG_TIME_IN_FUC))) + { + /* if long_time is 0 or long_code is 0, disable long and repeat check. */ + if(((MFBD_LONG_TIME_IN_FUC) - MFBD_BTN_IN_FUC->long_count) > times) + { + MFBD_BTN_IN_FUC->long_count = MFBD_BTN_IN_FUC->long_count + times; + } + else + { + MFBD_BTN_IN_FUC->long_count = MFBD_LONG_TIME_IN_FUC; + } + } + } + else + { + /* MFBD_BTN_STATE_LONG, if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) */ + /* we don't support repeat event here.*/ + } +#endif /* MFBD_MBTN_MULTICLICK_LONG_EVT */ +#else + else if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) + { + if ((MFBD_BTN_IN_FUC->long_count > 0) && (MFBD_BTN_IN_FUC->long_count < (MFBD_LONG_TIME_IN_FUC))) + { + if(((MFBD_LONG_TIME_IN_FUC) - MFBD_BTN_IN_FUC->long_count) > times) + { + MFBD_BTN_IN_FUC->long_count = MFBD_BTN_IN_FUC->long_count + times; + } + else + { + MFBD_BTN_IN_FUC->long_count = MFBD_LONG_TIME_IN_FUC; + } + } + } + else + { + /* MFBD_BTN_STATE_LONG, if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) */ + if ((MFBD_BTN_IN_FUC->repeat_count > 0) && (MFBD_BTN_IN_FUC->repeat_count < (MFBD_REPEAT_TIME_IN_FUC))) + { + if(((MFBD_REPEAT_TIME_IN_FUC) - MFBD_BTN_IN_FUC->repeat_count) > times) + { + MFBD_BTN_IN_FUC->repeat_count = MFBD_BTN_IN_FUC->repeat_count + times; + } + else + { + MFBD_BTN_IN_FUC->repeat_count = MFBD_REPEAT_TIME_IN_FUC; + } + } + } +#endif /* MFBD_MBTN_CONTINUE_LONG_COUNT */ _ppbtn++; _pbtn = *_ppbtn; } @@ -531,20 +713,20 @@ void mfbd_mbtn_reset(const mfbd_group_t *_pbtn_group) { mfbd_mbtn_t **_ppbtn = _pbtn_group->mbtns; mfbd_mbtn_t *_pbtn = *_ppbtn; - while (_pbtn != NULL) + while (MFBD_BTN_IN_FUC != NULL) { - _pbtn->filter_count = 0; - _pbtn->long_count = 0; - _pbtn->multiclick_count = 0; - _pbtn->multiclick_state = 0; - _pbtn->repeat_count = 0; - _pbtn->state = MFBD_BTN_STATE_UP; + MFBD_BTN_IN_FUC->filter_count = 0; + MFBD_BTN_IN_FUC->long_count = 0; + MFBD_BTN_IN_FUC->multiclick_count = 0; + MFBD_BTN_IN_FUC->multiclick_state = 0; + MFBD_BTN_IN_FUC->repeat_count = 0; + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP; _ppbtn++; _pbtn = *_ppbtn; } } -#endif +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ /** @@ -563,7 +745,7 @@ void mfbd_group_scan(const mfbd_group_t *_pbtn_group) /* call prepare scan function */ _pbtn_group->btn_scan_prepare(); } -#endif +#endif /* MFBD_USE_BTN_SCAN_PRE_FUNC */ #if MFBD_USE_TINY_BUTTON if (_pbtn_group->tbtns != NULL) @@ -571,7 +753,7 @@ void mfbd_group_scan(const mfbd_group_t *_pbtn_group) /*scan tiny buttons in group.*/ mfbd_tbtn_scan(_pbtn_group); } -#endif +#endif /* MFBD_USE_TINY_BUTTON */ #if MFBD_USE_NORMAL_BUTTON if (_pbtn_group->nbtns != NULL) @@ -579,7 +761,7 @@ void mfbd_group_scan(const mfbd_group_t *_pbtn_group) /*scan normal buttons in group.*/ mfbd_nbtn_scan(_pbtn_group); } -#endif +#endif /* MFBD_USE_NORMAL_BUTTON */ #if MFBD_USE_MULTIFUCNTION_BUTTON if (_pbtn_group->mbtns != NULL) @@ -587,7 +769,7 @@ void mfbd_group_scan(const mfbd_group_t *_pbtn_group) /*scan multifunction buttons in group.*/ mfbd_mbtn_scan(_pbtn_group); } -#endif +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ #if MFBD_USE_BTN_SCAN_AFTER_FUNC if (_pbtn_group->btn_scan_after != NULL) @@ -595,7 +777,7 @@ void mfbd_group_scan(const mfbd_group_t *_pbtn_group) /* call after scan function */ _pbtn_group->btn_scan_after(); } -#endif +#endif /* MFBD_USE_BTN_SCAN_AFTER_FUNC */ } @@ -618,7 +800,7 @@ void mfbd_group_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times) /* skip times of normal buttons in group.*/ mfbd_nbtn_skip(_pbtn_group, times); } -#endif +#endif /* MFBD_USE_NORMAL_BUTTON */ #if MFBD_USE_MULTIFUCNTION_BUTTON if (_pbtn_group->mbtns != NULL) @@ -626,7 +808,7 @@ void mfbd_group_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times) /* skip times of multifunction buttons in group.*/ mfbd_mbtn_skip(_pbtn_group, times); } -#endif +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ } @@ -647,7 +829,7 @@ void mfbd_group_reset(const mfbd_group_t *_pbtn_group) /*reset tiny buttons in group.*/ mfbd_tbtn_reset(_pbtn_group); } -#endif +#endif /* MFBD_USE_TINY_BUTTON */ #if MFBD_USE_NORMAL_BUTTON if (_pbtn_group->nbtns != NULL) @@ -655,7 +837,7 @@ void mfbd_group_reset(const mfbd_group_t *_pbtn_group) /*reset normal buttons in group.*/ mfbd_nbtn_reset(_pbtn_group); } -#endif +#endif /* MFBD_USE_NORMAL_BUTTON */ #if MFBD_USE_MULTIFUCNTION_BUTTON if (_pbtn_group->mbtns != NULL) @@ -663,7 +845,7 @@ void mfbd_group_reset(const mfbd_group_t *_pbtn_group) /*reset multifunction buttons in group.*/ mfbd_mbtn_reset(_pbtn_group); } -#endif +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ } diff --git a/mfbd.h b/mfbd.h index 8ff667c..ac71a35 100644 --- a/mfbd.h +++ b/mfbd.h @@ -5,8 +5,8 @@ * * Change Logs: * Date Author Notes - * 2022-02-22 smartmx the first version - * 2022-03-15 smartmx each mbtn has it's own max multi-click times + * 2022-02-22 smartmx the first version. + * 2022-03-15 smartmx each mbtn has it's own max multi-click times. * 2022-04-16 smartmx drop list definitions, use array, each group has all btn types. * 2022-08-05 smartmx add reset params function. * 2022-08-15 smartmx fix bugs. @@ -14,6 +14,7 @@ * 2023-03-15 smartmx add state declaration. * 2023-07-03 smartmx add Section Definition option. * 2023-07-15 smartmx add skip function, to reduce calling of scan functions. + * 2023-09-19 smartmx improve performance, add MFBD_BTN_STATE_SKIP. * */ @@ -29,6 +30,7 @@ typedef enum MFBD_BTN_STATE_UP = 0, MFBD_BTN_STATE_DOWN, MFBD_BTN_STATE_LONG, + MFBD_BTN_STATE_SKIP = 0xff, } MFBD_BTN_STATE_t; #define MFBD_DOWN_CODE_NAME(NAME) NAME##_DOWN_CODE /* when using tbtn/nbtn default define api, this is down-code name. */ @@ -56,7 +58,7 @@ typedef struct _mfbd_tbtn_info_struct mfbd_btn_index_t btn_index; /* parameter when calling is_btn_down_func. */ } mfbd_tbtn_info_t; -#endif /*MFBD_PARAMS_SAME_IN_GROUP*/ +#endif /* MFBD_PARAMS_SAME_IN_GROUP */ typedef struct _mfbd_tiny_btn_struct { @@ -119,7 +121,7 @@ mfbd_tbtn_t NAME = { \ 0, \ } -#endif /*MFBD_PARAMS_SAME_IN_GROUP*/ +#endif /* MFBD_PARAMS_SAME_IN_GROUP */ #define MFBD_TBTN_EXTERN(NAME) extern mfbd_tbtn_t NAME @@ -151,7 +153,7 @@ typedef struct _mfbd_nbtn_info_struct mfbd_btn_index_t btn_index; /* parameter when calling is_btn_down_func. */ } mfbd_nbtn_info_t; -#endif /*MFBD_PARAMS_SAME_IN_GROUP*/ +#endif /* MFBD_PARAMS_SAME_IN_GROUP */ typedef struct _mfbd_normal_btn_struct { @@ -229,7 +231,7 @@ mfbd_nbtn_t NAME = { 0, \ } -#endif /*MFBD_PARAMS_SAME_IN_GROUP*/ +#endif /* MFBD_PARAMS_SAME_IN_GROUP */ #define MFBD_NBTN_EXTERN(NAME) extern mfbd_nbtn_t NAME @@ -264,7 +266,7 @@ typedef struct _mfbd_mbtn_info_struct unsigned char max_multiclick_state; /* max multiclick states. */ } mfbd_mbtn_info_t; -#endif /*MFBD_PARAMS_SAME_IN_GROUP*/ +#endif /* MFBD_PARAMS_SAME_IN_GROUP */ /* * @Note: * repeat_count and long_count are conflict to multi-click. @@ -368,7 +370,7 @@ mfbd_mbtn_t NAME = { 0, \ } -#endif /*MFBD_PARAMS_SAME_IN_GROUP*/ +#endif /* MFBD_PARAMS_SAME_IN_GROUP */ #define MFBD_MBTN_EXTERN(NAME) extern mfbd_mbtn_t NAME @@ -386,19 +388,19 @@ typedef struct _mfbd_group_struct void (*btn_value_report)(mfbd_btn_code_t btn_value); #if MFBD_USE_TINY_BUTTON - /* pointer to the head of tiny buttons array */ + /* pointer to the head of tiny buttons pointer array */ mfbd_tbtn_t **tbtns; -#endif +#endif /* MFBD_USE_TINY_BUTTON */ #if MFBD_USE_NORMAL_BUTTON - /* pointer to the head of normal buttons array */ + /* pointer to the head of normal buttons pointer array */ mfbd_nbtn_t **nbtns; -#endif +#endif /* MFBD_USE_NORMAL_BUTTON */ #if MFBD_USE_MULTIFUCNTION_BUTTON - /* pointer to the head of multifunction buttons array */ + /* pointer to the head of multifunction buttons pointer array */ mfbd_mbtn_t **mbtns; -#endif +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ /* if set MFBD_PARAMS_SAME_IN_GROUP to 1, all btns in group has same params. */ #if MFBD_PARAMS_SAME_IN_GROUP @@ -413,25 +415,25 @@ typedef struct _mfbd_group_struct mfbd_btn_count_t long_time; /* long time when button still down, set 0 will disable long time and repeat time count. */ -#endif /* MFBD_USE_NORMAL_BUTTON || MFBD_USE_MULTIFUCNTION_BUTTON */ +#endif /* MFBD_USE_NORMAL_BUTTON || MFBD_USE_MULTIFUCNTION_BUTTON */ #if MFBD_USE_MULTIFUCNTION_BUTTON mfbd_btn_count_t multiclick_time; /* multi-click time when button still up, set 0 will disable multi-click time count. */ -#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ -#endif +#endif /* MFBD_PARAMS_SAME_IN_GROUP */ #if MFBD_USE_BTN_SCAN_PRE_FUNC /* prepare function when start to scan buttons for each group. */ void (*btn_scan_prepare)(void); -#endif +#endif /* MFBD_USE_BTN_SCAN_PRE_FUNC */ #if MFBD_USE_BTN_SCAN_AFTER_FUNC /* function after scanning buttons for each group. */ void (*btn_scan_after)(void); -#endif +#endif /* MFBD_USE_BTN_SCAN_AFTER_FUNC */ } mfbd_group_t; @@ -443,4 +445,4 @@ extern void mfbd_group_reset(const mfbd_group_t *_pbtn_group); #endif /* (MFBD_USE_SECTION_DEFINITION == 0) */ -#endif +#endif /* _MFBD_H_ */ diff --git a/mfbd_cfg.h b/mfbd_cfg.h index badc903..0f02949 100644 --- a/mfbd_cfg.h +++ b/mfbd_cfg.h @@ -5,13 +5,14 @@ * * Change Logs: * Date Author Notes - * 2022-02-22 smartmx the first version - * 2022-03-15 smartmx each mbtn has it's own max multi-click times + * 2022-02-22 smartmx the first version. + * 2022-03-15 smartmx each mbtn has it's own max multi-click times. * 2022-04-16 smartmx drop list definitions, use arraylist, each group has all btn types. * 2022-08-05 smartmx add reset params function. * 2022-12-04 smartmx change some definitions, add rtconfig.h. * 2023-03-25 smartmx add some comment. * 2023-07-03 smartmx add Section Definition option. + * 2023-07-22 smartmx add MFBD_MBTN_MULTICLICK_LONG_EVT and MFBD_MBTN_CONTINUE_LONG_COUNT option. * */ @@ -152,4 +153,28 @@ #define MFBD_MULTICLICK_STATE_AUTO_RESET 0 #endif +/* set MFBD_MBTN_CONTINUE_LONG_COUNT to 1 will continue count to change state to long after when multiclick state is not 0. */ +#ifdef PKG_MFBD_MBTN_CONTINUE_LONG_COUNT + #define MFBD_MBTN_CONTINUE_LONG_COUNT 1 +#else + /* if you are not use mfbd in rt-thread, you can change this instead. */ + #define MFBD_MBTN_CONTINUE_LONG_COUNT 0 +#endif + +#if MFBD_MBTN_CONTINUE_LONG_COUNT +/* + * @Note: + * MFBD_MBTN_MULTICLICK_LONG_EVT only valid when MFBD_MBTN_CONTINUE_LONG_COUNT is not 0. + * When MFBD_MBTN_MULTICLICK_LONG_EVT is 1, it will still report long code and repeat downcodes after multiclick. + */ +#ifdef PKG_MFBD_MBTN_MULTICLICK_LONG_EVT + #define MFBD_MBTN_MULTICLICK_LONG_EVT 1 +#else + /* if you are not use mfbd in rt-thread, you can change this instead. */ + #define MFBD_MBTN_MULTICLICK_LONG_EVT 0 +#endif +#else + #define MFBD_MBTN_MULTICLICK_LONG_EVT 0 +#endif + #endif /* _MFBD_CFG_H_ */ diff --git a/mfbd_sd.c b/mfbd_sd.c index 4eae7b3..b027263 100644 --- a/mfbd_sd.c +++ b/mfbd_sd.c @@ -7,6 +7,8 @@ * 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. + * 2023-07-22 smartmx add MFBD_MBTN_MULTICLICK_LONG_EVT and MFBD_MBTN_CONTINUE_LONG_COUNT option. + * 2023-09-19 smartmx improve performance, add MFBD_BTN_STATE_SKIP. * */ @@ -14,6 +16,9 @@ #if MFBD_USE_SECTION_DEFINITION +#define MFBD_BTN_IN_FUC (_pbtn_info->btn) +#define MFBD_BTN_INFO_IN_FUC (_pbtn_info) + #if MFBD_PARAMS_SAME_IN_GROUP /* filter_time */ @@ -36,7 +41,7 @@ /* multiclick_time */ #define MFBD_MULTICLICK_TIME_IN_FUC (_pbtn_info->multiclick_time) -#endif /*MFBD_PARAMS_SAME_IN_GROUP*/ +#endif /* MFBD_PARAMS_SAME_IN_GROUP */ #if MFBD_USE_TINY_BUTTON @@ -52,6 +57,7 @@ void mfbd_tbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_tbtn_info_t *_pbtn_info_start, const mfbd_tbtn_info_t *_pbtn_info_end) { const mfbd_tbtn_info_t *_pbtn_info = _pbtn_info_start; + MFBD_BTN_STATE_t btn_state; while (1) { @@ -59,48 +65,53 @@ void mfbd_tbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_tbtn_info_t *_pb { break; } - if (_pbtn_group->is_btn_down_func(_pbtn_info->btn_index) != MFBD_BTN_STATE_UP) + + btn_state = _pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->btn_index); + if (btn_state == MFBD_BTN_STATE_DOWN) { - if (_pbtn_info->btn->filter_count < (MFBD_FILTER_TIME_IN_FUC)) - { - _pbtn_info->btn->filter_count = (MFBD_FILTER_TIME_IN_FUC); - } - else if (_pbtn_info->btn->filter_count < ((MFBD_FILTER_TIME_IN_FUC) * 2)) - { - _pbtn_info->btn->filter_count++; - } - else + if (MFBD_BTN_IN_FUC->filter_count >= ((MFBD_FILTER_TIME_IN_FUC) * 2)) { /* it means the button is down for over filter_time. */ - if (_pbtn_info->btn->state == MFBD_BTN_STATE_UP) + if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_UP) { - if (_pbtn_info->btn_down_code > 0) + if (MFBD_BTN_INFO_IN_FUC->btn_down_code > 0) { - _pbtn_group->btn_value_report(_pbtn_info->btn_down_code); + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code); } - _pbtn_info->btn->state = MFBD_BTN_STATE_DOWN; + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_DOWN; } } - } - else - { - if (_pbtn_info->btn->filter_count > (MFBD_FILTER_TIME_IN_FUC)) + else if (MFBD_BTN_IN_FUC->filter_count >= (MFBD_FILTER_TIME_IN_FUC)) { - _pbtn_info->btn->filter_count = (MFBD_FILTER_TIME_IN_FUC); + MFBD_BTN_IN_FUC->filter_count++; } - else if (_pbtn_info->btn->filter_count != 0) + else { - _pbtn_info->btn->filter_count--; + MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC); } - else + } + else if (btn_state == MFBD_BTN_STATE_UP) + { + if (MFBD_BTN_IN_FUC->filter_count == 0) { - if (_pbtn_info->btn->state != MFBD_BTN_STATE_UP) + if (MFBD_BTN_IN_FUC->state != MFBD_BTN_STATE_UP) { - if (_pbtn_info->btn_up_code > 0) + if (MFBD_BTN_INFO_IN_FUC->btn_up_code > 0) { - _pbtn_group->btn_value_report(_pbtn_info->btn_up_code); + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_up_code); } - _pbtn_info->btn->state = MFBD_BTN_STATE_UP; + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP; + } + } + else + { + if (MFBD_BTN_IN_FUC->filter_count > (MFBD_FILTER_TIME_IN_FUC)) + { + MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC); + } + else if (MFBD_BTN_IN_FUC->filter_count != 0) + { + MFBD_BTN_IN_FUC->filter_count--; } } } @@ -125,14 +136,14 @@ void mfbd_tbtn_reset(const mfbd_tbtn_info_t *_pbtn_info_start, const mfbd_tbtn_i { break; } - _pbtn_info->btn->filter_count = 0; - _pbtn_info->btn->state = MFBD_BTN_STATE_UP; + MFBD_BTN_IN_FUC->filter_count = 0; + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP; _pbtn_info++; } } -#endif +#endif /* MFBD_USE_TINY_BUTTON */ #if MFBD_USE_NORMAL_BUTTON @@ -149,87 +160,114 @@ void mfbd_tbtn_reset(const mfbd_tbtn_info_t *_pbtn_info_start, const mfbd_tbtn_i void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_nbtn_info_t *_pbtn_info_start, const mfbd_nbtn_info_t *_pbtn_info_end) { const mfbd_nbtn_info_t *_pbtn_info = _pbtn_info_start; + MFBD_BTN_STATE_t btn_state; + while (1) { if (_pbtn_info_end <= _pbtn_info) { break; } - if (_pbtn_group->is_btn_down_func(_pbtn_info->btn_index) != MFBD_BTN_STATE_UP) + + btn_state = _pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->btn_index); + if (btn_state == MFBD_BTN_STATE_DOWN) { - if (_pbtn_info->btn->filter_count < (MFBD_FILTER_TIME_IN_FUC)) - { - _pbtn_info->btn->filter_count = (MFBD_FILTER_TIME_IN_FUC); - } - else if (_pbtn_info->btn->filter_count < ((MFBD_FILTER_TIME_IN_FUC) * 2)) - { - _pbtn_info->btn->filter_count++; - } - else + if (MFBD_BTN_IN_FUC->filter_count >= ((MFBD_FILTER_TIME_IN_FUC) * 2)) { /* it means the button is down for over filter_time. */ - if (_pbtn_info->btn->state == MFBD_BTN_STATE_UP) + if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) { - /* clear long_count. */ - _pbtn_info->btn->long_count = 0; - if (_pbtn_info->btn_down_code > 0) + /* MFBD_BTN_STATE_LONG */ + if (MFBD_BTN_IN_FUC->repeat_count > 0) { - _pbtn_group->btn_value_report(_pbtn_info->btn_down_code); + MFBD_BTN_IN_FUC->repeat_count++; + if (MFBD_BTN_IN_FUC->repeat_count > (MFBD_REPEAT_TIME_IN_FUC)) + { + /* repeat event has happened, reset repeat_count to 1. */ + MFBD_BTN_IN_FUC->repeat_count = 1; + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code); + } } - _pbtn_info->btn->state = MFBD_BTN_STATE_DOWN; } - else + else if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) { - if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn_info->btn_long_code != 0)) + if (MFBD_BTN_IN_FUC->long_count > 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_BTN_IN_FUC->long_count <= (MFBD_LONG_TIME_IN_FUC)) { - _pbtn_info->btn->long_count++; - if (_pbtn_info->btn->long_count >= (MFBD_LONG_TIME_IN_FUC)) + MFBD_BTN_IN_FUC->long_count++; + if (MFBD_BTN_IN_FUC->long_count > (MFBD_LONG_TIME_IN_FUC)) { /* it means the button is down for over long_time. */ - _pbtn_info->btn->repeat_count = 0; /* long event has happened, clear repeat_count. */ - _pbtn_group->btn_value_report(_pbtn_info->btn_long_code); - _pbtn_info->btn->state = MFBD_BTN_STATE_LONG; - } - } - else - { - if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code != 0)) - { - _pbtn_info->btn->repeat_count++; - if (_pbtn_info->btn->repeat_count >= (MFBD_REPEAT_TIME_IN_FUC)) + if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (MFBD_BTN_INFO_IN_FUC->btn_down_code != 0)) { - /* repeat event has happened, clear repeat_count. */ - _pbtn_info->btn->repeat_count = 0; - _pbtn_group->btn_value_report(_pbtn_info->btn_down_code); + /* repeat event is enabled in this btn. */ + MFBD_BTN_IN_FUC->repeat_count = 1; } + else + { + /* repeat event is disabled in this btn. */ + MFBD_BTN_IN_FUC->repeat_count = 0; + } + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_long_code); + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_LONG; } } } } + else + { + /* MFBD_BTN_STATE_UP */ + /* clear long_count. */ + if (((MFBD_LONG_TIME_IN_FUC) > 0) && (MFBD_BTN_INFO_IN_FUC->btn_long_code != 0)) + { + /* long event is enabled in this btn. */ + MFBD_BTN_IN_FUC->long_count = 1; + } + else + { + /* long event is disabled in this btn. */ + MFBD_BTN_IN_FUC->long_count = 0; + } + if (MFBD_BTN_INFO_IN_FUC->btn_down_code > 0) + { + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code); + } + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_DOWN; + } } - } - else - { - if (_pbtn_info->btn->filter_count > (MFBD_FILTER_TIME_IN_FUC)) + else if (MFBD_BTN_IN_FUC->filter_count >= (MFBD_FILTER_TIME_IN_FUC)) { - _pbtn_info->btn->filter_count = (MFBD_FILTER_TIME_IN_FUC); + MFBD_BTN_IN_FUC->filter_count++; } - else if (_pbtn_info->btn->filter_count != 0) + else { - _pbtn_info->btn->filter_count--; + MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC); } - else + } + else if (btn_state == MFBD_BTN_STATE_UP) + { + if (MFBD_BTN_IN_FUC->filter_count == 0) { - if (_pbtn_info->btn->state != MFBD_BTN_STATE_UP) + if (MFBD_BTN_IN_FUC->state != MFBD_BTN_STATE_UP) { - if (_pbtn_info->btn_up_code > 0) + if (MFBD_BTN_INFO_IN_FUC->btn_up_code > 0) { - _pbtn_group->btn_value_report(_pbtn_info->btn_up_code); + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_up_code); } - _pbtn_info->btn->state = MFBD_BTN_STATE_UP; + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP; + } + } + else + { + if (MFBD_BTN_IN_FUC->filter_count > (MFBD_FILTER_TIME_IN_FUC)) + { + MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC); + } + else if (MFBD_BTN_IN_FUC->filter_count != 0) + { + MFBD_BTN_IN_FUC->filter_count--; } } } @@ -255,35 +293,31 @@ void mfbd_nbtn_skip(const mfbd_group_t *_pbtn_group, const mfbd_nbtn_info_t *_pb { break; } - if(_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN) + if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) { - if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn_info->btn_long_code != 0)) + if ((MFBD_BTN_IN_FUC->long_count > 0) && (MFBD_BTN_IN_FUC->long_count < (MFBD_LONG_TIME_IN_FUC))) { - /* 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) - MFBD_BTN_IN_FUC->long_count) > times) { - 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; - } + MFBD_BTN_IN_FUC->long_count = MFBD_BTN_IN_FUC->long_count + times; + } + else + { + MFBD_BTN_IN_FUC->long_count = MFBD_LONG_TIME_IN_FUC; } } } - else if(_pbtn_info->btn->state == MFBD_BTN_STATE_LONG) + else if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) { - if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code != 0)) + if ((MFBD_BTN_IN_FUC->repeat_count > 0) && (MFBD_BTN_IN_FUC->repeat_count < (MFBD_REPEAT_TIME_IN_FUC))) { - if(((MFBD_REPEAT_TIME_IN_FUC) - 1 - _pbtn_info->btn->repeat_count) > times) + if (((MFBD_REPEAT_TIME_IN_FUC) - MFBD_BTN_IN_FUC->repeat_count) > times) { - _pbtn_info->btn->repeat_count = _pbtn_info->btn->repeat_count + times; + MFBD_BTN_IN_FUC->repeat_count = MFBD_BTN_IN_FUC->repeat_count + times; } else { - _pbtn_info->btn->repeat_count = MFBD_REPEAT_TIME_IN_FUC - 1; + MFBD_BTN_IN_FUC->repeat_count = MFBD_REPEAT_TIME_IN_FUC; } } } @@ -308,16 +342,16 @@ void mfbd_nbtn_reset(const mfbd_nbtn_info_t *_pbtn_info_start, const mfbd_nbtn_i { break; } - _pbtn_info->btn->filter_count = 0; - _pbtn_info->btn->long_count = 0; - _pbtn_info->btn->repeat_count = 0; - _pbtn_info->btn->state = MFBD_BTN_STATE_UP; + MFBD_BTN_IN_FUC->filter_count = 0; + MFBD_BTN_IN_FUC->long_count = 0; + MFBD_BTN_IN_FUC->repeat_count = 0; + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP; _pbtn_info++; } } -#endif +#endif /* MFBD_USE_NORMAL_BUTTON */ #if MFBD_USE_MULTIFUCNTION_BUTTON @@ -334,6 +368,8 @@ void mfbd_nbtn_reset(const mfbd_nbtn_info_t *_pbtn_info_start, const mfbd_nbtn_i void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd_mbtn_info_t *_pbtn_info_end) { const mfbd_mbtn_info_t *_pbtn_info = _pbtn_info_start; + MFBD_BTN_STATE_t btn_state; + while (1) { if (_pbtn_info_end <= _pbtn_info) @@ -341,124 +377,226 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb break; } - if (_pbtn_group->is_btn_down_func(_pbtn_info->btn_index) != MFBD_BTN_STATE_UP) + btn_state = _pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->btn_index); + if (btn_state == MFBD_BTN_STATE_DOWN) { - if (_pbtn_info->btn->filter_count < (MFBD_FILTER_TIME_IN_FUC)) - { - _pbtn_info->btn->filter_count = (MFBD_FILTER_TIME_IN_FUC); - } - else if (_pbtn_info->btn->filter_count < ((MFBD_FILTER_TIME_IN_FUC) * 2)) - { - _pbtn_info->btn->filter_count++; - } - else + if (MFBD_BTN_IN_FUC->filter_count >= ((MFBD_FILTER_TIME_IN_FUC) * 2)) { /* it means the button is down for over filter_time. */ - if (_pbtn_info->btn->state == MFBD_BTN_STATE_UP) +#if MFBD_MBTN_CONTINUE_LONG_COUNT +#if MFBD_MBTN_MULTICLICK_LONG_EVT + if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) { - /* clear long_count. */ - _pbtn_info->btn->long_count = 0; - if (_pbtn_info->btn_down_code[_pbtn_info->btn->multiclick_state] > 0) + /* MFBD_BTN_STATE_LONG */ + if (MFBD_BTN_IN_FUC->repeat_count > 0) { - _pbtn_group->btn_value_report(_pbtn_info->btn_down_code[_pbtn_info->btn->multiclick_state]); + MFBD_BTN_IN_FUC->repeat_count++; + if (MFBD_BTN_IN_FUC->repeat_count > (MFBD_REPEAT_TIME_IN_FUC)) + { + /* repeat event has happened, clear repeat_count. */ + MFBD_BTN_IN_FUC->repeat_count = 1; + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code[MFBD_BTN_IN_FUC->multiclick_state]); + } } - _pbtn_info->btn->state = MFBD_BTN_STATE_DOWN; } - else + else if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) { - if (_pbtn_info->btn->multiclick_state == 0) + if (MFBD_BTN_IN_FUC->long_count > 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 (MFBD_BTN_IN_FUC->long_count <= (MFBD_LONG_TIME_IN_FUC)) { - /* 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)) + MFBD_BTN_IN_FUC->long_count++; + if (MFBD_BTN_IN_FUC->long_count > (MFBD_LONG_TIME_IN_FUC)) { - _pbtn_info->btn->long_count++; - if (_pbtn_info->btn->long_count >= (MFBD_LONG_TIME_IN_FUC)) + /* it means the button is down for over long_time. */ + if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (MFBD_BTN_INFO_IN_FUC->btn_down_code[MFBD_BTN_IN_FUC->multiclick_state] != 0)) { - /* it means the button is down for over long_time. */ - _pbtn_info->btn->repeat_count = 0; /* long event has happened, clear repeat_count. */ - _pbtn_group->btn_value_report(_pbtn_info->btn_long_code); - _pbtn_info->btn->state = MFBD_BTN_STATE_LONG; + /* repeat event is enabled in this btn. */ + MFBD_BTN_IN_FUC->repeat_count = 1; + } + else + { + /* repeat event is disabled in this btn. */ + MFBD_BTN_IN_FUC->repeat_count = 0; } + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_long_code); + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_LONG; } - else + } + } + } +#else + if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) + { + /* we don't support repeat event here.*/ + } + else if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) + { + if (MFBD_BTN_IN_FUC->long_count > 0) + { + /* if long_time is 0 or long_code is 0, disable long and repeat check. */ + if (MFBD_BTN_IN_FUC->long_count <= (MFBD_LONG_TIME_IN_FUC)) + { + MFBD_BTN_IN_FUC->long_count++; + if (MFBD_BTN_IN_FUC->long_count > (MFBD_LONG_TIME_IN_FUC)) + { + /* it means the button is down for over long_time. */ + if (MFBD_BTN_IN_FUC->multiclick_state == 0) + { + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_long_code); + } + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_LONG; + } + } + } + } +#endif /* MFBD_MBTN_MULTICLICK_LONG_EVT */ +#else + if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) + { + /* MFBD_BTN_STATE_LONG */ + if (MFBD_BTN_IN_FUC->repeat_count > 0) + { + MFBD_BTN_IN_FUC->repeat_count++; + if (MFBD_BTN_IN_FUC->repeat_count > (MFBD_REPEAT_TIME_IN_FUC)) + { + /* repeat event has happened, clear repeat_count. */ + MFBD_BTN_IN_FUC->repeat_count = 1; + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code[0]); + } + } + } + else if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) + { + if (MFBD_BTN_IN_FUC->multiclick_state == 0) + { + if (MFBD_BTN_IN_FUC->long_count > 0) + { + /* if long_time is 0 or long_code is 0, disable long and repeat check. */ + if (MFBD_BTN_IN_FUC->long_count <= (MFBD_LONG_TIME_IN_FUC)) { - if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[0] != 0)) + MFBD_BTN_IN_FUC->long_count++; + if (MFBD_BTN_IN_FUC->long_count > (MFBD_LONG_TIME_IN_FUC)) { - _pbtn_info->btn->repeat_count++; - if (_pbtn_info->btn->repeat_count >= (MFBD_REPEAT_TIME_IN_FUC)) + /* it means the button is down for over long_time. */ + if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (MFBD_BTN_INFO_IN_FUC->btn_down_code[0] != 0)) + { + /* repeat event is enabled in this btn. */ + MFBD_BTN_IN_FUC->repeat_count = 1; + } + else { - /* repeat event has happened, clear repeat_count. */ - _pbtn_info->btn->repeat_count = 0; - _pbtn_group->btn_value_report(_pbtn_info->btn_down_code[0]); + /* repeat event is disabled in this btn. */ + MFBD_BTN_IN_FUC->repeat_count = 0; } + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_long_code); + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_LONG; } } } } } +#endif /* MFBD_MBTN_CONTINUE_LONG_COUNT */ + else + { + /* MFBD_BTN_STATE_UP */ + /* clear long_count. */ + if (((MFBD_LONG_TIME_IN_FUC) > 0) && (MFBD_BTN_INFO_IN_FUC->btn_long_code != 0)) + { + /* long event is enabled in this btn. */ + MFBD_BTN_IN_FUC->long_count = 1; + } + else + { + /* long event is disabled in this btn. */ + MFBD_BTN_IN_FUC->long_count = 0; + } + if (MFBD_BTN_INFO_IN_FUC->btn_down_code[MFBD_BTN_IN_FUC->multiclick_state] > 0) + { + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code[MFBD_BTN_IN_FUC->multiclick_state]); + } + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_DOWN; + } } - } - else - { - if (_pbtn_info->btn->filter_count > (MFBD_FILTER_TIME_IN_FUC)) + else if (MFBD_BTN_IN_FUC->filter_count >= (MFBD_FILTER_TIME_IN_FUC)) { - _pbtn_info->btn->filter_count = (MFBD_FILTER_TIME_IN_FUC); + MFBD_BTN_IN_FUC->filter_count++; } - else if (_pbtn_info->btn->filter_count != 0) + else { - _pbtn_info->btn->filter_count--; + MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC); } - else + } + else if (btn_state == MFBD_BTN_STATE_UP) + { + if (MFBD_BTN_IN_FUC->filter_count == 0) { - if (_pbtn_info->btn->state != MFBD_BTN_STATE_UP) + if (MFBD_BTN_IN_FUC->state != MFBD_BTN_STATE_UP) { #if MFBD_MULTICLICK_STATE_AUTO_RESET /* if multiclick_state is not 0 and less than max_multiclick_state, inc multiclick_state */ - if (((MFBD_MULTICLICK_TIME_IN_FUC) != 0) \ - && (_pbtn_info->btn->multiclick_state < _pbtn_info->max_multiclick_state) \ - && (_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN)) + if (((MFBD_MULTICLICK_TIME_IN_FUC) != 0) + && (MFBD_BTN_IN_FUC->multiclick_state < MFBD_BTN_INFO_IN_FUC->max_multiclick_state) +#if (MFBD_MBTN_CONTINUE_LONG_COUNT==0) + && (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) +#endif /* (MFBD_MBTN_CONTINUE_LONG_COUNT==0) */ + ) { - _pbtn_info->btn->multiclick_state++; - _pbtn_info->btn->multiclick_count = 0; + MFBD_BTN_IN_FUC->multiclick_state++; + MFBD_BTN_IN_FUC->multiclick_count = 0; } #else /* if multiclick_state is not 0 and less than max_multiclick_state, inc multiclick_state */ - if (((MFBD_MULTICLICK_TIME_IN_FUC) != 0) \ - && (_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN)) + if (((MFBD_MULTICLICK_TIME_IN_FUC) != 0) +#if (MFBD_MBTN_CONTINUE_LONG_COUNT==0) + && (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) +#endif /* (MFBD_MBTN_CONTINUE_LONG_COUNT==0) */ + ) { - if(_pbtn_info->btn->multiclick_state < _pbtn_info->max_multiclick_state) + if (MFBD_BTN_IN_FUC->multiclick_state < MFBD_BTN_INFO_IN_FUC->max_multiclick_state) { - _pbtn_info->btn->multiclick_state++; + MFBD_BTN_IN_FUC->multiclick_state++; } - _pbtn_info->btn->multiclick_count = 0; + MFBD_BTN_IN_FUC->multiclick_count = 0; } -#endif +#endif /* MFBD_MULTICLICK_STATE_AUTO_RESET */ else { /* over max multi-click times or (long event and repeat event) happened, reset to 0. */ - _pbtn_info->btn->multiclick_state = 0; + MFBD_BTN_IN_FUC->multiclick_state = 0; } - if (_pbtn_info->btn_up_code > 0) + if (MFBD_BTN_INFO_IN_FUC->btn_up_code > 0) { - _pbtn_group->btn_value_report(_pbtn_info->btn_up_code); + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_up_code); } - _pbtn_info->btn->state = MFBD_BTN_STATE_UP; + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP; } else { - if (_pbtn_info->btn->multiclick_state != 0) + if (MFBD_BTN_IN_FUC->multiclick_state != 0) { - _pbtn_info->btn->multiclick_count++; - if (_pbtn_info->btn->multiclick_count >= (MFBD_MULTICLICK_TIME_IN_FUC)) + MFBD_BTN_IN_FUC->multiclick_count++; + if (MFBD_BTN_IN_FUC->multiclick_count >= (MFBD_MULTICLICK_TIME_IN_FUC)) { - _pbtn_info->btn->multiclick_state = 0; + MFBD_BTN_IN_FUC->multiclick_state = 0; } } } } + else + { + if (MFBD_BTN_IN_FUC->filter_count > (MFBD_FILTER_TIME_IN_FUC)) + { + MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC); + } + else if (MFBD_BTN_IN_FUC->filter_count != 0) + { + MFBD_BTN_IN_FUC->filter_count--; + } + } } + _pbtn_info++; } } @@ -476,58 +614,108 @@ void mfbd_mbtn_skip(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb const mfbd_mbtn_info_t *_pbtn_info = _pbtn_info_start; while (1) { - if(_pbtn_info->btn->state == MFBD_BTN_STATE_UP) + if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_UP) { - if (_pbtn_info->btn->multiclick_state != 0) + if (MFBD_BTN_IN_FUC->multiclick_state != 0) { - if (_pbtn_info->btn->multiclick_count < (MFBD_MULTICLICK_TIME_IN_FUC)) + if (MFBD_BTN_IN_FUC->multiclick_count < (MFBD_MULTICLICK_TIME_IN_FUC)) { - if(((MFBD_MULTICLICK_TIME_IN_FUC) - _pbtn_info->btn->multiclick_count) > times) + if (((MFBD_MULTICLICK_TIME_IN_FUC) - MFBD_BTN_IN_FUC->multiclick_count) > times) { - _pbtn_info->btn->multiclick_count = _pbtn_info->btn->multiclick_count + times; + MFBD_BTN_IN_FUC->multiclick_count = MFBD_BTN_IN_FUC->multiclick_count + times; } else { - _pbtn_info->btn->multiclick_state = 0; + MFBD_BTN_IN_FUC->multiclick_state = 0; } } } } - else if(_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN) +#if MFBD_MBTN_CONTINUE_LONG_COUNT +#if MFBD_MBTN_MULTICLICK_LONG_EVT + else if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) { - if (_pbtn_info->btn->multiclick_state == 0) + if ((MFBD_BTN_IN_FUC->long_count > 0) && (MFBD_BTN_IN_FUC->long_count < (MFBD_LONG_TIME_IN_FUC))) { - if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn_info->btn_long_code != 0)) + if (((MFBD_LONG_TIME_IN_FUC) - MFBD_BTN_IN_FUC->long_count) > times) { - /* 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; - } - } + MFBD_BTN_IN_FUC->long_count = MFBD_BTN_IN_FUC->long_count + times; + } + else + { + MFBD_BTN_IN_FUC->long_count = MFBD_LONG_TIME_IN_FUC; + } + } + } + else + { + /* MFBD_BTN_STATE_LONG, if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) */ + if ((MFBD_BTN_IN_FUC->repeat_count > 0) && (MFBD_BTN_IN_FUC->repeat_count < (MFBD_REPEAT_TIME_IN_FUC))) + { + if (((MFBD_REPEAT_TIME_IN_FUC) - MFBD_BTN_IN_FUC->repeat_count) > times) + { + MFBD_BTN_IN_FUC->repeat_count = MFBD_BTN_IN_FUC->repeat_count + times; + } + else + { + MFBD_BTN_IN_FUC->repeat_count = MFBD_REPEAT_TIME_IN_FUC; } } } - else if(_pbtn_info->btn->state == MFBD_BTN_STATE_LONG) +#else + else if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) { - if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[0] != 0)) + if ((MFBD_BTN_IN_FUC->long_count > 0) && (MFBD_BTN_IN_FUC->long_count < (MFBD_LONG_TIME_IN_FUC))) { - if(((MFBD_REPEAT_TIME_IN_FUC) - 1 - _pbtn_info->btn->repeat_count) > times) + /* if long_time is 0 or long_code is 0, disable long and repeat check. */ + if (((MFBD_LONG_TIME_IN_FUC) - MFBD_BTN_IN_FUC->long_count) > times) { - _pbtn_info->btn->repeat_count = _pbtn_info->btn->repeat_count + times; + MFBD_BTN_IN_FUC->long_count = MFBD_BTN_IN_FUC->long_count + times; } else { - _pbtn_info->btn->repeat_count = MFBD_REPEAT_TIME_IN_FUC - 1; + MFBD_BTN_IN_FUC->long_count = MFBD_LONG_TIME_IN_FUC; } } } + else + { + /* MFBD_BTN_STATE_LONG, if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) */ + /* we don't support repeat event here.*/ + } +#endif /* MFBD_MBTN_MULTICLICK_LONG_EVT */ +#else + else if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) + { + if ((MFBD_BTN_IN_FUC->long_count > 0) && (MFBD_BTN_IN_FUC->long_count < (MFBD_LONG_TIME_IN_FUC))) + { + if (((MFBD_LONG_TIME_IN_FUC) - MFBD_BTN_IN_FUC->long_count) > times) + { + MFBD_BTN_IN_FUC->long_count = MFBD_BTN_IN_FUC->long_count + times; + } + else + { + MFBD_BTN_IN_FUC->long_count = MFBD_LONG_TIME_IN_FUC; + } + } + } + else + { + /* MFBD_BTN_STATE_LONG, if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) */ + if ((MFBD_BTN_IN_FUC->repeat_count > 0) && (MFBD_BTN_IN_FUC->repeat_count < (MFBD_REPEAT_TIME_IN_FUC))) + { + if (((MFBD_REPEAT_TIME_IN_FUC) - MFBD_BTN_IN_FUC->repeat_count) > times) + { + MFBD_BTN_IN_FUC->repeat_count = MFBD_BTN_IN_FUC->repeat_count + times; + } + else + { + MFBD_BTN_IN_FUC->repeat_count = MFBD_REPEAT_TIME_IN_FUC; + } + } + } +#endif /* MFBD_MBTN_CONTINUE_LONG_COUNT */ + _pbtn_info++; } } @@ -549,17 +737,17 @@ void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd_mbtn_i { break; } - _pbtn_info->btn->filter_count = 0; - _pbtn_info->btn->long_count = 0; - _pbtn_info->btn->multiclick_count = 0; - _pbtn_info->btn->multiclick_state = 0; - _pbtn_info->btn->repeat_count = 0; - _pbtn_info->btn->state = MFBD_BTN_STATE_UP; + MFBD_BTN_IN_FUC->filter_count = 0; + MFBD_BTN_IN_FUC->long_count = 0; + MFBD_BTN_IN_FUC->multiclick_count = 0; + MFBD_BTN_IN_FUC->multiclick_state = 0; + MFBD_BTN_IN_FUC->repeat_count = 0; + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP; _pbtn_info++; } } -#endif +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ -#endif /*MFBD_USE_SECTION_DEFINITION*/ +#endif /* MFBD_USE_SECTION_DEFINITION */ diff --git a/mfbd_sd.h b/mfbd_sd.h index 5794784..dd75f1d 100644 --- a/mfbd_sd.h +++ b/mfbd_sd.h @@ -7,6 +7,7 @@ * 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. + * 2023-09-19 smartmx improve performance, add MFBD_BTN_STATE_SKIP. * */ @@ -22,6 +23,7 @@ typedef enum MFBD_BTN_STATE_UP = 0, MFBD_BTN_STATE_DOWN, MFBD_BTN_STATE_LONG, + MFBD_BTN_STATE_SKIP = 0xff, } MFBD_BTN_STATE_t; #define MFBD_DOWN_CODE_NAME(NAME) NAME##_DOWN_CODE /* when using tbtn/nbtn default define api, this is down-code name. */ @@ -83,7 +85,7 @@ typedef struct _mfbd_tbtn_info_struct mfbd_btn_index_t btn_index; /* parameter when calling is_btn_down_func. */ } mfbd_tbtn_info_t; -#endif /*MFBD_PARAMS_SAME_IN_GROUP*/ +#endif /* MFBD_PARAMS_SAME_IN_GROUP */ #if MFBD_PARAMS_SAME_IN_GROUP @@ -139,7 +141,7 @@ typedef struct _mfbd_tbtn_info_struct BTN_INDEX, \ } -#endif /*MFBD_PARAMS_SAME_IN_GROUP*/ +#endif /* MFBD_PARAMS_SAME_IN_GROUP */ #define MFBD_TBTN_EXTERN(NAME) extern mfbd_tbtn_t NAME @@ -178,7 +180,7 @@ typedef struct _mfbd_nbtn_info_struct mfbd_btn_index_t btn_index; /* parameter when calling is_btn_down_func. */ } mfbd_nbtn_info_t; -#endif /*MFBD_PARAMS_SAME_IN_GROUP*/ +#endif /* MFBD_PARAMS_SAME_IN_GROUP */ #if MFBD_PARAMS_SAME_IN_GROUP @@ -251,7 +253,7 @@ typedef struct _mfbd_nbtn_info_struct BTN_INDEX, \ } -#endif /*MFBD_PARAMS_SAME_IN_GROUP*/ +#endif /* MFBD_PARAMS_SAME_IN_GROUP */ #define MFBD_NBTN_EXTERN(NAME) extern mfbd_nbtn_t NAME @@ -302,7 +304,7 @@ typedef struct _mfbd_mbtn_info_struct unsigned char max_multiclick_state; /* max multiclick states. */ } mfbd_mbtn_info_t; -#endif /*MFBD_PARAMS_SAME_IN_GROUP*/ +#endif /* MFBD_PARAMS_SAME_IN_GROUP */ #if MFBD_PARAMS_SAME_IN_GROUP @@ -390,7 +392,7 @@ typedef struct _mfbd_mbtn_info_struct MAX_MULTICLICK_STATE, \ } -#endif /*MFBD_PARAMS_SAME_IN_GROUP*/ +#endif /* MFBD_PARAMS_SAME_IN_GROUP */ #define MFBD_MBTN_EXTERN(NAME) extern mfbd_mbtn_t NAME @@ -425,17 +427,17 @@ typedef struct _mfbd_group_struct #endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ -#endif +#endif /* MFBD_PARAMS_SAME_IN_GROUP */ #if MFBD_USE_BTN_SCAN_PRE_FUNC /* prepare function when start to scan buttons for each group. */ void (*btn_scan_prepare)(void); -#endif +#endif /* MFBD_USE_BTN_SCAN_PRE_FUNC */ #if MFBD_USE_BTN_SCAN_AFTER_FUNC /* function after scanning buttons for each group. */ void (*btn_scan_after)(void); -#endif +#endif /* MFBD_USE_BTN_SCAN_AFTER_FUNC */ } mfbd_group_t; @@ -480,7 +482,7 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd #else #define MFBD_GROUP_SCAN_TBTN(GROUP) do{} while(0) #define MFBD_GROUP_RESET_TBTN(GROUP) do{} while(0) -#endif +#endif /* MFBD_USE_TINY_BUTTON */ #if MFBD_USE_NORMAL_BUTTON #define MFBD_GROUP_SCAN_NBTN(GROUP) \ @@ -508,7 +510,7 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd #define MFBD_GROUP_SCAN_NBTN(GROUP) do{} while(0) #define MFBD_GROUP_SKIP_NBTN(GROUP, TIMES) do{} while(0) #define MFBD_GROUP_RESET_NBTN(GROUP) do{} while(0) -#endif +#endif /* MFBD_USE_NORMAL_BUTTON */ #if MFBD_USE_MULTIFUCNTION_BUTTON #define MFBD_GROUP_SCAN_MBTN(GROUP) \ @@ -536,7 +538,7 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd #define MFBD_GROUP_SCAN_MBTN(GROUP) do{} while(0) #define MFBD_GROUP_SKIP_MBTN(GROUP, TIMES) do{} while(0) #define MFBD_GROUP_RESET_MBTN(GROUP) do{} while(0) -#endif +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ #elif defined (__IAR_SYSTEMS_ICC__) /* IAR Compiler */ @@ -553,7 +555,8 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd } while (0) #else #define MFBD_GROUP_SCAN_TBTN(GROUP) do{} while(0) -#endif +#endif /* MFBD_USE_TINY_BUTTON */ + #if MFBD_USE_NORMAL_BUTTON #define MFBD_GROUP_SCAN_NBTN(GROUP) \ do \ @@ -574,7 +577,8 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd #define MFBD_GROUP_SCAN_NBTN(GROUP) do{} while(0) #define MFBD_GROUP_SKIP_NBTN(GROUP, TIMES) do{} while(0) #define MFBD_GROUP_RESET_NBTN(GROUP) do{} while(0) -#endif +#endif /* MFBD_USE_NORMAL_BUTTON */ + #if MFBD_USE_MULTIFUCNTION_BUTTON #define MFBD_GROUP_SCAN_MBTN(GROUP) \ do \ @@ -595,7 +599,7 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd #define MFBD_GROUP_SCAN_MBTN(GROUP) do{} while(0) #define MFBD_GROUP_SKIP_MBTN(GROUP, TIMES) do{} while(0) #define MFBD_GROUP_RESET_MBTN(GROUP) do{} while(0) -#endif +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ #elif defined (__GNUC__) /* GNU GCC Compiler */ @@ -617,7 +621,7 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd #else #define MFBD_GROUP_SCAN_TBTN(GROUP) do{} while(0) #define MFBD_GROUP_RESET_TBTN(GROUP) do{} while(0) -#endif +#endif /* MFBD_USE_TINY_BUTTON */ #if MFBD_USE_NORMAL_BUTTON #define MFBD_GROUP_SCAN_NBTN(GROUP) \ @@ -645,7 +649,7 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd #define MFBD_GROUP_SCAN_NBTN(GROUP) do{} while(0) #define MFBD_GROUP_SKIP_NBTN(GROUP, TIMES) do{} while(0) #define MFBD_GROUP_RESET_NBTN(GROUP) do{} while(0) -#endif +#endif /* MFBD_USE_NORMAL_BUTTON */ #if MFBD_USE_MULTIFUCNTION_BUTTON #define MFBD_GROUP_SCAN_MBTN(GROUP) \ @@ -673,7 +677,7 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd #define MFBD_GROUP_SCAN_MBTN(GROUP) do{} while(0) #define MFBD_GROUP_SKIP_MBTN(GROUP, TIMES) do{} while(0) #define MFBD_GROUP_RESET_MBTN(GROUP) do{} while(0) -#endif +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ #else #error "not supported tool chain..." @@ -708,7 +712,7 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd /* * @Note: * this in a example for how to scan or reset the mfbd group, - * if some group has not all btn types, you should write code by youself. + * if some group has not all btn types, you should write code by yourself. */ #define MFBD_GROUP_SCAN(GROUP) \ do \ @@ -735,6 +739,6 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd MFBD_GROUP_RESET_MBTN(GROUP); \ } while (0) -#endif /*MFBD_USE_SECTION_DEFINITION*/ +#endif /* MFBD_USE_SECTION_DEFINITION */ -#endif +#endif /* _MFBD_SD_H_ */