mfbd.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. /*
  2. * Copyright (c) 2022-2023, smartmx <smartmx@qq.com>
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-02-22 smartmx the first version.
  9. * 2022-03-15 smartmx each mbtn has it's own max multi-click times.
  10. * 2022-04-16 smartmx drop list definitions, use arraylist, each group has all btn types.
  11. * 2022-08-05 smartmx add reset params function.
  12. * 2023-03-15 smartmx add state declaration.
  13. * 2023-07-03 smartmx add Section Definition option.
  14. * 2023-07-15 smartmx add skip function, to reduce calling of scan functions.
  15. * 2023-07-22 smartmx add MFBD_MBTN_MULTICLICK_LONG_EVT and MFBD_MBTN_CONTINUE_LONG_COUNT option.
  16. * 2023-09-19 smartmx improve performance, add MFBD_BTN_STATE_SKIP.
  17. *
  18. */
  19. #include "mfbd.h"
  20. #if (MFBD_USE_SECTION_DEFINITION == 0)
  21. #define MFBD_BTN_IN_FUC (_pbtn)
  22. #define MFBD_BTN_INFO_IN_FUC (_pbtn->btn_info)
  23. #if MFBD_PARAMS_SAME_IN_GROUP
  24. /* filter_time */
  25. #define MFBD_FILTER_TIME_IN_FUC (_pbtn_group->filter_time)
  26. /* long_time */
  27. #define MFBD_LONG_TIME_IN_FUC (_pbtn_group->long_time)
  28. /* repeat_time */
  29. #define MFBD_REPEAT_TIME_IN_FUC (_pbtn_group->repeat_time)
  30. /* multiclick_time */
  31. #define MFBD_MULTICLICK_TIME_IN_FUC (_pbtn_group->multiclick_time)
  32. #else
  33. /* filter_time */
  34. #define MFBD_FILTER_TIME_IN_FUC (MFBD_BTN_INFO_IN_FUC->filter_time)
  35. /* long_time */
  36. #define MFBD_LONG_TIME_IN_FUC (MFBD_BTN_INFO_IN_FUC->long_time)
  37. /* repeat_time */
  38. #define MFBD_REPEAT_TIME_IN_FUC (MFBD_BTN_INFO_IN_FUC->repeat_time)
  39. /* multiclick_time */
  40. #define MFBD_MULTICLICK_TIME_IN_FUC (MFBD_BTN_INFO_IN_FUC->multiclick_time)
  41. #endif /* MFBD_PARAMS_SAME_IN_GROUP */
  42. #if MFBD_USE_TINY_BUTTON
  43. /**
  44. * @brief scan all tiny buttons, and report button event value if event happened.
  45. *
  46. * @param _pbtn_group is a pointer of mfbd_group_t.
  47. *
  48. * @return None.
  49. */
  50. void mfbd_tbtn_scan(const mfbd_group_t *_pbtn_group)
  51. {
  52. mfbd_tbtn_t **_ppbtn = _pbtn_group->tbtns;
  53. mfbd_tbtn_t *_pbtn = *_ppbtn;
  54. MFBD_BTN_STATE_t btn_state;
  55. while (MFBD_BTN_IN_FUC != NULL)
  56. {
  57. btn_state = _pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->btn_index);
  58. if (btn_state == MFBD_BTN_STATE_DOWN)
  59. {
  60. if(MFBD_BTN_IN_FUC->filter_count >= ((MFBD_FILTER_TIME_IN_FUC) * 2))
  61. {
  62. /* it means the button is down for over filter_time. */
  63. if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_UP)
  64. {
  65. if (MFBD_BTN_INFO_IN_FUC->btn_down_code > 0)
  66. {
  67. _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code);
  68. }
  69. MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_DOWN;
  70. }
  71. }
  72. else if(MFBD_BTN_IN_FUC->filter_count >= (MFBD_FILTER_TIME_IN_FUC))
  73. {
  74. MFBD_BTN_IN_FUC->filter_count++;
  75. }
  76. else
  77. {
  78. MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC);
  79. }
  80. }
  81. else if (btn_state == MFBD_BTN_STATE_UP)
  82. {
  83. if (MFBD_BTN_IN_FUC->filter_count == 0)
  84. {
  85. if (MFBD_BTN_IN_FUC->state != MFBD_BTN_STATE_UP)
  86. {
  87. if (MFBD_BTN_INFO_IN_FUC->btn_up_code > 0)
  88. {
  89. _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_up_code);
  90. }
  91. MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP;
  92. }
  93. }
  94. else
  95. {
  96. if (MFBD_BTN_IN_FUC->filter_count > (MFBD_FILTER_TIME_IN_FUC))
  97. {
  98. MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC);
  99. }
  100. else if (MFBD_BTN_IN_FUC->filter_count != 0)
  101. {
  102. MFBD_BTN_IN_FUC->filter_count--;
  103. }
  104. }
  105. }
  106. _ppbtn++;
  107. _pbtn = *_ppbtn;
  108. }
  109. }
  110. /**
  111. * @brief reset all tiny buttons' params.
  112. *
  113. * @param _pbtn_group is a pointer of mfbd_group_t.
  114. *
  115. * @return None.
  116. */
  117. void mfbd_tbtn_reset(const mfbd_group_t *_pbtn_group)
  118. {
  119. mfbd_tbtn_t **_ppbtn = _pbtn_group->tbtns;
  120. mfbd_tbtn_t *_pbtn = *_ppbtn;
  121. while (MFBD_BTN_IN_FUC != NULL)
  122. {
  123. MFBD_BTN_IN_FUC->filter_count = 0;
  124. MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP;
  125. _ppbtn++;
  126. _pbtn = *_ppbtn;
  127. }
  128. }
  129. #endif /* MFBD_USE_TINY_BUTTON */
  130. #if MFBD_USE_NORMAL_BUTTON
  131. /**
  132. * @brief scan all normal buttons, and report button event value if event happened.
  133. *
  134. * @param _pbtn_group is a pointer of mfbd_group_t.
  135. *
  136. * @return None
  137. */
  138. void mfbd_nbtn_scan(const mfbd_group_t *_pbtn_group)
  139. {
  140. mfbd_nbtn_t **_ppbtn = _pbtn_group->nbtns;
  141. mfbd_nbtn_t *_pbtn = *_ppbtn;
  142. MFBD_BTN_STATE_t btn_state;
  143. while (MFBD_BTN_IN_FUC != NULL)
  144. {
  145. btn_state = _pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->btn_index);
  146. if (btn_state == MFBD_BTN_STATE_DOWN)
  147. {
  148. if(MFBD_BTN_IN_FUC->filter_count >= ((MFBD_FILTER_TIME_IN_FUC) * 2))
  149. {
  150. /* it means the button is down for over filter_time. */
  151. if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG)
  152. {
  153. /* MFBD_BTN_STATE_LONG */
  154. if (MFBD_BTN_IN_FUC->repeat_count > 0)
  155. {
  156. MFBD_BTN_IN_FUC->repeat_count++;
  157. if (MFBD_BTN_IN_FUC->repeat_count > (MFBD_REPEAT_TIME_IN_FUC))
  158. {
  159. /* repeat event has happened, reset repeat_count to 1. */
  160. MFBD_BTN_IN_FUC->repeat_count = 1;
  161. _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code);
  162. }
  163. }
  164. }
  165. else if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN)
  166. {
  167. if (MFBD_BTN_IN_FUC->long_count > 0)
  168. {
  169. /* if long_time is 0 or long_code is 0, disable long and repeat check. */
  170. if (MFBD_BTN_IN_FUC->long_count <= (MFBD_LONG_TIME_IN_FUC))
  171. {
  172. MFBD_BTN_IN_FUC->long_count++;
  173. if (MFBD_BTN_IN_FUC->long_count > (MFBD_LONG_TIME_IN_FUC))
  174. {
  175. /* it means the button is down for over long_time. */
  176. if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (MFBD_BTN_INFO_IN_FUC->btn_down_code != 0))
  177. {
  178. /* repeat event is enabled in this btn. */
  179. MFBD_BTN_IN_FUC->repeat_count = 1;
  180. }
  181. else
  182. {
  183. /* repeat event is disabled in this btn. */
  184. MFBD_BTN_IN_FUC->repeat_count = 0;
  185. }
  186. _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_long_code);
  187. MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_LONG;
  188. }
  189. }
  190. }
  191. }
  192. else
  193. {
  194. /* MFBD_BTN_STATE_UP */
  195. /* clear long_count. */
  196. if (((MFBD_LONG_TIME_IN_FUC) > 0) && (MFBD_BTN_INFO_IN_FUC->btn_long_code != 0))
  197. {
  198. /* long event is enabled in this btn. */
  199. MFBD_BTN_IN_FUC->long_count = 1;
  200. }
  201. else
  202. {
  203. /* long event is disabled in this btn. */
  204. MFBD_BTN_IN_FUC->long_count = 0;
  205. }
  206. if (MFBD_BTN_INFO_IN_FUC->btn_down_code > 0)
  207. {
  208. _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code);
  209. }
  210. MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_DOWN;
  211. }
  212. }
  213. else if(MFBD_BTN_IN_FUC->filter_count >= (MFBD_FILTER_TIME_IN_FUC))
  214. {
  215. MFBD_BTN_IN_FUC->filter_count++;
  216. }
  217. else
  218. {
  219. MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC);
  220. }
  221. }
  222. else if (btn_state == MFBD_BTN_STATE_UP)
  223. {
  224. if (MFBD_BTN_IN_FUC->filter_count == 0)
  225. {
  226. if (MFBD_BTN_IN_FUC->state != MFBD_BTN_STATE_UP)
  227. {
  228. if (MFBD_BTN_INFO_IN_FUC->btn_up_code > 0)
  229. {
  230. _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_up_code);
  231. }
  232. MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP;
  233. }
  234. }
  235. else
  236. {
  237. if (MFBD_BTN_IN_FUC->filter_count > (MFBD_FILTER_TIME_IN_FUC))
  238. {
  239. MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC);
  240. }
  241. else if (MFBD_BTN_IN_FUC->filter_count != 0)
  242. {
  243. MFBD_BTN_IN_FUC->filter_count--;
  244. }
  245. }
  246. }
  247. _ppbtn++;
  248. _pbtn = *_ppbtn;
  249. }
  250. }
  251. /**
  252. * @brief skip some times of mfbd_btn_count_t with last state.
  253. *
  254. * @param _pbtn_group is a pointer of mfbd_group_t.
  255. * @param times is times need to skip.
  256. *
  257. * @return None.
  258. */
  259. void mfbd_nbtn_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times)
  260. {
  261. mfbd_nbtn_t **_ppbtn = _pbtn_group->nbtns;
  262. mfbd_nbtn_t *_pbtn = *_ppbtn;
  263. while (MFBD_BTN_IN_FUC != NULL)
  264. {
  265. if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN)
  266. {
  267. if ((MFBD_BTN_IN_FUC->long_count > 0) && (MFBD_BTN_IN_FUC->long_count < (MFBD_LONG_TIME_IN_FUC)))
  268. {
  269. if(((MFBD_LONG_TIME_IN_FUC) - MFBD_BTN_IN_FUC->long_count) > times)
  270. {
  271. MFBD_BTN_IN_FUC->long_count = MFBD_BTN_IN_FUC->long_count + times;
  272. }
  273. else
  274. {
  275. MFBD_BTN_IN_FUC->long_count = MFBD_LONG_TIME_IN_FUC;
  276. }
  277. }
  278. }
  279. else if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG)
  280. {
  281. if ((MFBD_BTN_IN_FUC->repeat_count > 0) && (MFBD_BTN_IN_FUC->repeat_count < (MFBD_REPEAT_TIME_IN_FUC)))
  282. {
  283. if(((MFBD_REPEAT_TIME_IN_FUC) - MFBD_BTN_IN_FUC->repeat_count) > times)
  284. {
  285. MFBD_BTN_IN_FUC->repeat_count = MFBD_BTN_IN_FUC->repeat_count + times;
  286. }
  287. else
  288. {
  289. MFBD_BTN_IN_FUC->repeat_count = MFBD_REPEAT_TIME_IN_FUC;
  290. }
  291. }
  292. }
  293. _ppbtn++;
  294. _pbtn = *_ppbtn;
  295. }
  296. }
  297. /**
  298. * @brief reset all normal buttons' params.
  299. *
  300. * @param _pbtn_group is a pointer of mfbd_group_t.
  301. *
  302. * @return None.
  303. */
  304. void mfbd_nbtn_reset(const mfbd_group_t *_pbtn_group)
  305. {
  306. mfbd_nbtn_t **_ppbtn = _pbtn_group->nbtns;
  307. mfbd_nbtn_t *_pbtn = *_ppbtn;
  308. while (MFBD_BTN_IN_FUC != NULL)
  309. {
  310. MFBD_BTN_IN_FUC->filter_count = 0;
  311. MFBD_BTN_IN_FUC->long_count = 0;
  312. MFBD_BTN_IN_FUC->repeat_count = 0;
  313. MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP;
  314. _ppbtn++;
  315. _pbtn = *_ppbtn;
  316. }
  317. }
  318. #endif /* MFBD_USE_NORMAL_BUTTON */
  319. #if MFBD_USE_MULTIFUCNTION_BUTTON
  320. /**
  321. * @brief scan all multi-function buttons, and report button event value if event happened.
  322. *
  323. * @param _pbtn_group is a pointer of mfbd_group_t.
  324. *
  325. * @return None.
  326. */
  327. void mfbd_mbtn_scan(const mfbd_group_t *_pbtn_group)
  328. {
  329. mfbd_mbtn_t **_ppbtn = _pbtn_group->mbtns;
  330. mfbd_mbtn_t *_pbtn = *_ppbtn;
  331. MFBD_BTN_STATE_t btn_state;
  332. while (MFBD_BTN_IN_FUC != NULL)
  333. {
  334. btn_state = _pbtn_group->is_btn_down_func(MFBD_BTN_INFO_IN_FUC->btn_index);
  335. if (btn_state == MFBD_BTN_STATE_DOWN)
  336. {
  337. if(MFBD_BTN_IN_FUC->filter_count >= ((MFBD_FILTER_TIME_IN_FUC) * 2))
  338. {
  339. /* it means the button is down for over filter_time. */
  340. #if MFBD_MBTN_CONTINUE_LONG_COUNT
  341. #if MFBD_MBTN_MULTICLICK_LONG_EVT
  342. if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG)
  343. {
  344. /* MFBD_BTN_STATE_LONG */
  345. if (MFBD_BTN_IN_FUC->repeat_count > 0)
  346. {
  347. MFBD_BTN_IN_FUC->repeat_count++;
  348. if (MFBD_BTN_IN_FUC->repeat_count > (MFBD_REPEAT_TIME_IN_FUC))
  349. {
  350. /* repeat event has happened, clear repeat_count. */
  351. MFBD_BTN_IN_FUC->repeat_count = 1;
  352. _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code[MFBD_BTN_IN_FUC->multiclick_state]);
  353. }
  354. }
  355. }
  356. else if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN)
  357. {
  358. if (MFBD_BTN_IN_FUC->long_count > 0)
  359. {
  360. /* if long_time is 0 or long_code is 0, disable long and repeat check. */
  361. if (MFBD_BTN_IN_FUC->long_count <= (MFBD_LONG_TIME_IN_FUC))
  362. {
  363. MFBD_BTN_IN_FUC->long_count++;
  364. if (MFBD_BTN_IN_FUC->long_count > (MFBD_LONG_TIME_IN_FUC))
  365. {
  366. /* it means the button is down for over long_time. */
  367. if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (MFBD_BTN_INFO_IN_FUC->btn_down_code[MFBD_BTN_IN_FUC->multiclick_state] != 0))
  368. {
  369. /* repeat event is enabled in this btn. */
  370. MFBD_BTN_IN_FUC->repeat_count = 1;
  371. }
  372. else
  373. {
  374. /* repeat event is disabled in this btn. */
  375. MFBD_BTN_IN_FUC->repeat_count = 0;
  376. }
  377. _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_long_code);
  378. MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_LONG;
  379. }
  380. }
  381. }
  382. }
  383. #else
  384. if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG)
  385. {
  386. /* we don't support repeat event here.*/
  387. }
  388. else if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN)
  389. {
  390. if (MFBD_BTN_IN_FUC->long_count > 0)
  391. {
  392. /* if long_time is 0 or long_code is 0, disable long and repeat check. */
  393. if (MFBD_BTN_IN_FUC->long_count <= (MFBD_LONG_TIME_IN_FUC))
  394. {
  395. MFBD_BTN_IN_FUC->long_count++;
  396. if (MFBD_BTN_IN_FUC->long_count > (MFBD_LONG_TIME_IN_FUC))
  397. {
  398. /* it means the button is down for over long_time. */
  399. if (MFBD_BTN_IN_FUC->multiclick_state == 0)
  400. {
  401. _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_long_code);
  402. }
  403. MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_LONG;
  404. }
  405. }
  406. }
  407. }
  408. #endif /* MFBD_MBTN_MULTICLICK_LONG_EVT */
  409. #else
  410. if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG)
  411. {
  412. /* MFBD_BTN_STATE_LONG */
  413. if (MFBD_BTN_IN_FUC->repeat_count > 0)
  414. {
  415. MFBD_BTN_IN_FUC->repeat_count++;
  416. if (MFBD_BTN_IN_FUC->repeat_count > (MFBD_REPEAT_TIME_IN_FUC))
  417. {
  418. /* repeat event has happened, clear repeat_count. */
  419. MFBD_BTN_IN_FUC->repeat_count = 1;
  420. _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code[0]);
  421. }
  422. }
  423. }
  424. else if (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN)
  425. {
  426. if (MFBD_BTN_IN_FUC->multiclick_state == 0)
  427. {
  428. if (MFBD_BTN_IN_FUC->long_count > 0)
  429. {
  430. /* if long_time is 0 or long_code is 0, disable long and repeat check. */
  431. if (MFBD_BTN_IN_FUC->long_count <= (MFBD_LONG_TIME_IN_FUC))
  432. {
  433. MFBD_BTN_IN_FUC->long_count++;
  434. if (MFBD_BTN_IN_FUC->long_count > (MFBD_LONG_TIME_IN_FUC))
  435. {
  436. /* it means the button is down for over long_time. */
  437. if (((MFBD_REPEAT_TIME_IN_FUC) > 0) && (MFBD_BTN_INFO_IN_FUC->btn_down_code[0] != 0))
  438. {
  439. /* repeat event is enabled in this btn. */
  440. MFBD_BTN_IN_FUC->repeat_count = 1;
  441. }
  442. else
  443. {
  444. /* repeat event is disabled in this btn. */
  445. MFBD_BTN_IN_FUC->repeat_count = 0;
  446. }
  447. _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_long_code);
  448. MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_LONG;
  449. }
  450. }
  451. }
  452. }
  453. }
  454. #endif /* MFBD_MBTN_CONTINUE_LONG_COUNT */
  455. else
  456. {
  457. /* MFBD_BTN_STATE_UP */
  458. /* clear long_count. */
  459. if (((MFBD_LONG_TIME_IN_FUC) > 0) && (MFBD_BTN_INFO_IN_FUC->btn_long_code != 0))
  460. {
  461. /* long event is enabled in this btn. */
  462. MFBD_BTN_IN_FUC->long_count = 1;
  463. }
  464. else
  465. {
  466. /* long event is disabled in this btn. */
  467. MFBD_BTN_IN_FUC->long_count = 0;
  468. }
  469. if (MFBD_BTN_INFO_IN_FUC->btn_down_code[MFBD_BTN_IN_FUC->multiclick_state] > 0)
  470. {
  471. _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_down_code[MFBD_BTN_IN_FUC->multiclick_state]);
  472. }
  473. MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_DOWN;
  474. }
  475. }
  476. else if(MFBD_BTN_IN_FUC->filter_count >= (MFBD_FILTER_TIME_IN_FUC))
  477. {
  478. MFBD_BTN_IN_FUC->filter_count++;
  479. }
  480. else
  481. {
  482. MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC);
  483. }
  484. }
  485. else if (btn_state == MFBD_BTN_STATE_UP)
  486. {
  487. if (MFBD_BTN_IN_FUC->filter_count == 0)
  488. {
  489. if (MFBD_BTN_IN_FUC->state != MFBD_BTN_STATE_UP)
  490. {
  491. #if MFBD_MULTICLICK_STATE_AUTO_RESET
  492. /* if multiclick_state is not 0 and less than max_multiclick_state, inc multiclick_state */
  493. if (((MFBD_MULTICLICK_TIME_IN_FUC) != 0)
  494. && (MFBD_BTN_IN_FUC->multiclick_state < MFBD_BTN_INFO_IN_FUC->max_multiclick_state)
  495. #if (MFBD_MBTN_CONTINUE_LONG_COUNT==0)
  496. && (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN)
  497. #endif /* (MFBD_MBTN_CONTINUE_LONG_COUNT==0) */
  498. )
  499. {
  500. MFBD_BTN_IN_FUC->multiclick_state++;
  501. MFBD_BTN_IN_FUC->multiclick_count = 0;
  502. }
  503. #else
  504. /* if multiclick_state is not 0 and less than max_multiclick_state, inc multiclick_state */
  505. if (((MFBD_MULTICLICK_TIME_IN_FUC) != 0)
  506. #if (MFBD_MBTN_CONTINUE_LONG_COUNT==0)
  507. && (MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN)
  508. #endif /* (MFBD_MBTN_CONTINUE_LONG_COUNT==0) */
  509. )
  510. {
  511. if(MFBD_BTN_IN_FUC->multiclick_state < MFBD_BTN_INFO_IN_FUC->max_multiclick_state)
  512. {
  513. MFBD_BTN_IN_FUC->multiclick_state++;
  514. }
  515. MFBD_BTN_IN_FUC->multiclick_count = 0;
  516. }
  517. #endif /* MFBD_MULTICLICK_STATE_AUTO_RESET */
  518. else
  519. {
  520. /* over max multi-click times or (long event and repeat event) happened, reset to 0. */
  521. MFBD_BTN_IN_FUC->multiclick_state = 0;
  522. }
  523. if (MFBD_BTN_INFO_IN_FUC->btn_up_code > 0)
  524. {
  525. _pbtn_group->btn_value_report(MFBD_BTN_INFO_IN_FUC->btn_up_code);
  526. }
  527. MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP;
  528. }
  529. else
  530. {
  531. if (MFBD_BTN_IN_FUC->multiclick_state != 0)
  532. {
  533. MFBD_BTN_IN_FUC->multiclick_count++;
  534. if (MFBD_BTN_IN_FUC->multiclick_count >= (MFBD_MULTICLICK_TIME_IN_FUC))
  535. {
  536. MFBD_BTN_IN_FUC->multiclick_state = 0;
  537. }
  538. }
  539. }
  540. }
  541. else
  542. {
  543. if (MFBD_BTN_IN_FUC->filter_count > (MFBD_FILTER_TIME_IN_FUC))
  544. {
  545. MFBD_BTN_IN_FUC->filter_count = (MFBD_FILTER_TIME_IN_FUC);
  546. }
  547. else if (MFBD_BTN_IN_FUC->filter_count != 0)
  548. {
  549. MFBD_BTN_IN_FUC->filter_count--;
  550. }
  551. }
  552. }
  553. _ppbtn++;
  554. _pbtn = *_ppbtn;
  555. }
  556. }
  557. /**
  558. * @brief skip some times of mfbd_btn_count_t with last state.
  559. *
  560. * @param _pbtn_group is a pointer of mfbd_group_t.
  561. * @param times is times need to skip.
  562. *
  563. * @return None.
  564. */
  565. void mfbd_mbtn_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times)
  566. {
  567. mfbd_mbtn_t **_ppbtn = _pbtn_group->mbtns;
  568. mfbd_mbtn_t *_pbtn = *_ppbtn;
  569. while (MFBD_BTN_IN_FUC != NULL)
  570. {
  571. if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_UP)
  572. {
  573. if (MFBD_BTN_IN_FUC->multiclick_state != 0)
  574. {
  575. if (MFBD_BTN_IN_FUC->multiclick_count < (MFBD_MULTICLICK_TIME_IN_FUC))
  576. {
  577. if(((MFBD_MULTICLICK_TIME_IN_FUC) - MFBD_BTN_IN_FUC->multiclick_count) > times)
  578. {
  579. MFBD_BTN_IN_FUC->multiclick_count = MFBD_BTN_IN_FUC->multiclick_count + times;
  580. }
  581. else
  582. {
  583. MFBD_BTN_IN_FUC->multiclick_state = 0;
  584. }
  585. }
  586. }
  587. }
  588. #if MFBD_MBTN_CONTINUE_LONG_COUNT
  589. #if MFBD_MBTN_MULTICLICK_LONG_EVT
  590. else if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN)
  591. {
  592. if ((MFBD_BTN_IN_FUC->long_count > 0) && (MFBD_BTN_IN_FUC->long_count < (MFBD_LONG_TIME_IN_FUC)))
  593. {
  594. if(((MFBD_LONG_TIME_IN_FUC) - MFBD_BTN_IN_FUC->long_count) > times)
  595. {
  596. MFBD_BTN_IN_FUC->long_count = MFBD_BTN_IN_FUC->long_count + times;
  597. }
  598. else
  599. {
  600. MFBD_BTN_IN_FUC->long_count = MFBD_LONG_TIME_IN_FUC;
  601. }
  602. }
  603. }
  604. else
  605. {
  606. /* MFBD_BTN_STATE_LONG, if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) */
  607. if ((MFBD_BTN_IN_FUC->repeat_count > 0) && (MFBD_BTN_IN_FUC->repeat_count < (MFBD_REPEAT_TIME_IN_FUC)))
  608. {
  609. if(((MFBD_REPEAT_TIME_IN_FUC) - MFBD_BTN_IN_FUC->repeat_count) > times)
  610. {
  611. MFBD_BTN_IN_FUC->repeat_count = MFBD_BTN_IN_FUC->repeat_count + times;
  612. }
  613. else
  614. {
  615. MFBD_BTN_IN_FUC->repeat_count = MFBD_REPEAT_TIME_IN_FUC;
  616. }
  617. }
  618. }
  619. #else
  620. else if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN)
  621. {
  622. if ((MFBD_BTN_IN_FUC->long_count > 0) && (MFBD_BTN_IN_FUC->long_count < (MFBD_LONG_TIME_IN_FUC)))
  623. {
  624. /* if long_time is 0 or long_code is 0, disable long and repeat check. */
  625. if(((MFBD_LONG_TIME_IN_FUC) - MFBD_BTN_IN_FUC->long_count) > times)
  626. {
  627. MFBD_BTN_IN_FUC->long_count = MFBD_BTN_IN_FUC->long_count + times;
  628. }
  629. else
  630. {
  631. MFBD_BTN_IN_FUC->long_count = MFBD_LONG_TIME_IN_FUC;
  632. }
  633. }
  634. }
  635. else
  636. {
  637. /* MFBD_BTN_STATE_LONG, if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) */
  638. /* we don't support repeat event here.*/
  639. }
  640. #endif /* MFBD_MBTN_MULTICLICK_LONG_EVT */
  641. #else
  642. else if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_DOWN)
  643. {
  644. if ((MFBD_BTN_IN_FUC->long_count > 0) && (MFBD_BTN_IN_FUC->long_count < (MFBD_LONG_TIME_IN_FUC)))
  645. {
  646. if(((MFBD_LONG_TIME_IN_FUC) - MFBD_BTN_IN_FUC->long_count) > times)
  647. {
  648. MFBD_BTN_IN_FUC->long_count = MFBD_BTN_IN_FUC->long_count + times;
  649. }
  650. else
  651. {
  652. MFBD_BTN_IN_FUC->long_count = MFBD_LONG_TIME_IN_FUC;
  653. }
  654. }
  655. }
  656. else
  657. {
  658. /* MFBD_BTN_STATE_LONG, if(MFBD_BTN_IN_FUC->state == MFBD_BTN_STATE_LONG) */
  659. if ((MFBD_BTN_IN_FUC->repeat_count > 0) && (MFBD_BTN_IN_FUC->repeat_count < (MFBD_REPEAT_TIME_IN_FUC)))
  660. {
  661. if(((MFBD_REPEAT_TIME_IN_FUC) - MFBD_BTN_IN_FUC->repeat_count) > times)
  662. {
  663. MFBD_BTN_IN_FUC->repeat_count = MFBD_BTN_IN_FUC->repeat_count + times;
  664. }
  665. else
  666. {
  667. MFBD_BTN_IN_FUC->repeat_count = MFBD_REPEAT_TIME_IN_FUC;
  668. }
  669. }
  670. }
  671. #endif /* MFBD_MBTN_CONTINUE_LONG_COUNT */
  672. _ppbtn++;
  673. _pbtn = *_ppbtn;
  674. }
  675. }
  676. /**
  677. * @brief reset all multi-function buttons' params.
  678. *
  679. * @param _pbtn_group is a pointer of mfbd_group_t.
  680. *
  681. * @return None.
  682. */
  683. void mfbd_mbtn_reset(const mfbd_group_t *_pbtn_group)
  684. {
  685. mfbd_mbtn_t **_ppbtn = _pbtn_group->mbtns;
  686. mfbd_mbtn_t *_pbtn = *_ppbtn;
  687. while (MFBD_BTN_IN_FUC != NULL)
  688. {
  689. MFBD_BTN_IN_FUC->filter_count = 0;
  690. MFBD_BTN_IN_FUC->long_count = 0;
  691. MFBD_BTN_IN_FUC->multiclick_count = 0;
  692. MFBD_BTN_IN_FUC->multiclick_state = 0;
  693. MFBD_BTN_IN_FUC->repeat_count = 0;
  694. MFBD_BTN_IN_FUC->state = MFBD_BTN_STATE_UP;
  695. _ppbtn++;
  696. _pbtn = *_ppbtn;
  697. }
  698. }
  699. #endif /* MFBD_USE_MULTIFUCNTION_BUTTON */
  700. /**
  701. * @brief scan all buttons in the group, and report button event value if event happened.
  702. *
  703. * @param _pbtn_group is a pointer of mfbd_group_t.
  704. *
  705. * @return None.
  706. */
  707. void mfbd_group_scan(const mfbd_group_t *_pbtn_group)
  708. {
  709. #if MFBD_USE_BTN_SCAN_PRE_FUNC
  710. if (_pbtn_group->btn_scan_prepare != NULL)
  711. {
  712. /* call prepare scan function */
  713. _pbtn_group->btn_scan_prepare();
  714. }
  715. #endif /* MFBD_USE_BTN_SCAN_PRE_FUNC */
  716. #if MFBD_USE_TINY_BUTTON
  717. if (_pbtn_group->tbtns != NULL)
  718. {
  719. /*scan tiny buttons in group.*/
  720. mfbd_tbtn_scan(_pbtn_group);
  721. }
  722. #endif /* MFBD_USE_TINY_BUTTON */
  723. #if MFBD_USE_NORMAL_BUTTON
  724. if (_pbtn_group->nbtns != NULL)
  725. {
  726. /*scan normal buttons in group.*/
  727. mfbd_nbtn_scan(_pbtn_group);
  728. }
  729. #endif /* MFBD_USE_NORMAL_BUTTON */
  730. #if MFBD_USE_MULTIFUCNTION_BUTTON
  731. if (_pbtn_group->mbtns != NULL)
  732. {
  733. /*scan multifunction buttons in group.*/
  734. mfbd_mbtn_scan(_pbtn_group);
  735. }
  736. #endif /* MFBD_USE_MULTIFUCNTION_BUTTON */
  737. #if MFBD_USE_BTN_SCAN_AFTER_FUNC
  738. if (_pbtn_group->btn_scan_after != NULL)
  739. {
  740. /* call after scan function */
  741. _pbtn_group->btn_scan_after();
  742. }
  743. #endif /* MFBD_USE_BTN_SCAN_AFTER_FUNC */
  744. }
  745. /**
  746. * @brief skip some times with last state.
  747. *
  748. * @param _pbtn_group is a pointer of mfbd_group_t.
  749. * @param times is times need to skip.
  750. *
  751. * @return None.
  752. */
  753. void mfbd_group_skip(const mfbd_group_t *_pbtn_group, mfbd_btn_count_t times)
  754. {
  755. /* tbtn doesn't need to skip times. */
  756. #if MFBD_USE_NORMAL_BUTTON
  757. if (_pbtn_group->nbtns != NULL)
  758. {
  759. /* skip times of normal buttons in group.*/
  760. mfbd_nbtn_skip(_pbtn_group, times);
  761. }
  762. #endif /* MFBD_USE_NORMAL_BUTTON */
  763. #if MFBD_USE_MULTIFUCNTION_BUTTON
  764. if (_pbtn_group->mbtns != NULL)
  765. {
  766. /* skip times of multifunction buttons in group.*/
  767. mfbd_mbtn_skip(_pbtn_group, times);
  768. }
  769. #endif /* MFBD_USE_MULTIFUCNTION_BUTTON */
  770. }
  771. /**
  772. * @brief reset all buttons params in the group.
  773. *
  774. * @param _pbtn_group is a pointer of mfbd_group_t.
  775. *
  776. * @return None.
  777. */
  778. void mfbd_group_reset(const mfbd_group_t *_pbtn_group)
  779. {
  780. #if MFBD_USE_TINY_BUTTON
  781. if (_pbtn_group->tbtns != NULL)
  782. {
  783. /*reset tiny buttons in group.*/
  784. mfbd_tbtn_reset(_pbtn_group);
  785. }
  786. #endif /* MFBD_USE_TINY_BUTTON */
  787. #if MFBD_USE_NORMAL_BUTTON
  788. if (_pbtn_group->nbtns != NULL)
  789. {
  790. /*reset normal buttons in group.*/
  791. mfbd_nbtn_reset(_pbtn_group);
  792. }
  793. #endif /* MFBD_USE_NORMAL_BUTTON */
  794. #if MFBD_USE_MULTIFUCNTION_BUTTON
  795. if (_pbtn_group->mbtns != NULL)
  796. {
  797. /*reset multifunction buttons in group.*/
  798. mfbd_mbtn_reset(_pbtn_group);
  799. }
  800. #endif /* MFBD_USE_MULTIFUCNTION_BUTTON */
  801. }
  802. #endif /* (MFBD_USE_SECTION_DEFINITION == 0) */