From bcca81d62147d82be06e565ae1b981585f69987c Mon Sep 17 00:00:00 2001 From: CoderNotCute <30313912+smartmx@users.noreply.github.com> Date: Fri, 5 Aug 2022 06:46:58 +0800 Subject: [PATCH] update add reset params function. --- README.md | 16 ++++++ examples/mfbd_demo_rtt.c | 28 +++++++++++ mfbd.c | 104 +++++++++++++++++++++++++++++++++++++++ mfbd.h | 3 ++ mfbd_cfg.h | 1 + 5 files changed, 152 insertions(+) diff --git a/README.md b/README.md index b2ad5fd..92f0efe 100644 --- a/README.md +++ b/README.md @@ -333,6 +333,22 @@ const mfbd_group_t test_btn_group = }; ``` +### 按键检测函数调用 + +在其他配置都已完成后,只需定时调用检测函数即可完成对按键组的检测并上报兼职。 + +```c +extern void mfbd_group_scan(const mfbd_group_t *_pbtn_group); +``` + +### 停止按键检测 + +在某些场景下可能需要临时停止按键检测,可以调用下面的函数复位按键组内所有的信息。 + +```c +extern void mfbd_group_reset(const mfbd_group_t *_pbtn_group); +``` + ## 移植使用示例工程 MFBD提供了下面的测试例程,如果你使用其他开发板和其他RTOS,可以参考例程移植即可。 diff --git a/examples/mfbd_demo_rtt.c b/examples/mfbd_demo_rtt.c index 9f694f9..2426f33 100644 --- a/examples/mfbd_demo_rtt.c +++ b/examples/mfbd_demo_rtt.c @@ -8,6 +8,7 @@ * 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. * */ @@ -37,50 +38,77 @@ unsigned char bsp_btn_check(mfbd_btn_index_t btn_index); #if MFBD_PARAMS_SAME_IN_GROUP /* tbtn test */ +#if MFBD_USE_TINY_BUTTON /* MFBD_TBTN_DEFINE(NAME, BTN_INDEX, FILTER_TIME, BTN_DOWN_CODE, BTN_UP_CODE) */ MFBD_TBTN_DEFINE(test_tbtn, 1, 0x1201, 0x1200); +#endif /* MFBD_USE_TINY_BUTTON */ /* nbtn test */ +#if MFBD_USE_NORMAL_BUTTON /* MFBD_NBTN_DEFINE(NAME, BTN_INDEX, BTN_DOWN_CODE, BTN_UP_CODE, BTN_LONG_CODE) */ MFBD_NBTN_DEFINE(test_nbtn1, 3, 0x1401, 0x1400, 0x1402); MFBD_NBTN_DEFINE(test_nbtn, 2, 0x1301, 0x1300, 0x1301); +#endif /* MFBD_USE_NORMAL_BUTTON */ /* mbtn test */ +#if MFBD_USE_MULTIFUCNTION_BUTTON /* MFBD_MBTN_DEFINE(NAME, BTN_INDEX, MAX_MULTICLICK_STATE, BTN_DOWN_CODE, BTN_UP_CODE, BTN_LONG_CODE, ...) */ MFBD_MBTN_DEFINE(test_mbtn, 4, 3, 0x1501, 0x1500, 0x1501, 0x1511, 0x1521, 0x1531); +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ #else /* tbtn test */ +#if MFBD_USE_TINY_BUTTON /* MFBD_TBTN_DEFINE(NAME, BTN_INDEX, FILTER_TIME, BTN_DOWN_CODE, BTN_UP_CODE) */ MFBD_TBTN_DEFINE(test_tbtn, 1, 3, 0x1201, 0x1200); +#endif /* MFBD_USE_TINY_BUTTON */ /* nbtn test */ +#if MFBD_USE_NORMAL_BUTTON /* MFBD_NBTN_DEFINE(NAME, BTN_INDEX, FILTER_TIME, REPEAT_TIME, LONG_TIME, BTN_DOWN_CODE, BTN_UP_CODE, BTN_LONG_CODE) */ MFBD_NBTN_DEFINE(test_nbtn1, 3, 3, 0, 150, 0x1401, 0x1400, 0x1402); MFBD_NBTN_DEFINE(test_nbtn, 2, 3, 30, 150, 0x1301, 0x1300, 0x1301); +#endif /* MFBD_USE_NORMAL_BUTTON */ /* mbtn test */ +#if MFBD_USE_MULTIFUCNTION_BUTTON /* MFBD_MBTN_DEFINE(NAME, BTN_INDEX, FILTER_TIME, REPEAT_TIME, LONG_TIME, MULTICLICK_TIME, MAX_MULTICLICK_STATE, BTN_DOWN_CODE, BTN_UP_CODE, BTN_LONG_CODE, ...) */ MFBD_MBTN_DEFINE(test_mbtn, 4, 3, 30, 150, 75, 3, 0x1501, 0x1500, 0x1501, 0x1511, 0x1521, 0x1531); +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ #endif /*MFBD_PARAMS_SAME_IN_GROUP*/ +#if MFBD_USE_TINY_BUTTON MFBD_TBTN_ARRAYLIST(test_tbtn_list, &test_tbtn); +#endif /* MFBD_USE_TINY_BUTTON */ +#if MFBD_USE_NORMAL_BUTTON MFBD_NBTN_ARRAYLIST(test_nbtn_list, &test_nbtn1, &test_nbtn); +#endif /* MFBD_USE_NORMAL_BUTTON */ +#if MFBD_USE_MULTIFUCNTION_BUTTON MFBD_MBTN_ARRAYLIST(test_mbtn_list, &test_mbtn); +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ const mfbd_group_t test_btn_group = { bsp_btn_check, bsp_btn_value_report, + +#if MFBD_USE_TINY_BUTTON test_tbtn_list, +#endif /* MFBD_USE_TINY_BUTTON */ + +#if MFBD_USE_NORMAL_BUTTON test_nbtn_list, +#endif /* MFBD_USE_NORMAL_BUTTON */ + +#if MFBD_USE_MULTIFUCNTION_BUTTON test_mbtn_list, +#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */ #if MFBD_PARAMS_SAME_IN_GROUP 3, diff --git a/mfbd.c b/mfbd.c index 181f4ec..89bddaa 100644 --- a/mfbd.c +++ b/mfbd.c @@ -8,6 +8,7 @@ * 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. * */ @@ -103,6 +104,26 @@ void mfbd_tbtn_scan(const mfbd_group_t *_pbtn_group) } } +/** + * @brief reset all tiny buttons' params. + * + * @param _pbtn_group is a pointer of mfbd_group_t. + * + * @return None. + */ +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) + { + _pbtn->filter_count = 0; + _pbtn->state = 0; + _ppbtn++; + _pbtn = *_ppbtn; + } +} + #endif @@ -204,6 +225,28 @@ void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group) } } +/** + * @brief reset all normal buttons' params. + * + * @param _pbtn_group is a pointer of mfbd_group_t. + * + * @return None. + */ +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) + { + _pbtn->filter_count = 0; + _pbtn->long_count = 0; + _pbtn->repeat_count = 0; + _pbtn->state = 0; + _ppbtn++; + _pbtn = *_ppbtn; + } +} + #endif @@ -332,6 +375,30 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group) } } +/** + * @brief reset all multi-function buttons' params. + * + * @param _pbtn_group is a pointer of mfbd_group_t. + * + * @return None. + */ +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) + { + _pbtn->filter_count = 0; + _pbtn->long_count = 0; + _pbtn->multiclick_count = 0; + _pbtn->multiclick_state = 0; + _pbtn->repeat_count = 0; + _pbtn->state = 0; + _ppbtn++; + _pbtn = *_ppbtn; + } +} + #endif @@ -386,3 +453,40 @@ void mfbd_group_scan(const mfbd_group_t *_pbtn_group) #endif } + + +/** + * @brief reset all buttons params in the group. + * + * @param _pbtn_group is a pointer of mfbd_group_t. + * + * @return None. + */ +void mfbd_group_reset(const mfbd_group_t *_pbtn_group) +{ + +#if MFBD_USE_TINY_BUTTON + if (_pbtn_group->tbtns != NULL) + { + /*reset tiny buttons in group.*/ + mfbd_tbtn_reset(_pbtn_group); + } +#endif + +#if MFBD_USE_NORMAL_BUTTON + if (_pbtn_group->nbtns != NULL) + { + /*reset normal buttons in group.*/ + mfbd_nbtn_reset(_pbtn_group); + } +#endif + +#if MFBD_USE_MULTIFUCNTION_BUTTON + if (_pbtn_group->mbtns != NULL) + { + /*reset multifunction buttons in group.*/ + mfbd_mbtn_reset(_pbtn_group); + } +#endif + +} diff --git a/mfbd.h b/mfbd.h index 4f8a7ba..a411808 100644 --- a/mfbd.h +++ b/mfbd.h @@ -8,6 +8,7 @@ * 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. * */ @@ -314,4 +315,6 @@ typedef struct _mfbd_group_struct extern void mfbd_group_scan(const mfbd_group_t *_pbtn_group); +extern void mfbd_group_reset(const mfbd_group_t *_pbtn_group); + #endif diff --git a/mfbd_cfg.h b/mfbd_cfg.h index 88ac60e..ec7cf2d 100644 --- a/mfbd_cfg.h +++ b/mfbd_cfg.h @@ -8,6 +8,7 @@ * 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. * */