Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
mfbd.c add skip function.
  • Loading branch information
smartmx committed Jul 15, 2023
1 parent 2b7f72a commit fd46375
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 5 deletions.
158 changes: 158 additions & 0 deletions mfbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
*/

Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down
5 changes: 4 additions & 1 deletion mfbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
*/

Expand All @@ -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
Expand Down Expand Up @@ -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) */
Expand Down
15 changes: 12 additions & 3 deletions mfbd_sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion mfbd_sd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit fd46375

Please sign in to comment.