Skip to content

Commit fd46375

Browse files
committed
update
mfbd.c add skip function.
1 parent 2b7f72a commit fd46375

File tree

4 files changed

+175
-5
lines changed

4 files changed

+175
-5
lines changed

mfbd.c

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* 2022-08-05 smartmx add reset params function.
1212
* 2023-03-15 smartmx add state declaration.
1313
* 2023-07-03 smartmx add Section Definition option.
14+
* 2023-07-15 smartmx add skip function.
1415
*
1516
*/
1617

@@ -230,6 +231,59 @@ void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group)
230231
}
231232
}
232233

234+
/**
235+
* @brief skip some times of mfbd_btn_count_t with last state.
236+
*
237+
* @param _pbtn_group is a pointer of mfbd_group_t.
238+
* @param times is times need to skip.
239+
*
240+
* @return None.
241+
*/
242+
void mfbd_nbtn_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times)
243+
{
244+
mfbd_nbtn_t **_ppbtn = _pbtn_group->nbtns;
245+
mfbd_nbtn_t *_pbtn = *_ppbtn;
246+
247+
while (_pbtn != NULL)
248+
{
249+
if(_pbtn->state == MFBD_BTN_STATE_DOWN)
250+
{
251+
if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_long_code != 0))
252+
{
253+
/* if long_time is 0 or long_code is 0, disable long and repeat check. */
254+
if (_pbtn->long_count < (MFBD_LONG_TIME_IN_FUC))
255+
{
256+
if(((MFBD_LONG_TIME_IN_FUC) - 1 - _pbtn->long_count) > times)
257+
{
258+
_pbtn->long_count = _pbtn->long_count + times;
259+
}
260+
else
261+
{
262+
_pbtn->long_count = MFBD_LONG_TIME_IN_FUC - 1;
263+
}
264+
}
265+
}
266+
}
267+
else if(_pbtn->state == MFBD_BTN_STATE_LONG)
268+
{
269+
if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_down_code[0] != 0))
270+
{
271+
if(((MFBD_REPEAT_TIME_IN_FUC) - 1 - _pbtn->repeat_count) > times)
272+
{
273+
_pbtn->repeat_count = _pbtn->repeat_count + times;
274+
}
275+
else
276+
{
277+
_pbtn->repeat_count = MFBD_REPEAT_TIME_IN_FUC - 1;
278+
}
279+
}
280+
}
281+
282+
_ppbtn++;
283+
_pbtn = *_ppbtn;
284+
}
285+
}
286+
233287
/**
234288
* @brief reset all normal buttons' params.
235289
*
@@ -393,6 +447,79 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group)
393447
}
394448
}
395449

450+
/**
451+
* @brief skip some times of mfbd_btn_count_t with last state.
452+
*
453+
* @param _pbtn_group is a pointer of mfbd_group_t.
454+
* @param times is times need to skip.
455+
*
456+
* @return None.
457+
*/
458+
void mfbd_mbtn_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times)
459+
{
460+
mfbd_mbtn_t **_ppbtn = _pbtn_group->mbtns;
461+
mfbd_mbtn_t *_pbtn = *_ppbtn;
462+
463+
while (_pbtn != NULL)
464+
{
465+
if(_pbtn->state == MFBD_BTN_STATE_UP)
466+
{
467+
if (_pbtn->multiclick_state != 0)
468+
{
469+
if (_pbtn->multiclick_count < (MFBD_MULTICLICK_TIME_IN_FUC))
470+
{
471+
if(((MFBD_MULTICLICK_TIME_IN_FUC) - _pbtn->multiclick_count) > times)
472+
{
473+
_pbtn->multiclick_count = _pbtn->multiclick_count + times;
474+
}
475+
else
476+
{
477+
_pbtn->multiclick_state = 0;
478+
}
479+
}
480+
}
481+
}
482+
else if(_pbtn->state == MFBD_BTN_STATE_DOWN)
483+
{
484+
if (_pbtn->multiclick_state == 0)
485+
{
486+
if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_long_code != 0))
487+
{
488+
/* if long_time is 0 or long_code is 0, disable long and repeat check. */
489+
if (_pbtn->long_count < (MFBD_LONG_TIME_IN_FUC))
490+
{
491+
if(((MFBD_LONG_TIME_IN_FUC) - 1 - _pbtn->long_count) > times)
492+
{
493+
_pbtn->long_count = _pbtn->long_count + times;
494+
}
495+
else
496+
{
497+
_pbtn->long_count = MFBD_LONG_TIME_IN_FUC - 1;
498+
}
499+
}
500+
}
501+
}
502+
}
503+
else if(_pbtn->state == MFBD_BTN_STATE_LONG)
504+
{
505+
if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn->btn_info->btn_down_code[0] != 0))
506+
{
507+
if(((MFBD_REPEAT_TIME_IN_FUC) - 1 - _pbtn->repeat_count) > times)
508+
{
509+
_pbtn->repeat_count = _pbtn->repeat_count + times;
510+
}
511+
else
512+
{
513+
_pbtn->repeat_count = MFBD_REPEAT_TIME_IN_FUC - 1;
514+
}
515+
}
516+
}
517+
518+
_ppbtn++;
519+
_pbtn = *_ppbtn;
520+
}
521+
}
522+
396523
/**
397524
* @brief reset all multi-function buttons' params.
398525
*
@@ -473,6 +600,37 @@ void mfbd_group_scan(const mfbd_group_t *_pbtn_group)
473600
}
474601

475602

603+
/**
604+
* @brief skip some times with last state.
605+
*
606+
* @param _pbtn_group is a pointer of mfbd_group_t.
607+
* @param times is times need to skip.
608+
*
609+
* @return None.
610+
*/
611+
void mfbd_group_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times)
612+
{
613+
/* tbtn doesn't need to skip times. */
614+
615+
#if MFBD_USE_NORMAL_BUTTON
616+
if (_pbtn_group->nbtns != NULL)
617+
{
618+
/* skip times of normal buttons in group.*/
619+
mfbd_nbtn_skip(_pbtn_group, times);
620+
}
621+
#endif
622+
623+
#if MFBD_USE_MULTIFUCNTION_BUTTON
624+
if (_pbtn_group->mbtns != NULL)
625+
{
626+
/* skip times of multifunction buttons in group.*/
627+
mfbd_mbtn_skip(_pbtn_group, times);
628+
}
629+
#endif
630+
631+
}
632+
633+
476634
/**
477635
* @brief reset all buttons params in the group.
478636
*

mfbd.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* 2022-09-07 smartmx add default define apis.
1414
* 2023-03-15 smartmx add state declaration.
1515
* 2023-07-03 smartmx add Section Definition option.
16+
* 2023-07-15 smartmx add skip function.
1617
*
1718
*/
1819

