diff --git a/mfbd.c b/mfbd.c index 0d9b5a7..e8fd63b 100644 --- a/mfbd.c +++ b/mfbd.c @@ -11,6 +11,7 @@ * 2022-08-05 smartmx add reset params function. * 2023-03-15 smartmx add state declaration. * 2023-07-03 smartmx add Section Definition option. + * 2023-07-15 smartmx add skip function. * */ @@ -230,6 +231,59 @@ void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group) } } +/** + * @brief skip some times of mfbd_btn_count_t with last state. + * + * @param _pbtn_group is a pointer of mfbd_group_t. + * @param times is times need to skip. + * + * @return None. + */ +void mfbd_nbtn_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times) +{ + mfbd_nbtn_t **_ppbtn = _pbtn_group->nbtns; + mfbd_nbtn_t *_pbtn = *_ppbtn; + + while (_pbtn != NULL) + { + 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[0] != 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; + } + } + } + + _ppbtn++; + _pbtn = *_ppbtn; + } +} + /** * @brief reset all normal buttons' params. * @@ -393,6 +447,79 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group) } } +/** + * @brief skip some times of mfbd_btn_count_t with last state. + * + * @param _pbtn_group is a pointer of mfbd_group_t. + * @param times is times need to skip. + * + * @return None. + */ +void mfbd_mbtn_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times) +{ + mfbd_mbtn_t **_ppbtn = _pbtn_group->mbtns; + mfbd_mbtn_t *_pbtn = *_ppbtn; + + while (_pbtn != NULL) + { + if(_pbtn->state == MFBD_BTN_STATE_UP) + { + if (_pbtn->multiclick_state != 0) + { + if (_pbtn->multiclick_count < (MFBD_MULTICLICK_TIME_IN_FUC)) + { + if(((MFBD_MULTICLICK_TIME_IN_FUC) - _pbtn->multiclick_count) > times) + { + _pbtn->multiclick_count = _pbtn->multiclick_count + times; + } + else + { + _pbtn->multiclick_state = 0; + } + } + } + } + else if(_pbtn->state == MFBD_BTN_STATE_DOWN) + { + if (_pbtn->multiclick_state == 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)) + { + 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[0] != 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; + } + } + } + + _ppbtn++; + _pbtn = *_ppbtn; + } +} + /** * @brief reset all multi-function buttons' params. * @@ -473,6 +600,37 @@ void mfbd_group_scan(const mfbd_group_t *_pbtn_group) } +/** + * @brief skip some times with last state. + * + * @param _pbtn_group is a pointer of mfbd_group_t. + * @param times is times need to skip. + * + * @return None. + */ +void mfbd_group_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times) +{ + /* tbtn doesn't need to skip times. */ + +#if MFBD_USE_NORMAL_BUTTON + if (_pbtn_group->nbtns != NULL) + { + /* skip times of normal buttons in group.*/ + mfbd_nbtn_skip(_pbtn_group, times); + } +#endif + +#if MFBD_USE_MULTIFUCNTION_BUTTON + if (_pbtn_group->mbtns != NULL) + { + /* skip times of multifunction buttons in group.*/ + mfbd_mbtn_skip(_pbtn_group, times); + } +#endif + +} + + /** * @brief reset all buttons params in the group. * diff --git a/mfbd.h b/mfbd.h index e6c825b..b5bb40f 100644 --- a/mfbd.h +++ b/mfbd.h @@ -13,6 +13,7 @@ * 2022-09-07 smartmx add default define apis. * 2023-03-15 smartmx add state declaration. * 2023-07-03 smartmx add Section Definition option. + * 2023-07-15 smartmx add skip function. * */ @@ -33,7 +34,7 @@ typedef enum #define MFBD_DOWN_CODE_NAME(NAME) NAME##_DOWN_CODE /* when using tbtn/nbtn default define api, this is down-code name. */ #define MFBD_UP_CODE_NAME(NAME) NAME##_UP_CODE /* when using tbtn/nbtn/mbtn default define api, this is up-code name. */ #define MFBD_LONG_CODE_NAME(NAME) NAME##_LONG_CODE /* when using nbtn/mbtn default define api, this is long-code name. */ -#define MFBD_DOWN_CODES_NAME(NAME) NAME##_DOWN_CODES /* when using mbtn default define api, this is long-codes name. */ +#define MFBD_DOWN_CODES_NAME(NAME) NAME##_DOWN_CODES /* when using mbtn default define api, this is down-codes name. */ /* tiny button definitions, tiny button functions only support down and up event. */ #if MFBD_PARAMS_SAME_IN_GROUP @@ -436,6 +437,8 @@ typedef struct _mfbd_group_struct extern void mfbd_group_scan(const mfbd_group_t *_pbtn_group); +extern void mfbd_group_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times); + extern void mfbd_group_reset(const mfbd_group_t *_pbtn_group); #endif /* (MFBD_USE_SECTION_DEFINITION == 0) */ diff --git a/mfbd_sd.c b/mfbd_sd.c index 1575c93..94a1e6c 100644 --- a/mfbd_sd.c +++ b/mfbd_sd.c @@ -43,6 +43,8 @@ * @brief scan all tiny buttons, and report button event value if event happened. * * @param _pbtn_group is a pointer of mfbd_group_t. + * @param _pbtn_info_start is a pointer to the start address in flash with type mfbd_tbtn_info_t. + * @param _pbtn_info_end is a pointer to the end address in flash with type mfbd_tbtn_info_t. * * @return None. */ @@ -108,7 +110,8 @@ void mfbd_tbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_tbtn_info_t *_pb /** * @brief reset all tiny buttons' params. * - * @param _pbtn_group is a pointer of mfbd_group_t. + * @param _pbtn_info_start is a pointer to the start address in flash with type mfbd_tbtn_info_t. + * @param _pbtn_info_end is a pointer to the end address in flash with type mfbd_tbtn_info_t. * * @return None. */ @@ -137,6 +140,8 @@ void mfbd_tbtn_reset(const mfbd_tbtn_info_t *_pbtn_info_start, const mfbd_tbtn_i * @brief scan all normal buttons, and report button event value if event happened. * * @param _pbtn_group is a pointer of mfbd_group_t. + * @param _pbtn_info_start is a pointer to the start address in flash with type mfbd_nbtn_info_t. + * @param _pbtn_info_end is a pointer to the end address in flash with type mfbd_nbtn_info_t. * * @return None */ @@ -234,7 +239,8 @@ void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_nbtn_info_t *_pb /** * @brief reset all normal buttons' params. * - * @param _pbtn_group is a pointer of mfbd_group_t. + * @param _pbtn_info_start is a pointer to the start address in flash with type mfbd_nbtn_info_t. + * @param _pbtn_info_end is a pointer to the end address in flash with type mfbd_nbtn_info_t. * * @return None. */ @@ -265,6 +271,8 @@ void mfbd_nbtn_reset(const mfbd_nbtn_info_t *_pbtn_info_start, const mfbd_nbtn_i * @brief scan all multi-function buttons, and report button event value if event happened. * * @param _pbtn_group is a pointer of mfbd_group_t. + * @param _pbtn_info_start is a pointer to the start address in flash with type mfbd_mbtn_info_t. + * @param _pbtn_info_end is a pointer to the end address in flash with type mfbd_mbtn_info_t. * * @return None. */ @@ -403,7 +411,8 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb /** * @brief reset all multi-function buttons' params. * - * @param _pbtn_group is a pointer of mfbd_group_t. + * @param _pbtn_info_start is a pointer to the start address in flash with type mfbd_mbtn_info_t. + * @param _pbtn_info_end is a pointer to the end address in flash with type mfbd_mbtn_info_t. * * @return None. */ diff --git a/mfbd_sd.h b/mfbd_sd.h index 83a4d10..6982157 100644 --- a/mfbd_sd.h +++ b/mfbd_sd.h @@ -26,7 +26,7 @@ typedef enum #define MFBD_DOWN_CODE_NAME(NAME) NAME##_DOWN_CODE /* when using tbtn/nbtn default define api, this is down-code name. */ #define MFBD_UP_CODE_NAME(NAME) NAME##_UP_CODE /* when using tbtn/nbtn/mbtn default define api, this is up-code name. */ #define MFBD_LONG_CODE_NAME(NAME) NAME##_LONG_CODE /* when using nbtn/mbtn default define api, this is long-code name. */ -#define MFBD_DOWN_CODES_NAME(NAME) NAME##_DOWN_CODES /* when using mbtn default define api, this is long-codes name. */ +#define MFBD_DOWN_CODES_NAME(NAME) NAME##_DOWN_CODES /* when using mbtn default define api, this is down-codes name. */ #if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM Compiler */ #define __MFBD_SECTION(x) __attribute__((section(x)))