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.

154 lines
4.7 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. #include "human_computer_interaction_service.h"
  2. #include "port.h"
  3. #include "zes8p5066lib/systicket.h"
  4. #include "zsimple_timer/zsimple_timer.h"
  5. void hcis_active_input(active_input_t input) {
  6. thisDevice.active_start_ticket = systicket_get_now_ms();
  7. thisDevice.active_input = input;
  8. }
  9. bool hcis_input_is_active(active_input_t input) { return (thisDevice.active_input == input); }
  10. /***********************************************************************************************************************
  11. * =====================================================schedule====================================================== *
  12. ***********************************************************************************************************************/
  13. void mf_set_status_light_state(bool r, bool g, bool b) {
  14. port_led_r_set(r);
  15. port_led_g_set(g);
  16. port_led_b_set(b);
  17. }
  18. static void mf_set_status_light_by_level(level_t level) {
  19. if (level == klevel1) {
  20. mf_set_status_light_state(/*rgb:*/ 0, 0, 1);
  21. } else if (level == klevel2) {
  22. mf_set_status_light_state(/*rgb:*/ 1, 0, 0);
  23. }
  24. }
  25. void do_countdown_flash_light_effect() {
  26. //所有定时指示灯闪烁效果
  27. static uint32_t lastticket = 0;
  28. static bool statenow;
  29. if (systicket_haspassedms(lastticket) > kconst_active_input_light_flick_interval_ms) {
  30. lastticket = systicket_get_now_ms();
  31. statenow = !statenow;
  32. port_led0_set(statenow && thisDevice.countdonwnum > 0);
  33. port_led1_set(statenow && thisDevice.countdonwnum > 1);
  34. port_led2_set(statenow && thisDevice.countdonwnum > 2);
  35. port_led3_set(statenow && thisDevice.countdonwnum > 3);
  36. }
  37. }
  38. void close_all_light() {
  39. port_led0_set(0);
  40. port_led1_set(0);
  41. port_led2_set(0);
  42. port_led3_set(0);
  43. mf_set_status_light_state(0, 0, 0);
  44. }
  45. void process_countdonwlight() {
  46. /**
  47. * @brief
  48. *
  49. *
  50. *
  51. *
  52. */
  53. if (thisDevice.active_input == kchange_countdonw_time_input || //
  54. thisDevice.active_input == kchange_intermittentmode_time_input) {
  55. do_countdown_flash_light_effect();
  56. } else {
  57. port_led0_set(thisDevice.countdonwnum > 0);
  58. port_led1_set(thisDevice.countdonwnum > 1);
  59. port_led2_set(thisDevice.countdonwnum > 2);
  60. port_led3_set(thisDevice.countdonwnum > 3);
  61. }
  62. }
  63. void process_level_light() {
  64. /**
  65. * @brief
  66. *
  67. *
  68. * 绿
  69. *
  70. */
  71. if (thisDevice.active_input == kchange_level_input) {
  72. #if 0
  73. /**
  74. * @brief
  75. */
  76. static uint32_t lastticket = 0;
  77. static bool statenow;
  78. if (systicket_haspassedms(lastticket) > kconst_active_input_light_flick_interval_ms) {
  79. lastticket = systicket_get_now_ms();
  80. statenow = !statenow;
  81. if (statenow) {
  82. mf_set_status_light_by_level(thisDevice.level);
  83. } else {
  84. mf_set_status_light_state(/*rgb:*/ 0, 0, 0);
  85. }
  86. }
  87. #endif
  88. mf_set_status_light_by_level(thisDevice.level);
  89. } else {
  90. if (thisDevice.mode == kintermittentMode && !thisDevice.working) {
  91. mf_set_status_light_state(/*rgb:*/ 0, 1, 0);
  92. } else {
  93. mf_set_status_light_by_level(thisDevice.level);
  94. }
  95. }
  96. }
  97. void process_light_state_on_exception() {
  98. thisDevice.active_input = knone_active;
  99. static uint32_t lastticket = 0;
  100. if (systicket_haspassedms(lastticket) > 1500) {
  101. static bool statenow;
  102. statenow = !statenow;
  103. if (statenow) {
  104. mf_set_status_light_state(1, 0, 0);
  105. port_led0_set(thisDevice.error > 0);
  106. port_led1_set(thisDevice.error > 1);
  107. port_led2_set(thisDevice.error > 2);
  108. port_led3_set(thisDevice.error > 3);
  109. } else {
  110. mf_set_status_light_state(/*rgb:*/ 0, 0, 0);
  111. port_led0_set(false);
  112. port_led1_set(false);
  113. port_led2_set(false);
  114. port_led3_set(false);
  115. }
  116. lastticket = systicket_get_now_ms();
  117. }
  118. }
  119. void lcs_schedule_process() {
  120. if (!thisDevice.poweron) {
  121. close_all_light();
  122. return;
  123. }
  124. if (thisDevice.error == knoneException) {
  125. //自动失能active_input
  126. if (thisDevice.active_input != knone_active && systicket_haspassedms(thisDevice.active_start_ticket) >= kconst_flash_auto_close_time) {
  127. thisDevice.active_input = knone_active;
  128. }
  129. //控制定时指示灯
  130. process_countdonwlight();
  131. //控制等级指示灯
  132. process_level_light();
  133. } else {
  134. process_light_state_on_exception();
  135. }
  136. }
  137. void hcis_shcedule() {
  138. static uint32_t ticket = 0;
  139. if (systicket_haspassedms(ticket) > 30) {
  140. ticket = systicket_get_now_ms();
  141. lcs_schedule_process();
  142. }
  143. }