Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
add reset params function.
  • Loading branch information
smartmx committed Aug 4, 2022
1 parent e5bc170 commit bcca81d
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,可以参考例程移植即可。
Expand Down
28 changes: 28 additions & 0 deletions examples/mfbd_demo_rtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
*/

Expand Down Expand Up @@ -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,
Expand Down
104 changes: 104 additions & 0 deletions mfbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
*/

Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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

}
3 changes: 3 additions & 0 deletions mfbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
*/

Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions mfbd_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
*/

Expand Down

0 comments on commit bcca81d

Please sign in to comment.