@@ -33,7 +34,7 @@ typedef enum
3334
#define MFBD_DOWN_CODE_NAME(NAME) NAME##_DOWN_CODE /* when using tbtn/nbtn default define api, this is down-code name. */
3435
#define MFBD_UP_CODE_NAME(NAME) NAME##_UP_CODE /* when using tbtn/nbtn/mbtn default define api, this is up-code name. */
3536
#define MFBD_LONG_CODE_NAME(NAME) NAME##_LONG_CODE /* when using nbtn/mbtn default define api, this is long-code name. */
36-
#define MFBD_DOWN_CODES_NAME(NAME) NAME##_DOWN_CODES /* when using mbtn default define api, this is long-codes name. */
37+
#define MFBD_DOWN_CODES_NAME(NAME) NAME##_DOWN_CODES /* when using mbtn default define api, this is down-codes name. */
3738

3839
/* tiny button definitions, tiny button functions only support down and up event. */
3940
#if MFBD_PARAMS_SAME_IN_GROUP
@@ -436,6 +437,8 @@ typedef struct _mfbd_group_struct
436437

437438
extern void mfbd_group_scan(const mfbd_group_t *_pbtn_group);
438439

440+
extern void mfbd_group_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times);
441+
439442
extern void mfbd_group_reset(const mfbd_group_t *_pbtn_group);
440443

441444
#endif /* (MFBD_USE_SECTION_DEFINITION == 0) */

