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.

248 lines
7.2 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  1. #include "light_control_service.h"
  2. #include "../../zes8p5066lib/systicket.h"
  3. #include "../port.h"
  4. static Page_t s_nowpage;
  5. typedef struct {
  6. Page_t nowpage;
  7. union {
  8. struct {
  9. // rgb状态指示灯
  10. bool status_light_r;
  11. bool status_light_g;
  12. bool status_light_b;
  13. //倒计时指示灯
  14. int countdown_num; //当前灯的数量
  15. int one_light_time; //
  16. uint32_t countdown_ms; //当前灯代表的时间
  17. uint32_t flash_triggerTicket; //倒计时指示灯闪烁效果触发时间
  18. bool flash_triggered; //是否触发闪烁指示灯
  19. uint32_t flash_autoCloseTimeMs; //倒计时闪烁指示灯自动关闭时间
  20. int count_light_flash_ticket;
  21. } p1;
  22. struct {
  23. int errorNum;
  24. } p2;
  25. } p;
  26. } ModuleState_t;
  27. ModuleState_t m;
  28. void lcs_change_page(Page_t page) {
  29. m.nowpage = page;
  30. if (m.nowpage == kworkPage) {
  31. port_led_r_set(m.p.p1.status_light_r);
  32. port_led_g_set(m.p.p1.status_light_g);
  33. port_led_b_set(m.p.p1.status_light_b);
  34. }
  35. }
  36. void lcs_count_donwload_light__set_one_light_time_min(int min) {}
  37. void lcs_count_donwload_light__set_count_num(int num) {}
  38. void lcs_count_donwload_light__trigger_flash(int lastfortime, bool retrigger) {
  39. /**
  40. * @brief
  41. */
  42. m.p.p1.flash_triggerTicket = systicket_get_now_ms();
  43. m.p.p1.flash_triggered = true;
  44. m.p.p1.flash_autoCloseTimeMs = lastfortime;
  45. }
  46. void lcs_status_light__set_color(bool r, bool g, bool b) {
  47. m.p.p1.status_light_r = r;
  48. m.p.p1.status_light_g = g;
  49. m.p.p1.status_light_b = b;
  50. }
  51. void lcs_error_light__set_error(int errorNum) {}
  52. void lcs_error_light__clear_error(int errorNum) {}
  53. /***********************************************************************************************************************
  54. * =====================================================schedule====================================================== *
  55. ***********************************************************************************************************************/
  56. void lcs_schedule_process() {
  57. /**
  58. * @brief
  59. */
  60. if (m.nowpage == kworkPage) {
  61. if (m.p.p1.flash_triggered) {
  62. }
  63. }
  64. }
  65. void lcs_shcedule() {
  66. static uint32_t ticket = 0;
  67. if (systicket_haspassedms(ticket) > 30) {
  68. ticket = systicket_get_now_ms();
  69. lcs_schedule_process();
  70. }
  71. }
  72. #if 0
  73. #include "light.h"
  74. static bool s_interval_working_mode;
  75. static rgb_light_mode_t s_rgb_now_state;
  76. static rgb_light_mode_t s_rgb_light_mode_config;
  77. static int s_errornum = 0;
  78. static bool s_errorlight_display_state;
  79. static bool s_autoshutdown_light_state;
  80. /**
  81. * @brief ,
  82. * 绿
  83. */
  84. static void prv_light_module_set_rgb_mode(rgb_light_mode_t mode) {
  85. if (mode == krgb_color_red) {
  86. port_led_r_set(true);
  87. port_led_g_set(false);
  88. port_led_b_set(false);
  89. } else if (mode == krgb_color_blue) {
  90. port_led_r_set(false);
  91. port_led_g_set(false);
  92. port_led_b_set(true);
  93. } else if (mode == krgb_color_green) {
  94. port_led_r_set(false);
  95. port_led_b_set(false);
  96. port_led_g_set(true);
  97. } else if (mode == krgb_close) {
  98. port_led_r_set(false);
  99. port_led_g_set(false);
  100. port_led_b_set(false);
  101. }
  102. s_rgb_now_state = mode;
  103. }
  104. static void prv_set_timing_light_mode(int mode) {
  105. if (mode == 1) {
  106. port_led0_set(true);
  107. port_led1_set(false);
  108. port_led2_set(false);
  109. port_led3_set(false);
  110. } else if (mode == 2) {
  111. port_led0_set(true);
  112. port_led1_set(true);
  113. port_led2_set(false);
  114. port_led3_set(false);
  115. } else if (mode == 3) {
  116. port_led0_set(true);
  117. port_led1_set(true);
  118. port_led2_set(true);
  119. port_led3_set(false);
  120. } else if (mode == 4) {
  121. port_led0_set(true);
  122. port_led1_set(true);
  123. port_led2_set(true);
  124. port_led3_set(true);
  125. } else if (mode == 0) {
  126. port_led0_set(false);
  127. port_led1_set(false);
  128. port_led2_set(false);
  129. port_led3_set(false);
  130. }
  131. }
  132. void prv_light_module_rgb_light_control_schedule() {
  133. if (s_rgb_light_mode_config == krgb_close) {
  134. prv_light_module_set_rgb_mode(krgb_close);
  135. return;
  136. }
  137. if (!s_interval_working_mode) {
  138. prv_light_module_set_rgb_mode(s_rgb_light_mode_config);
  139. return;
  140. }
  141. /**
  142. * @brief
  143. */
  144. if (s_interval_working_mode) {
  145. if (hook_get_ozone_generator_working_flag()) {
  146. static uint32_t rgb_flicker_ticket = 0;
  147. static uint8_t rgb_ticket_count = 0;
  148. if (port_haspassedms(rgb_flicker_ticket) > 1000) {
  149. rgb_flicker_ticket = get_sys_ticket();
  150. if (s_rgb_now_state == krgb_close) {
  151. prv_light_module_set_rgb_mode(s_rgb_light_mode_config);
  152. } else {
  153. prv_light_module_set_rgb_mode(krgb_close);
  154. }
  155. }
  156. } else {
  157. prv_light_module_set_rgb_mode(krgb_color_green);
  158. }
  159. }
  160. }
  161. /**
  162. * @brief
  163. */
  164. static void prv_time_light_control_schedule() {
  165. if (s_autoshutdown_light_state) {
  166. /**
  167. * @brief
  168. */
  169. int lightnum = hook_get_autoshutdown_timecount() / AUTO_SHUTDOWN_ONE_LIGHT_EQ_TIME_S;
  170. int lightnum_remainder = hook_get_autoshutdown_timecount() % AUTO_SHUTDOWN_ONE_LIGHT_EQ_TIME_S;
  171. if (lightnum_remainder != 0) {
  172. lightnum += 1;
  173. }
  174. prv_set_timing_light_mode(lightnum);
  175. } else if (s_errorlight_display_state) {
  176. /**
  177. * @brief
  178. */
  179. static uint32_t ticket = 0;
  180. static bool state;
  181. if (port_haspassedms(ticket) > 300) {
  182. ticket = get_sys_ticket();
  183. state = !state;
  184. if (state) {
  185. prv_set_timing_light_mode(s_errornum);
  186. } else {
  187. prv_set_timing_light_mode(0);
  188. }
  189. }
  190. } else {
  191. prv_set_timing_light_mode(0);
  192. }
  193. }
  194. /***********************************************************************************************************************
  195. * ======================================================Extern======================================================= *
  196. ***********************************************************************************************************************/
  197. void light_module_set_rgb_mode(rgb_light_mode_t mode) {
  198. printf("light_module_set_rgb_mode %d\n", mode);
  199. s_rgb_light_mode_config = mode;
  200. prv_light_module_set_rgb_mode(mode);
  201. }
  202. void light_module_set_rgb_in_interval_working_mode(bool state) {
  203. printf("light_module_set_rgb_in_interval_working_mode %d\n", state);
  204. s_interval_working_mode = state;
  205. }
  206. void light_module_set_autoshutdown_indicator_light(bool open) { s_autoshutdown_light_state = open; }
  207. void light_module_set_error_light_mode(bool open, uint8_t error_mode) {
  208. printf("light_module_set_error_light_mode %d\n", error_mode);
  209. s_errorlight_display_state = open;
  210. s_errornum = error_mode;
  211. }
  212. void light_module_close_all_light(void) {
  213. printf("light_module_close_all_light\n");
  214. light_module_set_rgb_mode(krgb_close);
  215. light_module_set_autoshutdown_indicator_light(false);
  216. light_module_set_rgb_in_interval_working_mode(false);
  217. prv_set_timing_light_mode(0);
  218. s_errornum = 0;
  219. s_interval_working_mode = false;
  220. s_autoshutdown_light_state = false;
  221. s_errorlight_display_state = false;
  222. }
  223. void light_module_schedule(void) {
  224. prv_light_module_rgb_light_control_schedule();
  225. prv_time_light_control_schedule();
  226. }
  227. #endif