Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
smartmx committed Jul 3, 2023
1 parent 03bfb4f commit 19ae09e
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 13 deletions.
89 changes: 89 additions & 0 deletions examples/mfbd_demo_rtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
* 2022-04-16 smartmx drop list definitions, use arraylist, each group has all btn types.
* 2022-08-05 smartmx add reset params function.
* 2022-08-15 smartmx fix bugs.
* 2023-07-03 smartmx add Section Definition option.
*
*/

#include <rtthread.h>
#include <board.h>
#include "mfbd.h"
#include "mfbd_sd.h"

void bsp_btn_value_report(mfbd_btn_code_t btn_value);
unsigned char bsp_btn_check(mfbd_btn_index_t btn_index);
Expand All @@ -36,6 +38,81 @@ unsigned char bsp_btn_check(mfbd_btn_index_t btn_index);
#define BTN_WK_UP GET_PIN(A, 0)
#endif

#if MFBD_USE_SECTION_DEFINITION
/* use section definition. */

#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_btns, 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_btns, test_nbtn1, 3, 0x1401, 0x1400, 0x1402);

MFBD_NBTN_DEFINE(test_btns, 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_btns, 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_btns, 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_btns, test_nbtn1, 3, 3, 0, 150, 0x1401, 0x1400, 0x1402);

MFBD_NBTN_DEFINE(test_btns, 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_btns, 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*/

//MFBD_GROUP_DEFINE(test_btns, bsp_btn_check, bsp_btn_value_report, 3, 30, 150, 75);
//MFBD_GROUP_DEFINE(test_btns, bsp_btn_check, bsp_btn_value_report);

const mfbd_group_t MFBD_GROUP_NAME(test_btns) = {
bsp_btn_check,
bsp_btn_value_report,
#if MFBD_PARAMS_SAME_IN_GROUP

#if MFBD_USE_TINY_BUTTON || MFBD_USE_NORMAL_BUTTON || MFBD_USE_MULTIFUCNTION_BUTTON
3,
#endif /* MFBD_USE_TINY_BUTTON || MFBD_USE_NORMAL_BUTTON || MFBD_USE_MULTIFUCNTION_BUTTON */

#if MFBD_USE_NORMAL_BUTTON || MFBD_USE_MULTIFUCNTION_BUTTON
30,
150,
#endif /* MFBD_USE_NORMAL_BUTTON || MFBD_USE_MULTIFUCNTION_BUTTON */

#if MFBD_USE_MULTIFUCNTION_BUTTON
75,
#endif /* MFBD_USE_MULTIFUCNTION_BUTTON */

#endif /*MFBD_PARAMS_SAME_IN_GROUP*/
};

#else

#if MFBD_PARAMS_SAME_IN_GROUP

/* tbtn test */
Expand Down Expand Up @@ -130,6 +207,8 @@ const mfbd_group_t test_btn_group =

};

#endif /*MFBD_USE_SECTION_DEFINITION*/

