|
6 | 6 | * Change Logs:
|
7 | 7 | * Date Author Notes
|
8 | 8 | * 2023-07-03 smartmx the first version, Multi-Function Button Dectection with Section Definition.
|
| 9 | + * 2023-07-15 smartmx add skip function, to reduce calling of scan functions. |
9 | 10 | *
|
10 | 11 | */
|
11 | 12 |
|
@@ -236,6 +237,60 @@ void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_nbtn_info_t *_pb
|
236 | 237 | }
|
237 | 238 | }
|
238 | 239 |
|
| 240 | +/** |
| 241 | + * @brief skip some times of mfbd_btn_count_t with last state. |
| 242 | + * |
| 243 | + * @param _pbtn_group is a pointer of mfbd_group_t. |
| 244 | + * @param times is times need to skip. |
| 245 | + * |
| 246 | + * @return None. |
| 247 | + */ |
| 248 | +void mfbd_nbtn_skip(const mfbd_group_t *_pbtn_group, const mfbd_nbtn_info_t *_pbtn_info_start, const mfbd_nbtn_info_t *_pbtn_info_end, mfbd_btn_count_t times) |
| 249 | +{ |
| 250 | + const mfbd_nbtn_info_t *_pbtn_info = _pbtn_info_start; |
| 251 | + |
| 252 | + while (1) |
| 253 | + { |
| 254 | + if (_pbtn_info_end <= _pbtn_info) |
| 255 | + { |
| 256 | + break; |
| 257 | + } |
| 258 | + if(_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN) |
| 259 | + { |
| 260 | + if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn_info->btn_long_code != 0)) |
| 261 | + { |
| 262 | + /* if long_time is 0 or long_code is 0, disable long and repeat check. */ |
| 263 | + if (_pbtn_info->btn->long_count < (MFBD_LONG_TIME_IN_FUC)) |
| 264 | + { |
| 265 | + if(((MFBD_LONG_TIME_IN_FUC) - 1 - _pbtn_info->btn->long_count) > times) |
| 266 | + { |
| 267 | + _pbtn_info->btn->long_count = _pbtn_info->btn->long_count + times; |
| 268 | + } |
| 269 | + else |
| 270 | + { |
| 271 | + _pbtn_info->btn->long_count = MFBD_LONG_TIME_IN_FUC - 1; |
| 272 | + } |
| 273 | + } |
| 274 | + } |
| 275 | + } |
| 276 | + else if(_pbtn_info->btn->state == MFBD_BTN_STATE_LONG) |
| 277 | + { |
| 278 | + if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[0] != 0)) |
| 279 | + { |
| 280 | + if(((MFBD_REPEAT_TIME_IN_FUC) - 1 - _pbtn_info->btn->repeat_count) > times) |
| 281 | + { |
| 282 | + _pbtn_info->btn->repeat_count = _pbtn_info->btn->repeat_count + times; |
| 283 | + } |
| 284 | + else |
| 285 | + { |
| 286 | + _pbtn_info->btn->repeat_count = MFBD_REPEAT_TIME_IN_FUC - 1; |
| 287 | + } |
| 288 | + } |
| 289 | + } |
| 290 | + _pbtn_info++; |
| 291 | + } |
| 292 | +} |
| 293 | + |
239 | 294 | /**
|
240 | 295 | * @brief reset all normal buttons' params.
|
241 | 296 | *
|
@@ -408,6 +463,75 @@ void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pb
|
408 | 463 | }
|
409 | 464 | }
|
410 | 465 |
|
| 466 | +/** |
| 467 | + * @brief skip some times of mfbd_btn_count_t with last state. |
| 468 | + * |
| 469 | + * @param _pbtn_group is a pointer of mfbd_group_t. |
| 470 | + * @param times is times need to skip. |
| 471 | + * |
| 472 | + * @return None. |
| 473 | + */ |
| 474 | +void mfbd_mbtn_skip(const mfbd_group_t *_pbtn_group, const mfbd_mbtn_info_t *_pbtn_info_start, const mfbd_mbtn_info_t *_pbtn_info_end, mfbd_btn_count_t times) |
| 475 | +{ |
| 476 | + const mfbd_mbtn_info_t *_pbtn_info = _pbtn_info_start; |
| 477 | + while (1) |
| 478 | + { |
| 479 | + if(_pbtn_info->btn->state == MFBD_BTN_STATE_UP) |
| 480 | + { |
| 481 | + if (_pbtn_info->btn->multiclick_state != 0) |
| 482 | + { |
| 483 | + if (_pbtn_info->btn->multiclick_count < (MFBD_MULTICLICK_TIME_IN_FUC)) |
| 484 | + { |
| 485 | + if(((MFBD_MULTICLICK_TIME_IN_FUC) - _pbtn_info->btn->multiclick_count) > times) |
| 486 | + { |
| 487 | + _pbtn_info->btn->multiclick_count = _pbtn_info->btn->multiclick_count + times; |
| 488 | + } |
| 489 | + else |
| 490 | + { |
| 491 | + _pbtn_info->btn->multiclick_state = 0; |
| 492 | + } |
| 493 | + } |
| 494 | + } |
| 495 | + } |
| 496 | + else if(_pbtn_info->btn->state == MFBD_BTN_STATE_DOWN) |
| 497 | + { |
| 498 | + if (_pbtn_info->btn->multiclick_state == 0) |
| 499 | + { |
| 500 | + if (((MFBD_LONG_TIME_IN_FUC) > 0) && (_pbtn_info->btn_long_code != 0)) |
| 501 | + { |
| 502 | + /* if long_time is 0 or long_code is 0, disable long and repeat check. */ |
| 503 | + if (_pbtn_info->btn->long_count < (MFBD_LONG_TIME_IN_FUC)) |
| 504 | + { |
| 505 | + if(((MFBD_LONG_TIME_IN_FUC) - 1 - _pbtn_info->btn->long_count) > times) |
| 506 | + { |
| 507 | + _pbtn_info->btn->long_count = _pbtn_info->btn->long_count + times; |
| 508 | + } |
| 509 | + else |
| 510 | + { |
| 511 | + _pbtn_info->btn->long_count = MFBD_LONG_TIME_IN_FUC - 1; |
| 512 | + } |
| 513 | + } |
| 514 | + } |
| 515 | + } |
| 516 | + } |
| 517 | + else if(_pbtn_info->btn->state == MFBD_BTN_STATE_LONG) |
| 518 | + { |
| 519 | + if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (_pbtn_info->btn_down_code[0] != 0)) |
| 520 | + { |
| 521 | + if(((MFBD_REPEAT_TIME_IN_FUC) - 1 - _pbtn_info->btn->repeat_count) > times) |
| 522 | + { |
| 523 | + _pbtn_info->btn->repeat_count = _pbtn_info->btn->repeat_count + times; |
| 524 | + } |
| 525 | + else |
| 526 | + { |
| 527 | + _pbtn_info->btn->repeat_count = MFBD_REPEAT_TIME_IN_FUC - 1; |
| 528 | + } |
| 529 | + } |
| 530 | + } |
| 531 | + _pbtn_info++; |
| 532 | + } |
| 533 | +} |
| 534 | + |
411 | 535 | /**
|
412 | 536 | * @brief reset all multi-function buttons' params.
|
413 | 537 | *
|
|
0 commit comments