You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
1.8 KiB

2 years ago
  1. #include "zkey.h"
  2. #define TAG "zkey"
  3. static zkey_module_t *s_module;
  4. static bool s_inited;
  5. void zkey_process_each_after_filter(zkey_t *each, bool now_io_state)
  6. {
  7. if (now_io_state != each->last_io_state)
  8. {
  9. if (now_io_state)
  10. {
  11. each->keep_state_count = 0;
  12. each->hasProcessed = false;
  13. each->cur_state = zks_rising_edge;
  14. s_module->onkey(each, each->cur_state);
  15. }
  16. else
  17. {
  18. each->cur_state = zks_falling_edge;
  19. s_module->onkey(each, each->cur_state);
  20. each->keep_state_count = 0;
  21. }
  22. each->last_io_state = now_io_state;
  23. }
  24. else
  25. {
  26. each->cur_state = zks_keep;
  27. if (now_io_state)
  28. {
  29. s_module->onkey(each, each->cur_state);
  30. }
  31. }
  32. }
  33. void zkey_process_each(zkey_t *each)
  34. {
  35. /**
  36. * @brief zkey_process_each
  37. */
  38. each->keep_state_count++;
  39. bool now_io_state = each->get_key_state();
  40. if (each->currentstatekeep_count < 1000)
  41. {
  42. each->currentstatekeep_count++;
  43. }
  44. if (now_io_state != each->last_real_state)
  45. {
  46. each->currentstatekeep_count = 0;
  47. }
  48. if (each->currentstatekeep_count >= 1)
  49. {
  50. each->after_filter_state = now_io_state;
  51. }
  52. each->last_real_state = now_io_state;
  53. zkey_process_each_after_filter(each, each->after_filter_state);
  54. /**
  55. * @brief
  56. */
  57. }
  58. void zkey_do_loop_in_each_period(void *_null)
  59. {
  60. if (!s_inited)
  61. return;
  62. for (int i = 0; i < s_module->nkey; i++)
  63. {
  64. zkey_process_each(&s_module->keys[i]);
  65. }
  66. }
  67. void zkey_init(zkey_module_t *module)
  68. {
  69. s_module = module;
  70. //
  71. s_inited = true;
  72. for (int i = 0; i < s_module->nkey; i++)
  73. {
  74. s_module->keys[i].cur_state = zks_keep;
  75. s_module->keys[i].last_io_state = s_module->keys[i].get_key_state();
  76. s_module->keys[i].after_filter_state = s_module->keys[i].get_key_state();
  77. }
  78. }