unsigned char bsp_btn_check(mfbd_btn_index_t btn_index)
{
switch (btn_index)
Expand Down Expand Up @@ -173,7 +252,17 @@ static void mfbd_scan(void *arg)
{
while (1)
{
#if MFBD_USE_SECTION_DEFINITION
/* use section definition. */

MFBD_GROUP_SCAN(test_btns);

#else

mfbd_group_scan(&test_btn_group); /* scan button group */

#endif /*MFBD_USE_SECTION_DEFINITION*/

rt_thread_mdelay(10); /* scan period: 10ms */
}
}
Expand Down
31 changes: 18 additions & 13 deletions mfbd_sd.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,14 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd
{ \
extern const int MFBD_SECTION_START(GROUP, tbtn); \
extern const int MFBD_SECTION_END(GROUP, tbtn); \
mfbd_tbtn_scan(&(MFBD_GROUP_NAME(GROUP)), &(MFBD_SECTION_START(GROUP, tbtn)), &(MFBD_SECTION_END(GROUP, tbtn))); \
mfbd_tbtn_scan((const mfbd_group_t *)&(MFBD_GROUP_NAME(GROUP)), (const mfbd_tbtn_info_t *)&(MFBD_SECTION_START(GROUP, tbtn)), (const mfbd_tbtn_info_t *)&(MFBD_SECTION_END(GROUP, tbtn))); \
} while (0)
#define MFBD_GROUP_RESET_TBTN(GROUP) \
do \
{ \
extern const int MFBD_SECTION_START(GROUP, tbtn); \
extern const int MFBD_SECTION_END(GROUP, tbtn); \
mfbd_tbtn_reset(&(MFBD_SECTION_START(GROUP, tbtn)), &(MFBD_SECTION_END(GROUP, tbtn))); \
mfbd_tbtn_reset((const mfbd_tbtn_info_t *)&(MFBD_SECTION_START(GROUP, tbtn)), (const mfbd_tbtn_info_t *)&(MFBD_SECTION_END(GROUP, tbtn))); \
} while (0)
#else
#define MFBD_GROUP_SCAN_TBTN(GROUP) do{} while(0)
Expand All @@ -480,14 +480,14 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd
{ \
extern const int MFBD_SECTION_START(GROUP, nbtn); \
extern const int MFBD_SECTION_END(GROUP, nbtn); \
mfbd_nbtn_scan(&(MFBD_GROUP_NAME(GROUP)), &(MFBD_SECTION_START(GROUP, nbtn)), &(MFBD_SECTION_END(GROUP, nbtn))); \
mfbd_nbtn_scan((const mfbd_group_t *)&(MFBD_GROUP_NAME(GROUP)), (const mfbd_nbtn_info_t *)&(MFBD_SECTION_START(GROUP, nbtn)), (const mfbd_nbtn_info_t *)&(MFBD_SECTION_END(GROUP, nbtn))); \
} while (0)
#define MFBD_GROUP_RESET_NBTN(GROUP) \
do \
{ \
extern const int MFBD_SECTION_START(GROUP, nbtn); \
extern const int MFBD_SECTION_END(GROUP, nbtn); \
mfbd_nbtn_reset(&(MFBD_SECTION_START(GROUP, nbtn)), &(MFBD_SECTION_END(GROUP, nbtn))); \
mfbd_nbtn_reset((const mfbd_nbtn_info_t *)&(MFBD_SECTION_START(GROUP, nbtn)), (const mfbd_nbtn_info_t *)&(MFBD_SECTION_END(GROUP, nbtn))); \
} while (0)
#else
#define MFBD_GROUP_SCAN_NBTN(GROUP) do{} while(0)
Expand All @@ -500,14 +500,14 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd
{ \
extern const int MFBD_SECTION_START(GROUP, mbtn); \
extern const int MFBD_SECTION_END(GROUP, mbtn); \
mfbd_mbtn_scan(&(MFBD_GROUP_NAME(GROUP)), &(MFBD_SECTION_START(GROUP, mbtn)), &(MFBD_SECTION_END(GROUP, mbtn))); \
mfbd_mbtn_scan((const mfbd_group_t *)&(MFBD_GROUP_NAME(GROUP)), (const mfbd_mbtn_info_t *)&(MFBD_SECTION_START(GROUP, mbtn)), (const mfbd_mbtn_info_t *)&(MFBD_SECTION_END(GROUP, mbtn))); \
} while (0)
#define MFBD_GROUP_RESET_MBTN(GROUP) \
do \
{ \
extern const int MFBD_SECTION_START(GROUP, mbtn); \
extern const int MFBD_SECTION_END(GROUP, mbtn); \
mfbd_mbtn_reset(&(MFBD_SECTION_START(GROUP, mbtn)), &(MFBD_SECTION_END(GROUP, mbtn))); \
mfbd_mbtn_reset((const mfbd_mbtn_info_t *)&(MFBD_SECTION_START(GROUP, mbtn)), (const mfbd_mbtn_info_t *)&(MFBD_SECTION_END(GROUP, mbtn))); \
} while (0)
#else
#define MFBD_GROUP_SCAN_MBTN(GROUP) do{} while(0)
Expand All @@ -520,7 +520,12 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd
#define MFBD_GROUP_SCAN_TBTN(GROUP) \
do \
{ \
mfbd_tbtn_scan(&(MFBD_GROUP_NAME(GROUP)), MFBD_SECTION_START(GROUP, tbtn), MFBD_SECTION_END(GROUP, tbtn)); \
mfbd_tbtn_scan((const mfbd_group_t *)&(MFBD_GROUP_NAME(GROUP)), (const mfbd_tbtn_info_t *)MFBD_SECTION_START(GROUP, tbtn), (const mfbd_tbtn_info_t *)MFBD_SECTION_END(GROUP, tbtn)); \
} while (0)
#define MFBD_GROUP_RESET_TBTN(GROUP) \
do \
{ \
mfbd_tbtn_reset((const mfbd_tbtn_info_t *)MFBD_SECTION_START(GROUP, nbtn), (const mfbd_tbtn_info_t *)MFBD_SECTION_END(GROUP, nbtn)); \
} while (0)
#else
#define MFBD_GROUP_SCAN_TBTN(GROUP) do{} while(0)
Expand All @@ -529,12 +534,12 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd
#define MFBD_GROUP_SCAN_NBTN(GROUP) \
do \
{ \
mfbd_nbtn_scan(&(MFBD_GROUP_NAME(GROUP)), MFBD_SECTION_START(GROUP, nbtn), MFBD_SECTION_END(GROUP, nbtn)); \
mfbd_nbtn_scan((const mfbd_group_t *)&(MFBD_GROUP_NAME(GROUP)), (const mfbd_nbtn_info_t *)MFBD_SECTION_START(GROUP, nbtn), (const mfbd_nbtn_info_t *)MFBD_SECTION_END(GROUP, nbtn)); \
} while (0)
#define MFBD_GROUP_RESET_NBTN(GROUP) \
do \
{ \
mfbd_nbtn_reset(MFBD_SECTION_START(GROUP, nbtn), MFBD_SECTION_END(GROUP, nbtn)); \
mfbd_nbtn_reset((const mfbd_nbtn_info_t *)MFBD_SECTION_START(GROUP, nbtn), (const mfbd_nbtn_info_t *)MFBD_SECTION_END(GROUP, nbtn)); \
} while (0)
#else
#define MFBD_GROUP_SCAN_NBTN(GROUP) do{} while(0)
Expand All @@ -544,12 +549,12 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd
#define MFBD_GROUP_SCAN_MBTN(GROUP) \
do \
{ \
mfbd_mbtn_scan(&(MFBD_GROUP_NAME(GROUP)), MFBD_SECTION_START(GROUP, mbtn), MFBD_SECTION_END(GROUP, mbtn)); \
mfbd_mbtn_scan((const mfbd_group_t *)&(MFBD_GROUP_NAME(GROUP)), (const mfbd_mbtn_info_t *)MFBD_SECTION_START(GROUP, mbtn), (const mfbd_mbtn_info_t *)MFBD_SECTION_END(GROUP, mbtn)); \
} while (0)
#define MFBD_GROUP_RESET_MBTN(GROUP) \
do \
{ \
mfbd_mbtn_reset(MFBD_SECTION_START(GROUP, mbtn), MFBD_SECTION_END(GROUP, mbtn)); \
mfbd_mbtn_reset((const mfbd_mbtn_info_t *)MFBD_SECTION_START(GROUP, mbtn), (const mfbd_mbtn_info_t *)MFBD_SECTION_END(GROUP, mbtn)); \
} while (0)
#else
#define MFBD_GROUP_SCAN_MBTN(GROUP) do{} while(0)
Expand Down Expand Up @@ -632,7 +637,7 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd
} \
} while(0)
#else
#define MFBD_GROUP_SCAN_AFTER(GROUP) do{} while(0)
#define MFBD_GROUP_SCAN_PREPARE(GROUP) do{} while(0)
#endif /* MFBD_USE_BTN_SCAN_PRE_FUNC */

#if MFBD_USE_BTN_SCAN_AFTER_FUNC
Expand All @@ -645,7 +650,7 @@ extern void mfbd_mbtn_reset(const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd
} \
} while(0)
#else
#define MFBD_GROUP_SCAN_AFTER(GROUP) do{} while(0)
#define MFBD_GROUP_SCAN_AFTER(GROUP) do{} while(0)
#endif /* MFBD_USE_BTN_SCAN_AFTER_FUNC */

/*
Expand Down

0 comments on commit 19ae09e

Please sign in to comment.