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.

163 lines
5.0 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
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 "light.h"
  2. static bool s_interval_working_mode;
  3. static rgb_light_mode_t s_rgb_now_state;
  4. static rgb_light_mode_t s_rgb_light_mode_config;
  5. static int s_errornum = 0;
  6. static bool s_errorlight_display_state;
  7. static bool s_autoshutdown_light_state;
  8. /**
  9. * @brief ,
  10. * 绿
  11. */
  12. static void prv_light_module_set_rgb_mode(rgb_light_mode_t mode) {
  13. if (mode == krgb_color_red) {
  14. port_led_r_set(true);
  15. port_led_g_set(false);
  16. port_led_b_set(false);
  17. } else if (mode == krgb_color_blue) {
  18. port_led_r_set(false);
  19. port_led_g_set(false);
  20. port_led_b_set(true);
  21. } else if (mode == krgb_color_green) {
  22. port_led_r_set(false);
  23. port_led_b_set(false);
  24. port_led_g_set(true);
  25. } else if (mode == krgb_close) {
  26. port_led_r_set(false);
  27. port_led_g_set(false);
  28. port_led_b_set(false);
  29. }
  30. s_rgb_now_state = mode;
  31. }
  32. static void prv_set_timing_light_mode(int mode) {
  33. if (mode == 1) {
  34. port_led0_set(true);
  35. port_led1_set(false);
  36. port_led2_set(false);
  37. port_led3_set(false);
  38. } else if (mode == 2) {
  39. port_led0_set(true);
  40. port_led1_set(true);
  41. port_led2_set(false);
  42. port_led3_set(false);
  43. } else if (mode == 3) {
  44. port_led0_set(true);
  45. port_led1_set(true);
  46. port_led2_set(true);
  47. port_led3_set(false);
  48. } else if (mode == 4) {
  49. port_led0_set(true);
  50. port_led1_set(true);
  51. port_led2_set(true);
  52. port_led3_set(true);
  53. } else if (mode == 0) {
  54. port_led0_set(false);
  55. port_led1_set(false);
  56. port_led2_set(false);
  57. port_led3_set(false);
  58. }
  59. }
  60. void prv_light_module_rgb_light_control_schedule() {
  61. if (s_rgb_light_mode_config == krgb_close) {
  62. prv_light_module_set_rgb_mode(krgb_close);
  63. return;
  64. }
  65. if (!s_interval_working_mode) {
  66. prv_light_module_set_rgb_mode(s_rgb_light_mode_config);
  67. return;
  68. }
  69. /**
  70. * @brief
  71. */
  72. if (s_interval_working_mode) {
  73. if (hook_get_ozone_generator_working_flag()) {
  74. static uint32_t rgb_flicker_ticket = 0;
  75. static uint8_t rgb_ticket_count = 0;
  76. if (port_haspassedms(rgb_flicker_ticket) > 1000) {
  77. rgb_flicker_ticket = get_sys_ticket();
  78. if (s_rgb_now_state == krgb_close) {
  79. prv_light_module_set_rgb_mode(s_rgb_light_mode_config);
  80. } else {
  81. prv_light_module_set_rgb_mode(krgb_close);
  82. }
  83. }
  84. } else {
  85. prv_light_module_set_rgb_mode(krgb_color_green);
  86. }
  87. }
  88. }
  89. /**
  90. * @brief
  91. */
  92. static void prv_time_light_control_schedule() {
  93. if (s_autoshutdown_light_state) {
  94. /**
  95. * @brief
  96. */
  97. int lightnum = hook_get_autoshutdown_timecount() / AUTO_SHUTDOWN_ONE_LIGHT_EQ_TIME_S;
  98. int lightnum_remainder = hook_get_autoshutdown_timecount() % AUTO_SHUTDOWN_ONE_LIGHT_EQ_TIME_S;
  99. if (lightnum_remainder != 0) {
  100. lightnum += 1;
  101. }
  102. prv_set_timing_light_mode(lightnum);
  103. } else if (s_errorlight_display_state) {
  104. /**
  105. * @brief
  106. */
  107. static uint32_t ticket = 0;
  108. static bool state;
  109. if (port_haspassedms(ticket) > 300) {
  110. ticket = get_sys_ticket();
  111. state = !state;
  112. if (state) {
  113. prv_set_timing_light_mode(s_errornum);
  114. } else {
  115. prv_set_timing_light_mode(0);
  116. }
  117. }
  118. } else {
  119. prv_set_timing_light_mode(0);
  120. }
  121. }
  122. /***********************************************************************************************************************
  123. * ======================================================Extern======================================================= *
  124. ***********************************************************************************************************************/
  125. void light_module_set_rgb_mode(rgb_light_mode_t mode) {
  126. printf("light_module_set_rgb_mode %d\n", mode);
  127. s_rgb_light_mode_config = mode;
  128. prv_light_module_set_rgb_mode(mode);
  129. }
  130. void light_module_set_rgb_in_interval_working_mode(bool state) {
  131. printf("light_module_set_rgb_in_interval_working_mode %d\n", state);
  132. s_interval_working_mode = state;
  133. }
  134. void light_module_set_autoshutdown_indicator_light(bool open) { s_autoshutdown_light_state = open; }
  135. void light_module_set_error_light_mode(bool open, uint8_t error_mode) {
  136. printf("light_module_set_error_light_mode %d\n", error_mode);
  137. s_errorlight_display_state = open;
  138. s_errornum = error_mode;
  139. }
  140. void light_module_close_all_light(void) {
  141. printf("light_module_close_all_light\n");
  142. light_module_set_rgb_mode(krgb_close);
  143. light_module_set_autoshutdown_indicator_light(false);
  144. light_module_set_rgb_in_interval_working_mode(false);
  145. prv_set_timing_light_mode(0);
  146. s_errornum = 0;
  147. s_interval_working_mode = false;
  148. s_autoshutdown_light_state = false;
  149. s_errorlight_display_state = false;
  150. }
  151. void light_module_schedule(void) {
  152. prv_light_module_rgb_light_control_schedule();
  153. prv_time_light_control_schedule();
  154. }