From 1d4618ffd6c1b6d470f99ca51ca6b9cf7fce0965 Mon Sep 17 00:00:00 2001 From: CoderNotCute <30313912+smartmx@users.noreply.github.com> Date: Fri, 21 Jul 2023 08:07:51 +0800 Subject: [PATCH 01/14] Update mfbd_cfg.h --- mfbd_cfg.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mfbd_cfg.h b/mfbd_cfg.h index badc903..181d86d 100644 --- a/mfbd_cfg.h +++ b/mfbd_cfg.h @@ -152,4 +152,12 @@ #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 + #endif /* _MFBD_CFG_H_ */ From 4a943d8e09c91d251be73f6f3b0c0319315cba66 Mon Sep 17 00:00:00 2001 From: CoderNotCute <30313912+smartmx@users.noreply.github.com> Date: Sat, 22 Jul 2023 16:04:13 +0800 Subject: [PATCH 02/14] update change the way to handle state. --- mfbd.c | 54 ++++++++++++++++++++++++++++-------------------------- mfbd_sd.c | 54 ++++++++++++++++++++++++++++-------------------------- 2 files changed, 56 insertions(+), 52 deletions(-) diff --git a/mfbd.c b/mfbd.c index fca465b..b010838 100644 --- a/mfbd.c +++ b/mfbd.c @@ -171,7 +171,7 @@ void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group) } _pbtn->state = MFBD_BTN_STATE_DOWN; } - else + else if(_pbtn->state == MFBD_BTN_STATE_DOWN) { if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_long_code != 0)) { @@ -187,18 +187,19 @@ void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group) _pbtn->state = MFBD_BTN_STATE_LONG; } } - else + } + } + else + { + /* MFBD_BTN_STATE_LONG */ + 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)) { - 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); - } - } + /* repeat event has happened, clear repeat_count. */ + _pbtn->repeat_count = 0; + _pbtn_group->btn_value_report(_pbtn->btn_info->btn_down_code); } } } @@ -347,7 +348,7 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group) _pbtn_group->btn_value_report(_pbtn->btn_info->btn_down_code[_pbtn->multiclick_state]); } } - else + else if(_pbtn->state == MFBD_BTN_STATE_DOWN) { if (_pbtn->multiclick_state == 0) { @@ -365,19 +366,20 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group) _pbtn->state = MFBD_BTN_STATE_LONG; } } - else - { - if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_down_code[0] != 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]); - } - } - } + } + } + } + else + { + /* MFBD_BTN_STATE_LONG */ + if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_down_code[0] != 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]); } } } diff --git a/mfbd_sd.c b/mfbd_sd.c index 4eae7b3..8f4ec10 100644 --- a/mfbd_sd.c +++ b/mfbd_sd.c @@ -178,7 +178,7 @@ void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_nbtn_info_t *_pb } _pbtn_info->btn->state = MFBD_BTN_STATE_DOWN; } - else + else if(_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN) { if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn_info->btn_long_code != 0)) { @@ -194,18 +194,19 @@ void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_nbtn_info_t *_pb _pbtn_info->btn->state = MFBD_BTN_STATE_LONG; } } - else + } + } + else + { + /* MFBD_BTN_STATE_LONG */ + 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) && (_pbtn_info->btn_down_code != 0)) - { - _pbtn_info->btn->repeat_count++; - if (_pbtn_info->btn->repeat_count >= (MFBD_REPEAT_TIME_IN_FUC)) - { - /* 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 has happened, clear repeat_count. */ + _pbtn_info->btn->repeat_count = 0; + _pbtn_group->btn_value_report(_pbtn_info->btn_down_code); } } } @@ -364,7 +365,7 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb } _pbtn_info->btn->state = MFBD_BTN_STATE_DOWN; } - else + else if(_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN) { if (_pbtn_info->btn->multiclick_state == 0) { @@ -382,19 +383,20 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb _pbtn_info->btn->state = MFBD_BTN_STATE_LONG; } } - else - { - if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[0] != 0)) - { - _pbtn_info->btn->repeat_count++; - if (_pbtn_info->btn->repeat_count >= (MFBD_REPEAT_TIME_IN_FUC)) - { - /* repeat event has happened, clear repeat_count. */ - _pbtn_info->btn->repeat_count = 0; - _pbtn_group->btn_value_report(_pbtn_info->btn_down_code[0]); - } - } - } + } + } + } + else + { + /* MFBD_BTN_STATE_LONG */ + if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[0] != 0)) + { + _pbtn_info->btn->repeat_count++; + if (_pbtn_info->btn->repeat_count >= (MFBD_REPEAT_TIME_IN_FUC)) + { + /* repeat event has happened, clear repeat_count. */ + _pbtn_info->btn->repeat_count = 0; + _pbtn_group->btn_value_report(_pbtn_info->btn_down_code[0]); } } } From ae4d79efd8e7845dce763a089d7a6c2c66c7139f Mon Sep 17 00:00:00 2001 From: CoderNotCute <30313912+smartmx@users.noreply.github.com> Date: Sat, 22 Jul 2023 16:44:50 +0800 Subject: [PATCH 03/14] update add MFBD_MBTN_MULTICLICK_LONG_EVT and MFBD_MBTN_CONTINUE_LONG_COUNT option. --- mfbd.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++- mfbd_cfg.h | 17 ++++++++++++++ mfbd_sd.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 1 deletion(-) diff --git a/mfbd.c b/mfbd.c index b010838..4757587 100644 --- a/mfbd.c +++ b/mfbd.c @@ -12,6 +12,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-07-22 smartmx add MFBD_MBTN_MULTICLICK_LONG_EVT and MFBD_MBTN_CONTINUE_LONG_COUNT option. * */ @@ -189,7 +190,7 @@ void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group) } } } - else + else { /* MFBD_BTN_STATE_LONG */ if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_down_code != 0)) @@ -348,6 +349,69 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group) _pbtn_group->btn_value_report(_pbtn->btn_info->btn_down_code[_pbtn->multiclick_state]); } } +#if MFBD_MBTN_CONTINUE_LONG_COUNT +#if MFBD_MBTN_MULTICLICK_LONG_EVT + else if(_pbtn->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->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_info->btn_long_code); + _pbtn->state = MFBD_BTN_STATE_LONG; + } + } + } + } + else + { + /* MFBD_BTN_STATE_LONG */ + if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[_pbtn->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_info->btn_down_code[_pbtn->multiclick_state]]); + } + } + } +#else + else if(_pbtn->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->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 (_pbtn->multiclick_state == 0) + { + _pbtn->repeat_count = 0; /* long event has happened, clear repeat_count. */ + _pbtn_group->btn_value_report(_pbtn_info->btn_long_code); + } + _pbtn->state = MFBD_BTN_STATE_LONG; + } + } + } + } + else + { + /* MFBD_BTN_STATE_LONG */ + /* we don't support repeat event here.*/ + } +#endif /* MFBD_MBTN_MULTICLICK_LONG_EVT */ +#else else if(_pbtn->state == MFBD_BTN_STATE_DOWN) { if (_pbtn->multiclick_state == 0) @@ -383,6 +447,7 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group) } } } +#endif /* MFBD_MBTN_CONTINUE_LONG_COUNT */ } } else diff --git a/mfbd_cfg.h b/mfbd_cfg.h index 181d86d..bf0c909 100644 --- a/mfbd_cfg.h +++ b/mfbd_cfg.h @@ -12,6 +12,7 @@ * 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. * */ @@ -160,4 +161,20 @@ #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 8f4ec10..c65a141 100644 --- a/mfbd_sd.c +++ b/mfbd_sd.c @@ -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-07-22 smartmx add MFBD_MBTN_MULTICLICK_LONG_EVT and MFBD_MBTN_CONTINUE_LONG_COUNT option. * */ @@ -365,6 +366,69 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb } _pbtn_info->btn->state = MFBD_BTN_STATE_DOWN; } +#if MFBD_MBTN_CONTINUE_LONG_COUNT +#if MFBD_MBTN_MULTICLICK_LONG_EVT + else 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)) + { + _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. */ + _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 + { + /* MFBD_BTN_STATE_LONG */ + if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[_pbtn_info->btn->multiclick_state]] != 0)) + { + _pbtn_info->btn->repeat_count++; + if (_pbtn_info->btn->repeat_count >= (MFBD_REPEAT_TIME_IN_FUC)) + { + /* repeat event has happened, clear repeat_count. */ + _pbtn_info->btn->repeat_count = 0; + _pbtn_group->btn_value_report(_pbtn_info->btn_down_code[_pbtn_info->btn->multiclick_state]]); + } + } + } +#else + else 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)) + { + _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 (_pbtn_info->btn->multiclick_state == 0) + { + _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 + { + /* MFBD_BTN_STATE_LONG */ + /* we don't support repeat event here.*/ + } +#endif /* MFBD_MBTN_MULTICLICK_LONG_EVT */ +#else else if(_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN) { if (_pbtn_info->btn->multiclick_state == 0) @@ -400,6 +464,7 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb } } } +#endif /* MFBD_MBTN_CONTINUE_LONG_COUNT */ } } else From 8872eed020792d9c8442a8c4bb7292267c1c5036 Mon Sep 17 00:00:00 2001 From: CoderNotCute <30313912+smartmx@users.noreply.github.com> Date: Mon, 24 Jul 2023 07:35:05 +0800 Subject: [PATCH 04/14] update some comments --- mfbd.c | 34 +++++++++++++++++----------------- mfbd.h | 30 +++++++++++++++--------------- mfbd_sd.c | 16 ++++++++-------- mfbd_sd.h | 42 ++++++++++++++++++++++-------------------- 4 files changed, 62 insertions(+), 60 deletions(-) diff --git a/mfbd.c b/mfbd.c index 4757587..3a3ab53 100644 --- a/mfbd.c +++ b/mfbd.c @@ -42,7 +42,7 @@ /* multiclick_time */ #define MFBD_MULTICLICK_TIME_IN_FUC (_pbtn->btn_info->multiclick_time) -#endif /*MFBD_PARAMS_SAME_IN_GROUP*/ +#endif /* MFBD_PARAMS_SAME_IN_GROUP */ #if MFBD_USE_TINY_BUTTON @@ -130,7 +130,7 @@ void mfbd_tbtn_reset(const mfbd_group_t *_pbtn_group) } } -#endif +#endif /* MFBD_USE_TINY_BUTTON */ #if MFBD_USE_NORMAL_BUTTON @@ -308,7 +308,7 @@ void mfbd_nbtn_reset(const mfbd_group_t *_pbtn_group) } } -#endif +#endif /* MFBD_USE_NORMAL_BUTTON */ #if MFBD_USE_MULTIFUCNTION_BUTTON @@ -410,7 +410,7 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group) /* MFBD_BTN_STATE_LONG */ /* we don't support repeat event here.*/ } -#endif /* MFBD_MBTN_MULTICLICK_LONG_EVT */ +#endif /* MFBD_MBTN_MULTICLICK_LONG_EVT */ #else else if(_pbtn->state == MFBD_BTN_STATE_DOWN) { @@ -447,7 +447,7 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group) } } } -#endif /* MFBD_MBTN_CONTINUE_LONG_COUNT */ +#endif /* MFBD_MBTN_CONTINUE_LONG_COUNT */ } } else @@ -484,7 +484,7 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group) } _pbtn->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. */ @@ -611,7 +611,7 @@ void mfbd_mbtn_reset(const mfbd_group_t *_pbtn_group) } } -#endif +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ /** @@ -630,7 +630,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) @@ -638,7 +638,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) @@ -646,7 +646,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) @@ -654,7 +654,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) @@ -662,7 +662,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 */ } @@ -685,7 +685,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) @@ -693,7 +693,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 */ } @@ -714,7 +714,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) @@ -722,7 +722,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) @@ -730,7 +730,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..840c860 100644 --- a/mfbd.h +++ b/mfbd.h @@ -56,7 +56,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 +119,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 +151,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 +229,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 +264,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 +368,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 @@ -388,17 +388,17 @@ typedef struct _mfbd_group_struct #if MFBD_USE_TINY_BUTTON /* pointer to the head of tiny buttons array */ mfbd_tbtn_t **tbtns; -#endif +#endif /* MFBD_USE_TINY_BUTTON */ #if MFBD_USE_NORMAL_BUTTON /* pointer to the head of normal buttons array */ mfbd_nbtn_t **nbtns; -#endif +#endif /* MFBD_USE_NORMAL_BUTTON */ #if MFBD_USE_MULTIFUCNTION_BUTTON /* pointer to the head of multifunction buttons 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 +413,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 +443,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_sd.c b/mfbd_sd.c index c65a141..f38264e 100644 --- a/mfbd_sd.c +++ b/mfbd_sd.c @@ -37,7 +37,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 @@ -133,7 +133,7 @@ void mfbd_tbtn_reset(const mfbd_tbtn_info_t *_pbtn_info_start, const mfbd_tbtn_i } } -#endif +#endif /* MFBD_USE_TINY_BUTTON */ #if MFBD_USE_NORMAL_BUTTON @@ -319,7 +319,7 @@ void mfbd_nbtn_reset(const mfbd_nbtn_info_t *_pbtn_info_start, const mfbd_nbtn_i } } -#endif +#endif /* MFBD_USE_NORMAL_BUTTON */ #if MFBD_USE_MULTIFUCNTION_BUTTON @@ -427,7 +427,7 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb /* MFBD_BTN_STATE_LONG */ /* we don't support repeat event here.*/ } -#endif /* MFBD_MBTN_MULTICLICK_LONG_EVT */ +#endif /* MFBD_MBTN_MULTICLICK_LONG_EVT */ #else else if(_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN) { @@ -464,7 +464,7 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb } } } -#endif /* MFBD_MBTN_CONTINUE_LONG_COUNT */ +#endif /* MFBD_MBTN_CONTINUE_LONG_COUNT */ } } else @@ -501,7 +501,7 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb } _pbtn_info->btn->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. */ @@ -627,6 +627,6 @@ void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd_mbtn_i } } -#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..bbf1482 100644 --- a/mfbd_sd.h +++ b/mfbd_sd.h @@ -83,7 +83,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 +139,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 +178,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 +251,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 +302,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 +390,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 +425,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 +480,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 +508,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 +536,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 +553,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 +575,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 +597,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 +619,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 +647,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 +675,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..." @@ -735,6 +737,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_ */ From 5ed6d3a2c5893aa10e8adf2e5887d9507f0806f0 Mon Sep 17 00:00:00 2001 From: CoderNotCute <30313912+smartmx@users.noreply.github.com> Date: Mon, 24 Jul 2023 07:54:29 +0800 Subject: [PATCH 05/14] update update mbtn-skip function. --- mfbd.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++- mfbd_sd.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 125 insertions(+), 2 deletions(-) diff --git a/mfbd.c b/mfbd.c index 3a3ab53..706654e 100644 --- a/mfbd.c +++ b/mfbd.c @@ -546,6 +546,66 @@ void mfbd_mbtn_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times) } } } +#if MFBD_MBTN_CONTINUE_LONG_COUNT +#if MFBD_MBTN_MULTICLICK_LONG_EVT + else if(_pbtn->state == MFBD_BTN_STATE_DOWN) + { + 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)) + { + 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; + } + } + } + } + else if(_pbtn->state == MFBD_BTN_STATE_LONG) + { + if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_down_code[_pbtn->multiclick_state] != 0)) + { + if(((MFBD_REPEAT_TIME_IN_FUC) - 1 - _pbtn->repeat_count) > times) + { + _pbtn->repeat_count = _pbtn->repeat_count + times; + } + else + { + _pbtn->repeat_count = MFBD_REPEAT_TIME_IN_FUC - 1; + } + } + } +#else + else if(_pbtn->state == MFBD_BTN_STATE_DOWN) + { + 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)) + { + 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; + } + } + } + } + else + { + /* MFBD_BTN_STATE_LONG */ + /* we don't support repeat event here.*/ + } +#endif /* MFBD_MBTN_MULTICLICK_LONG_EVT */ +#else else if(_pbtn->state == MFBD_BTN_STATE_DOWN) { if (_pbtn->multiclick_state == 0) @@ -581,7 +641,7 @@ void mfbd_mbtn_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times) } } } - +#endif /* MFBD_MBTN_CONTINUE_LONG_COUNT */ _ppbtn++; _pbtn = *_ppbtn; } diff --git a/mfbd_sd.c b/mfbd_sd.c index f38264e..a63a62d 100644 --- a/mfbd_sd.c +++ b/mfbd_sd.c @@ -560,6 +560,67 @@ void mfbd_mbtn_skip(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb } } } +#if MFBD_MBTN_CONTINUE_LONG_COUNT +#if MFBD_MBTN_MULTICLICK_LONG_EVT + else 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 + { + /* MFBD_BTN_STATE_LONG, if(_pbtn_info->btn->state == MFBD_BTN_STATE_LONG) */ + if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[_pbtn_info->btn->multiclick_state] != 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; + } + } + } +#else + else 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 + { + /* MFBD_BTN_STATE_LONG, if(_pbtn_info->btn->state == MFBD_BTN_STATE_LONG) */ + /* we don't support repeat event here.*/ + } +#endif /* MFBD_MBTN_MULTICLICK_LONG_EVT */ +#else else if(_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN) { if (_pbtn_info->btn->multiclick_state == 0) @@ -581,8 +642,9 @@ void mfbd_mbtn_skip(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb } } } - else if(_pbtn_info->btn->state == MFBD_BTN_STATE_LONG) + else { + /* MFBD_BTN_STATE_LONG, 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) @@ -595,6 +657,7 @@ void mfbd_mbtn_skip(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb } } } +#endif /* MFBD_MBTN_CONTINUE_LONG_COUNT */ _pbtn_info++; } } From cdca31b95a5266dfb5ffaabb8320a8a7b8880957 Mon Sep 17 00:00:00 2001 From: smartmx <30313912+smartmx@users.noreply.github.com> Date: Mon, 24 Jul 2023 13:29:32 +0800 Subject: [PATCH 06/14] fix --- mfbd.c | 28 +++++++++++++++++----------- mfbd_sd.c | 20 +++++++++++++------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/mfbd.c b/mfbd.c index 706654e..5853af2 100644 --- a/mfbd.c +++ b/mfbd.c @@ -353,7 +353,7 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group) #if MFBD_MBTN_MULTICLICK_LONG_EVT else if(_pbtn->state == MFBD_BTN_STATE_DOWN) { - if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn_info->btn_long_code != 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 (_pbtn->long_count < (MFBD_LONG_TIME_IN_FUC)) @@ -363,7 +363,7 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group) { /* 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_info->btn_long_code); + _pbtn_group->btn_value_report(_pbtn->btn_info->btn_long_code); _pbtn->state = MFBD_BTN_STATE_LONG; } } @@ -372,21 +372,21 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group) else { /* MFBD_BTN_STATE_LONG */ - if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[_pbtn->multiclick_state]] != 0)) + if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_down_code[_pbtn->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_info->btn_down_code[_pbtn->multiclick_state]]); + _pbtn_group->btn_value_report(_pbtn->btn_info->btn_down_code[_pbtn->multiclick_state]); } } } #else else if(_pbtn->state == MFBD_BTN_STATE_DOWN) { - if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn_info->btn_long_code != 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 (_pbtn->long_count < (MFBD_LONG_TIME_IN_FUC)) @@ -398,7 +398,7 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group) if (_pbtn->multiclick_state == 0) { _pbtn->repeat_count = 0; /* long event has happened, clear repeat_count. */ - _pbtn_group->btn_value_report(_pbtn_info->btn_long_code); + _pbtn_group->btn_value_report(_pbtn->btn_info->btn_long_code); } _pbtn->state = MFBD_BTN_STATE_LONG; } @@ -466,17 +466,23 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group) { #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)) + if (((MFBD_MULTICLICK_TIME_IN_FUC) != 0) + && (_pbtn->multiclick_state < _pbtn->btn_info->max_multiclick_state) +#if (MFBD_MBTN_CONTINUE_LONG_COUNT==0) + && (_pbtn->state == MFBD_BTN_STATE_DOWN) +#endif /* (MFBD_MBTN_CONTINUE_LONG_COUNT==0) */ + ) { _pbtn->multiclick_state++; _pbtn->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->state == MFBD_BTN_STATE_DOWN)) + if (((MFBD_MULTICLICK_TIME_IN_FUC) != 0) +#if (MFBD_MBTN_CONTINUE_LONG_COUNT==0) + && (_pbtn->state == MFBD_BTN_STATE_DOWN) +#endif /* (MFBD_MBTN_CONTINUE_LONG_COUNT==0) */ + ) { if(_pbtn->multiclick_state < _pbtn->btn_info->max_multiclick_state) { diff --git a/mfbd_sd.c b/mfbd_sd.c index a63a62d..e205d91 100644 --- a/mfbd_sd.c +++ b/mfbd_sd.c @@ -389,14 +389,14 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb else { /* MFBD_BTN_STATE_LONG */ - if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[_pbtn_info->btn->multiclick_state]] != 0)) + if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[_pbtn_info->btn->multiclick_state] != 0)) { _pbtn_info->btn->repeat_count++; if (_pbtn_info->btn->repeat_count >= (MFBD_REPEAT_TIME_IN_FUC)) { /* repeat event has happened, clear repeat_count. */ _pbtn_info->btn->repeat_count = 0; - _pbtn_group->btn_value_report(_pbtn_info->btn_down_code[_pbtn_info->btn->multiclick_state]]); + _pbtn_group->btn_value_report(_pbtn_info->btn_down_code[_pbtn_info->btn->multiclick_state]); } } } @@ -483,17 +483,23 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb { #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) + && (_pbtn_info->btn->multiclick_state < _pbtn_info->max_multiclick_state) +#if (MFBD_MBTN_CONTINUE_LONG_COUNT==0) + && (_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN) +#endif /* (MFBD_MBTN_CONTINUE_LONG_COUNT==0) */ + ) { _pbtn_info->btn->multiclick_state++; _pbtn_info->btn->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) + && (_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN) +#endif /* (MFBD_MBTN_CONTINUE_LONG_COUNT==0) */ + ) { if(_pbtn_info->btn->multiclick_state < _pbtn_info->max_multiclick_state) { From e0591e39ffabebde31370c8cddf6cc4bddd15f00 Mon Sep 17 00:00:00 2001 From: CoderNotCute <30313912+smartmx@users.noreply.github.com> Date: Wed, 26 Jul 2023 07:09:11 +0800 Subject: [PATCH 07/14] update update some comments. --- README.md | 15 +++++++++++++++ mfbd.c | 4 ++-- mfbd.h | 4 ++-- mfbd_cfg.h | 4 ++-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fa67d23..e714e3e 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; 连击事件中,每次按键按下后,都会上报指定次数的连击按键值。 其实连击事件是不应该由按键驱动层进行检测的,但是嵌入式环境资源紧张,不可以像电脑那样交给应用层处理。 **注意:多次连击事件和长按事件是冲突的,当长按事件发生,不会进行多次连击的检测。当触发多次连击检测后,也不会进行长按事件的检测** +通过配置宏`MFBD_MBTN_CONTINUE_LONG_COUNT`为1,和`MFBD_MBTN_MULTICLICK_LONG_EVT`为1,可以实现连击和长按的共存。 ## MFBD按键组结构体 diff --git a/mfbd.c b/mfbd.c index 5853af2..e3cca93 100644 --- a/mfbd.c +++ b/mfbd.c @@ -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 arraylist, each group has all btn types. * 2022-08-05 smartmx add reset params function. * 2023-03-15 smartmx add state declaration. diff --git a/mfbd.h b/mfbd.h index 840c860..d543496 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. diff --git a/mfbd_cfg.h b/mfbd_cfg.h index bf0c909..0f02949 100644 --- a/mfbd_cfg.h +++ b/mfbd_cfg.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 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. From eb940551608b974deb3c27cde0f2cba5c3c436c2 Mon Sep 17 00:00:00 2001 From: CoderNotCute <30313912+smartmx@users.noreply.github.com> Date: Wed, 26 Jul 2023 07:59:56 +0800 Subject: [PATCH 08/14] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e714e3e..ffd155b 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ 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按键事件 @@ -126,7 +126,7 @@ typedef uint32_t mfbd_btn_index_t; 连击事件中,每次按键按下后,都会上报指定次数的连击按键值。 其实连击事件是不应该由按键驱动层进行检测的,但是嵌入式环境资源紧张,不可以像电脑那样交给应用层处理。 **注意:多次连击事件和长按事件是冲突的,当长按事件发生,不会进行多次连击的检测。当触发多次连击检测后,也不会进行长按事件的检测** -通过配置宏`MFBD_MBTN_CONTINUE_LONG_COUNT`为1,和`MFBD_MBTN_MULTICLICK_LONG_EVT`为1,可以实现连击和长按的共存。 +在1.0.5版本后,可以通过配置宏`MFBD_MBTN_CONTINUE_LONG_COUNT`为1,和`MFBD_MBTN_MULTICLICK_LONG_EVT`为1,可以实现连击和长按的共存。 ## MFBD按键组结构体 From fb3ef4d1ae530c3647375ca0e1c61ddb98a48177 Mon Sep 17 00:00:00 2001 From: CoderNotCute <30313912+smartmx@users.noreply.github.com> Date: Thu, 27 Jul 2023 16:36:54 +0800 Subject: [PATCH 09/14] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ffd155b..d386e1d 100644 --- a/README.md +++ b/README.md @@ -516,19 +516,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) From d0f5d88ec3574fcdc27dddc3810e0ef4e6840686 Mon Sep 17 00:00:00 2001 From: CoderNotCute <30313912+smartmx@users.noreply.github.com> Date: Thu, 10 Aug 2023 20:40:37 +0800 Subject: [PATCH 10/14] update improve performance. --- mfbd.c | 648 +++++++++++++++++++++------------------- mfbd_sd.c | 870 ++++++++++++++++++++++++++++-------------------------- 2 files changed, 801 insertions(+), 717 deletions(-) diff --git a/mfbd.c b/mfbd.c index e3cca93..04594b6 100644 --- a/mfbd.c +++ b/mfbd.c @@ -13,6 +13,7 @@ * 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-08-10 smartmx improve performance. * */ @@ -20,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 */ @@ -34,13 +38,13 @@ #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 */ @@ -58,50 +62,53 @@ void mfbd_tbtn_scan(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) { - if (_pbtn_group->is_btn_down_func(_pbtn->btn_info->btn_index) != MFBD_BTN_STATE_UP) + if (_pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->btn_index) != MFBD_BTN_STATE_UP) { - 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 (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--; } } } @@ -121,10 +128,10 @@ 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; } @@ -147,84 +154,106 @@ void mfbd_nbtn_scan(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) { - if (_pbtn_group->is_btn_down_func(_pbtn->btn_info->btn_index) != MFBD_BTN_STATE_UP) + if (_pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->btn_index) != MFBD_BTN_STATE_UP) { - 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(_pbtn->state == MFBD_BTN_STATE_DOWN) - { - 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 - { - /* MFBD_BTN_STATE_LONG */ - 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 { - 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--; } } } @@ -246,37 +275,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; } } } @@ -297,12 +322,12 @@ 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; } @@ -324,194 +349,223 @@ 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) + while (MFBD_BTN_IN_FUC != NULL) { - if (_pbtn_group->is_btn_down_func(_pbtn->btn_info->btn_index) != MFBD_BTN_STATE_UP) + if (_pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->btn_index) != MFBD_BTN_STATE_UP) { - 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]); + } } } -#if MFBD_MBTN_CONTINUE_LONG_COUNT -#if MFBD_MBTN_MULTICLICK_LONG_EVT - else if(_pbtn->state == MFBD_BTN_STATE_DOWN) + else 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) { /* 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_BTN_IN_FUC->long_count <= (MFBD_LONG_TIME_IN_FUC)) { - _pbtn->long_count++; - 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)) { /* 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; + if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (MFBD_BTN_INFO_IN_FUC->btn_down_code[MFBD_BTN_IN_FUC->multiclick_state] != 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 +#else + if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) { - /* MFBD_BTN_STATE_LONG */ - if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_down_code[_pbtn->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[_pbtn->multiclick_state]); - } - } + /* we don't support repeat event here.*/ } -#else - else if(_pbtn->state == MFBD_BTN_STATE_DOWN) + else 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) { /* 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_BTN_IN_FUC->long_count <= (MFBD_LONG_TIME_IN_FUC)) { - _pbtn->long_count++; - 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)) { /* it means the button is down for over long_time. */ - if (_pbtn->multiclick_state == 0) + if (MFBD_BTN_IN_FUC->multiclick_state == 0) { - _pbtn->repeat_count = 0; /* long event has happened, clear repeat_count. */ - _pbtn_group->btn_value_report(_pbtn->btn_info->btn_long_code); + _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_long_code); } - _pbtn->state = MFBD_BTN_STATE_LONG; + MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_LONG; } } } } - else +#endif /* MFBD_MBTN_MULTICLICK_LONG_EVT */ +#else + if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) { /* MFBD_BTN_STATE_LONG */ - /* we don't support repeat event here.*/ + 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]); + } + } } -#endif /* MFBD_MBTN_MULTICLICK_LONG_EVT */ -#else - else if(_pbtn->state == MFBD_BTN_STATE_DOWN) + else if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) { - if (_pbtn->multiclick_state == 0) + if (MFBD_BTN_IN_FUC->multiclick_state == 0) { - if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn->btn_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->long_count < (MFBD_LONG_TIME_IN_FUC)) + if (MFBD_BTN_IN_FUC->long_count <= (MFBD_LONG_TIME_IN_FUC)) { - _pbtn->long_count++; - 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)) { /* 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; + 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; } } } } } +#endif /* MFBD_MBTN_CONTINUE_LONG_COUNT */ else { - /* MFBD_BTN_STATE_LONG */ - if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_down_code[0] != 0)) + /* MFBD_BTN_STATE_UP */ + /* clear long_count. */ + if (((MFBD_LONG_TIME_IN_FUC) > 0) && (MFBD_BTN_INFO_IN_FUC->btn_long_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[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; } -#endif /* MFBD_MBTN_CONTINUE_LONG_COUNT */ } - } - 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 (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 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) + /* 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) - && (_pbtn->state == MFBD_BTN_STATE_DOWN) + && (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) #endif /* (MFBD_MBTN_CONTINUE_LONG_COUNT==0) */ - ) - { - _pbtn->multiclick_state++; - _pbtn->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) + /* 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) - && (_pbtn->state == MFBD_BTN_STATE_DOWN) + && (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) #endif /* (MFBD_MBTN_CONTINUE_LONG_COUNT==0) */ - ) - { - if(_pbtn->multiclick_state < _pbtn->btn_info->max_multiclick_state) - { - _pbtn->multiclick_state++; - } - _pbtn->multiclick_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. */ - _pbtn->multiclick_state = 0; - } - 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; + 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)) + { + MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC); } - else + else if (MFBD_BTN_IN_FUC->filter_count != 0) { - 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--; } } } @@ -533,117 +587,105 @@ 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; } } } } #if MFBD_MBTN_CONTINUE_LONG_COUNT #if MFBD_MBTN_MULTICLICK_LONG_EVT - else if(_pbtn->state == MFBD_BTN_STATE_DOWN) + else 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_REPEAT_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_down_code[_pbtn->multiclick_state] != 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(_pbtn->state == MFBD_BTN_STATE_DOWN) + else 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 { - /* MFBD_BTN_STATE_LONG */ + /* 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(_pbtn->state == MFBD_BTN_STATE_DOWN) + 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; } } } @@ -664,14 +706,14 @@ 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; } diff --git a/mfbd_sd.c b/mfbd_sd.c index e205d91..1fc61a5 100644 --- a/mfbd_sd.c +++ b/mfbd_sd.c @@ -8,6 +8,7 @@ * 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-08-10 smartmx improve performance. * */ @@ -15,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 */ @@ -60,48 +64,51 @@ 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) + if (_pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->btn_index) != MFBD_BTN_STATE_UP) { - 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 (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--; } } } @@ -126,8 +133,8 @@ 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++; } @@ -156,82 +163,104 @@ void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_nbtn_info_t *_pb { break; } - if (_pbtn_group->is_btn_down_func(_pbtn_info->btn_index) != MFBD_BTN_STATE_UP) + if (_pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->btn_index) != MFBD_BTN_STATE_UP) { - if (_pbtn_info->btn->filter_count < (MFBD_FILTER_TIME_IN_FUC)) - { - _pbtn_info->btn->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_info->btn->filter_count < ((MFBD_FILTER_TIME_IN_FUC) * 2)) + else if(MFBD_BTN_IN_FUC->filter_count >= (MFBD_FILTER_TIME_IN_FUC)) { - _pbtn_info->btn->filter_count++; + MFBD_BTN_IN_FUC->filter_count++; } else { - /* it means the button is down for over filter_time. */ - if (_pbtn_info->btn->state == MFBD_BTN_STATE_UP) - { - /* clear long_count. */ - _pbtn_info->btn->long_count = 0; - if (_pbtn_info->btn_down_code > 0) - { - _pbtn_group->btn_value_report(_pbtn_info->btn_down_code); - } - _pbtn_info->btn->state = MFBD_BTN_STATE_DOWN; - } - else 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)) - { - _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. */ - _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 - { - /* MFBD_BTN_STATE_LONG */ - 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)) - { - /* repeat event has happened, clear repeat_count. */ - _pbtn_info->btn->repeat_count = 0; - _pbtn_group->btn_value_report(_pbtn_info->btn_down_code); - } - } - } + MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC); } } else { - if (_pbtn_info->btn->filter_count > (MFBD_FILTER_TIME_IN_FUC)) + if (MFBD_BTN_IN_FUC->filter_count == 0) { - _pbtn_info->btn->filter_count = (MFBD_FILTER_TIME_IN_FUC); - } - else if (_pbtn_info->btn->filter_count != 0) - { - _pbtn_info->btn->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_info->btn->state != MFBD_BTN_STATE_UP) + if (MFBD_BTN_IN_FUC->filter_count > (MFBD_FILTER_TIME_IN_FUC)) { - if (_pbtn_info->btn_up_code > 0) - { - _pbtn_group->btn_value_report(_pbtn_info->btn_up_code); - } - _pbtn_info->btn->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--; } } } @@ -257,35 +286,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; } } } @@ -310,10 +335,10 @@ 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++; } @@ -343,195 +368,225 @@ 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) - { - 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 - { - /* it means the button is down for over filter_time. */ - if (_pbtn_info->btn->state == MFBD_BTN_STATE_UP) - { - /* clear long_count. */ - _pbtn_info->btn->long_count = 0; - if (_pbtn_info->btn_down_code[_pbtn_info->btn->multiclick_state] > 0) - { - _pbtn_group->btn_value_report(_pbtn_info->btn_down_code[_pbtn_info->btn->multiclick_state]); - } - _pbtn_info->btn->state = MFBD_BTN_STATE_DOWN; - } -#if MFBD_MBTN_CONTINUE_LONG_COUNT -#if MFBD_MBTN_MULTICLICK_LONG_EVT - else 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)) - { - _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. */ - _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 - { - /* MFBD_BTN_STATE_LONG */ - if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[_pbtn_info->btn->multiclick_state] != 0)) - { - _pbtn_info->btn->repeat_count++; - if (_pbtn_info->btn->repeat_count >= (MFBD_REPEAT_TIME_IN_FUC)) - { - /* repeat event has happened, clear repeat_count. */ - _pbtn_info->btn->repeat_count = 0; - _pbtn_group->btn_value_report(_pbtn_info->btn_down_code[_pbtn_info->btn->multiclick_state]); - } - } - } -#else - else 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)) - { - _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 (_pbtn_info->btn->multiclick_state == 0) - { - _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 - { - /* MFBD_BTN_STATE_LONG */ - /* we don't support repeat event here.*/ - } -#endif /* MFBD_MBTN_MULTICLICK_LONG_EVT */ -#else - 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)) - { - _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. */ - _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 - { - /* MFBD_BTN_STATE_LONG */ - if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[0] != 0)) - { - _pbtn_info->btn->repeat_count++; - if (_pbtn_info->btn->repeat_count >= (MFBD_REPEAT_TIME_IN_FUC)) - { - /* repeat event has happened, clear repeat_count. */ - _pbtn_info->btn->repeat_count = 0; - _pbtn_group->btn_value_report(_pbtn_info->btn_down_code[0]); - } - } - } -#endif /* MFBD_MBTN_CONTINUE_LONG_COUNT */ - } - } - else - { - 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 != 0) - { - _pbtn_info->btn->filter_count--; - } - else - { - if (_pbtn_info->btn->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) -#if (MFBD_MBTN_CONTINUE_LONG_COUNT==0) - && (_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN) -#endif /* (MFBD_MBTN_CONTINUE_LONG_COUNT==0) */ - ) - { - _pbtn_info->btn->multiclick_state++; - _pbtn_info->btn->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) - && (_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN) -#endif /* (MFBD_MBTN_CONTINUE_LONG_COUNT==0) */ - ) - { - if(_pbtn_info->btn->multiclick_state < _pbtn_info->max_multiclick_state) - { - _pbtn_info->btn->multiclick_state++; - } - _pbtn_info->btn->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. */ - _pbtn_info->btn->multiclick_state = 0; - } - if (_pbtn_info->btn_up_code > 0) - { - _pbtn_group->btn_value_report(_pbtn_info->btn_up_code); - } - _pbtn_info->btn->state = MFBD_BTN_STATE_UP; - } - else - { - if (_pbtn_info->btn->multiclick_state != 0) - { - _pbtn_info->btn->multiclick_count++; - if (_pbtn_info->btn->multiclick_count >= (MFBD_MULTICLICK_TIME_IN_FUC)) - { - _pbtn_info->btn->multiclick_state = 0; - } - } - } - } - } + if (_pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->btn_index) != MFBD_BTN_STATE_UP) + { + 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_MBTN_CONTINUE_LONG_COUNT + #if MFBD_MBTN_MULTICLICK_LONG_EVT + 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[MFBD_BTN_IN_FUC->multiclick_state]); + } + } + } + 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[MFBD_BTN_IN_FUC->multiclick_state] != 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 + 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)) + { + 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; + } + } + } + } + } + #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(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 (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)) + { + 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++; } } @@ -549,121 +604,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 (_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; - } - } - } - } + if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_UP) + { + if (MFBD_BTN_IN_FUC->multiclick_state != 0) + { + if (MFBD_BTN_IN_FUC->multiclick_count < (MFBD_MULTICLICK_TIME_IN_FUC)) + { + if(((MFBD_MULTICLICK_TIME_IN_FUC) - MFBD_BTN_IN_FUC->multiclick_count) > times) + { + MFBD_BTN_IN_FUC->multiclick_count = MFBD_BTN_IN_FUC->multiclick_count + times; + } + else + { + MFBD_BTN_IN_FUC->multiclick_state = 0; + } + } + } + } #if MFBD_MBTN_CONTINUE_LONG_COUNT #if MFBD_MBTN_MULTICLICK_LONG_EVT - else 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 - { - /* MFBD_BTN_STATE_LONG, if(_pbtn_info->btn->state == MFBD_BTN_STATE_LONG) */ - if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[_pbtn_info->btn->multiclick_state] != 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; - } - } - } + 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; + } + } + } #else - else 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 - { - /* MFBD_BTN_STATE_LONG, if(_pbtn_info->btn->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) && (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(_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 - { - /* MFBD_BTN_STATE_LONG, 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; - } - } - } + 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++; } } @@ -685,12 +727,12 @@ 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++; } From 7567c4b71c1661e0c7264880a3bdf81a2d56634e Mon Sep 17 00:00:00 2001 From: CoderNotCute <30313912+smartmx@users.noreply.github.com> Date: Sun, 13 Aug 2023 18:41:52 +0800 Subject: [PATCH 11/14] update update some comments. --- mfbd.h | 6 +++--- mfbd_sd.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mfbd.h b/mfbd.h index d543496..e2a4daf 100644 --- a/mfbd.h +++ b/mfbd.h @@ -386,17 +386,17 @@ 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 /* 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 /* 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 /* MFBD_USE_MULTIFUCNTION_BUTTON */ diff --git a/mfbd_sd.h b/mfbd_sd.h index bbf1482..8cc480f 100644 --- a/mfbd_sd.h +++ b/mfbd_sd.h @@ -710,7 +710,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 \ From 61ddfbc27fa5f5e19d84ece5251617b12803ae5d Mon Sep 17 00:00:00 2001 From: CoderNotCute <30313912+smartmx@users.noreply.github.com> Date: Tue, 19 Sep 2023 20:57:31 +0800 Subject: [PATCH 12/14] update improve performance, add MFBD_BTN_STATE_SKIP. format code. --- mfbd.c | 21 +- mfbd.h | 2 + mfbd_sd.c | 788 +++++++++++++++++++++++++++--------------------------- mfbd_sd.h | 2 + 4 files changed, 417 insertions(+), 396 deletions(-) diff --git a/mfbd.c b/mfbd.c index 04594b6..8e30e07 100644 --- a/mfbd.c +++ b/mfbd.c @@ -13,7 +13,7 @@ * 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-08-10 smartmx improve performance. + * 2023-09-19 smartmx improve performance, add MFBD_BTN_STATE_SKIP. * */ @@ -61,10 +61,12 @@ 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 (MFBD_BTN_IN_FUC != NULL) { - if (_pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->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(MFBD_BTN_IN_FUC->filter_count >= ((MFBD_FILTER_TIME_IN_FUC) * 2)) { @@ -87,7 +89,7 @@ void mfbd_tbtn_scan(const mfbd_group_t *_pbtn_group) 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) { @@ -153,10 +155,12 @@ 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 (MFBD_BTN_IN_FUC != NULL) { - if (_pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->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(MFBD_BTN_IN_FUC->filter_count >= ((MFBD_FILTER_TIME_IN_FUC) * 2)) { @@ -232,7 +236,7 @@ void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group) 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) { @@ -349,9 +353,12 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group) { mfbd_mbtn_t **_ppbtn = _pbtn_group->mbtns; mfbd_mbtn_t *_pbtn = *_ppbtn; + MFBD_BTN_STATE_t btn_state; + while (MFBD_BTN_IN_FUC != NULL) { - if (_pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->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(MFBD_BTN_IN_FUC->filter_count >= ((MFBD_FILTER_TIME_IN_FUC) * 2)) { @@ -501,7 +508,7 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group) 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) { diff --git a/mfbd.h b/mfbd.h index e2a4daf..d69d334 100644 --- a/mfbd.h +++ b/mfbd.h @@ -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, } 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. */ diff --git a/mfbd_sd.c b/mfbd_sd.c index 1fc61a5..b027263 100644 --- a/mfbd_sd.c +++ b/mfbd_sd.c @@ -8,7 +8,7 @@ * 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-08-10 smartmx improve performance. + * 2023-09-19 smartmx improve performance, add MFBD_BTN_STATE_SKIP. * */ @@ -57,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) { @@ -64,9 +65,11 @@ void mfbd_tbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_tbtn_info_t *_pb { break; } - if (_pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->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(MFBD_BTN_IN_FUC->filter_count >= ((MFBD_FILTER_TIME_IN_FUC) * 2)) + 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_UP) @@ -78,7 +81,7 @@ void mfbd_tbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_tbtn_info_t *_pb MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_DOWN; } } - else if(MFBD_BTN_IN_FUC->filter_count >= (MFBD_FILTER_TIME_IN_FUC)) + else if (MFBD_BTN_IN_FUC->filter_count >= (MFBD_FILTER_TIME_IN_FUC)) { MFBD_BTN_IN_FUC->filter_count++; } @@ -87,7 +90,7 @@ void mfbd_tbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_tbtn_info_t *_pb 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) { @@ -157,80 +160,84 @@ 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(MFBD_BTN_INFO_IN_FUC->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(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; - } + 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(MFBD_BTN_IN_FUC->filter_count >= (MFBD_FILTER_TIME_IN_FUC)) + else if (MFBD_BTN_IN_FUC->filter_count >= (MFBD_FILTER_TIME_IN_FUC)) { MFBD_BTN_IN_FUC->filter_count++; } @@ -239,7 +246,7 @@ void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_nbtn_info_t *_pb 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) { @@ -286,11 +293,11 @@ void mfbd_nbtn_skip(const mfbd_group_t *_pbtn_group, const mfbd_nbtn_info_t *_pb { break; } - if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN) + 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) + 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; } @@ -300,11 +307,11 @@ void mfbd_nbtn_skip(const mfbd_group_t *_pbtn_group, const mfbd_nbtn_info_t *_pb } } } - else if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) + else 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) + 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; } @@ -361,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) @@ -368,224 +377,225 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb break; } - if (_pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->btn_index) != MFBD_BTN_STATE_UP) - { - 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_MBTN_CONTINUE_LONG_COUNT - #if MFBD_MBTN_MULTICLICK_LONG_EVT - 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[MFBD_BTN_IN_FUC->multiclick_state]); - } - } - } - 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[MFBD_BTN_IN_FUC->multiclick_state] != 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 - 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)) - { - 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; - } - } - } - } - } - #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(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 (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)) - { - 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--; - } - } - } + btn_state = _pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->btn_index); + if (btn_state == MFBD_BTN_STATE_DOWN) + { + 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_MBTN_CONTINUE_LONG_COUNT +#if MFBD_MBTN_MULTICLICK_LONG_EVT + 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[MFBD_BTN_IN_FUC->multiclick_state]); + } + } + } + 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[MFBD_BTN_IN_FUC->multiclick_state] != 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 + 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)) + { + 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; + } + } + } + } + } +#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 (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)) + { + 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++; } @@ -604,106 +614,106 @@ 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(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_UP) - { - if (MFBD_BTN_IN_FUC->multiclick_state != 0) - { - if (MFBD_BTN_IN_FUC->multiclick_count < (MFBD_MULTICLICK_TIME_IN_FUC)) - { - if(((MFBD_MULTICLICK_TIME_IN_FUC) - MFBD_BTN_IN_FUC->multiclick_count) > times) - { - MFBD_BTN_IN_FUC->multiclick_count = MFBD_BTN_IN_FUC->multiclick_count + times; - } - else - { - MFBD_BTN_IN_FUC->multiclick_state = 0; - } - } - } - } + if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_UP) + { + if (MFBD_BTN_IN_FUC->multiclick_state != 0) + { + if (MFBD_BTN_IN_FUC->multiclick_count < (MFBD_MULTICLICK_TIME_IN_FUC)) + { + if (((MFBD_MULTICLICK_TIME_IN_FUC) - MFBD_BTN_IN_FUC->multiclick_count) > times) + { + MFBD_BTN_IN_FUC->multiclick_count = MFBD_BTN_IN_FUC->multiclick_count + times; + } + else + { + MFBD_BTN_IN_FUC->multiclick_state = 0; + } + } + } + } #if MFBD_MBTN_CONTINUE_LONG_COUNT #if MFBD_MBTN_MULTICLICK_LONG_EVT - 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; - } - } - } + 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; + } + } + } #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.*/ - } + 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; - } - } - } + 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++; diff --git a/mfbd_sd.h b/mfbd_sd.h index 8cc480f..1e82ca8 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, } 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. */ From 6f0a43d51498bc45c5ba21ce7ec71afc786588e6 Mon Sep 17 00:00:00 2001 From: CoderNotCute <30313912+smartmx@users.noreply.github.com> Date: Wed, 20 Sep 2023 21:20:25 +0800 Subject: [PATCH 13/14] update --- mfbd.h | 2 +- mfbd_sd.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mfbd.h b/mfbd.h index d69d334..ac71a35 100644 --- a/mfbd.h +++ b/mfbd.h @@ -30,7 +30,7 @@ typedef enum MFBD_BTN_STATE_UP = 0, MFBD_BTN_STATE_DOWN, MFBD_BTN_STATE_LONG, - MFBD_BTN_STATE_SKIP, + 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. */ diff --git a/mfbd_sd.h b/mfbd_sd.h index 1e82ca8..dd75f1d 100644 --- a/mfbd_sd.h +++ b/mfbd_sd.h @@ -23,7 +23,7 @@ typedef enum MFBD_BTN_STATE_UP = 0, MFBD_BTN_STATE_DOWN, MFBD_BTN_STATE_LONG, - MFBD_BTN_STATE_SKIP, + 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. */ From 796d12352f99f5f1bb8d84d6833b7ebce57e3251 Mon Sep 17 00:00:00 2001 From: CoderNotCute <30313912+smartmx@users.noreply.github.com> Date: Sun, 24 Sep 2023 16:11:44 +0800 Subject: [PATCH 14/14] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d386e1d..36dd9ad 100644 --- a/README.md +++ b/README.md @@ -337,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) {