mfbd_sd.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
* @brief scan all tiny buttons, and report button event value if event happened.
4444
*
4545
* @param _pbtn_group is a pointer of mfbd_group_t.
46+
* @param _pbtn_info_start is a pointer to the start address in flash with type mfbd_tbtn_info_t.
47+
* @param _pbtn_info_end is a pointer to the end address in flash with type mfbd_tbtn_info_t.
4648
*
4749
* @return None.
4850
*/
@@ -108,7 +110,8 @@ void mfbd_tbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_tbtn_info_t *_pb
108110
/**
109111
* @brief reset all tiny buttons' params.
110112
*
111-
* @param _pbtn_group is a pointer of mfbd_group_t.
113+
* @param _pbtn_info_start is a pointer to the start address in flash with type mfbd_tbtn_info_t.
114+
* @param _pbtn_info_end is a pointer to the end address in flash with type mfbd_tbtn_info_t.
112115
*
113116
* @return None.
114117
*/
@@ -137,6 +140,8 @@ void mfbd_tbtn_reset(const mfbd_tbtn_info_t *_pbtn_info_start, const mfbd_tbtn_i
137140
* @brief scan all normal buttons, and report button event value if event happened.
138141
*
139142
* @param _pbtn_group is a pointer of mfbd_group_t.
143+
* @param _pbtn_info_start is a pointer to the start address in flash with type mfbd_nbtn_info_t.
144+
* @param _pbtn_info_end is a pointer to the end address in flash with type mfbd_nbtn_info_t.
140145
*
141146
* @return None
142147
*/
@@ -234,7 +239,8 @@ void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_nbtn_info_t *_pb
234239
/**
235240
* @brief reset all normal buttons' params.
236241
*
237-
* @param _pbtn_group is a pointer of mfbd_group_t.
242+
* @param _pbtn_info_start is a pointer to the start address in flash with type mfbd_nbtn_info_t.
243+
* @param _pbtn_info_end is a pointer to the end address in flash with type mfbd_nbtn_info_t.
238244
*
239245
* @return None.
240246
*/
@@ -265,6 +271,8 @@ void mfbd_nbtn_reset(const mfbd_nbtn_info_t *_pbtn_info_start, const mfbd_nbtn_i
265271
* @brief scan all multi-function buttons, and report button event value if event happened.
266272
*
267273
* @param _pbtn_group is a pointer of mfbd_group_t.
274+
* @param _pbtn_info_start is a pointer to the start address in flash with type mfbd_mbtn_info_t.
275+
* @param _pbtn_info_end is a pointer to the end address in flash with type mfbd_mbtn_info_t.
268276
*
269277
* @return None.
270278
*/
@@ -403,7 +411,8 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb
403411
/**
404412
* @brief reset all multi-function buttons' params.
405413
*
406-
* @param _pbtn_group is a pointer of mfbd_group_t.
414+
* @param _pbtn_info_start is a pointer to the start address in flash with type mfbd_mbtn_info_t.
415+
* @param _pbtn_info_end is a pointer to the end address in flash with type mfbd_mbtn_info_t.
407416
*
408417
* @return None.
409418
*/

mfbd_sd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef enum
2626
#define MFBD_DOWN_CODE_NAME(NAME) NAME##_DOWN_CODE /* when using tbtn/nbtn default define api, this is down-code name. */
2727
#define MFBD_UP_CODE_NAME(NAME) NAME##_UP_CODE /* when using tbtn/nbtn/mbtn default define api, this is up-code name. */
2828
#define MFBD_LONG_CODE_NAME(NAME) NAME##_LONG_CODE /* when using nbtn/mbtn default define api, this is long-code name. */
29-
#define MFBD_DOWN_CODES_NAME(NAME) NAME##_DOWN_CODES /* when using mbtn default define api, this is long-codes name. */
29+
#define MFBD_DOWN_CODES_NAME(NAME) NAME##_DOWN_CODES /* when using mbtn default define api, this is down-codes name. */
3030

3131
#if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM Compiler */
3232
#define __MFBD_SECTION(x) __attribute__((section(x)))

0 commit comments

Comments
 (0)