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