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.

72 lines
2.1 KiB

4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
  1. #include "key.h"
  2. void zkey_init(zkey_module_t *module) {
  3. /**
  4. * @brief ʼ״̬ijʼ֮ǰģڵģ֮
  5. *
  6. */
  7. s_module = module;
  8. s_inited = true; //��־λ˵��������ʼ������
  9. for (int i = 0; i < s_module->nkey; i++) {
  10. s_module->keys[i].cur_state = zks_keep;
  11. s_module->keys[i].last_io_state = s_module->keys[i].get_key_state();
  12. s_module->keys[i].after_filter_state = s_module->keys[i].get_key_state();
  13. }
  14. }
  15. void zkey_do_loop_in_each_period(void *_null) { /**
  16. * @brief ѭѯ״̬
  17. *
  18. */
  19. if (!s_inited) return;
  20. for (int i = 0; i < s_module->nkey; i++) //��ʼ��ÿ���������в�ѯ
  21. {
  22. zkey_process_each(&s_module->keys[i]);
  23. }
  24. }
  25. void zkey_process_each(zkey_t *each) {
  26. /**
  27. * @brief Ƿûʱʱ¼
  28. *
  29. * @param each
  30. */
  31. each->keep_state_count++;
  32. bool now_io_state = each->get_key_state(); //��ȡ���ڵİ���io״̬
  33. if (each->currentstatekeep_count < 1000) {
  34. each->currentstatekeep_count++;
  35. }
  36. if (now_io_state != each->last_real_state) //�����任
  37. {
  38. each->currentstatekeep_count = 0;
  39. }
  40. if (each->currentstatekeep_count >= 1) //����״̬����ʱ������20ms,���°���״̬
  41. {
  42. each->after_filter_state = now_io_state;
  43. }
  44. each->last_real_state = now_io_state;
  45. zkey_process_each_after_filter(each, each->after_filter_state);
  46. }
  47. void zkey_process_each_after_filter(zkey_t *each, bool now_io_state) {
  48. if (now_io_state != each->last_io_state) {
  49. if (now_io_state) {
  50. each->keep_state_count = 0;
  51. each->hasProcessed = false;
  52. each->cur_state = zks_rising_edge;
  53. s_module->onkey(each, each->cur_state);
  54. } else {
  55. each->cur_state = zks_falling_edge;
  56. s_module->onkey(each, each->cur_state);
  57. each->keep_state_count = 0;
  58. }
  59. each->last_io_state = now_io_state;
  60. } else {
  61. each->cur_state = zks_keep;
  62. if (now_io_state) {
  63. s_module->onkey(each, each->cur_state);
  64. }
  65. }
  66. }