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.8 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
  1. #include "light.h"
  2. static bool s_flicker;
  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. static timing_light_mode_t get_timing_light_mode_by_errornum(int errornum) { return (timing_light_mode_t)errornum; }
  9. /**
  10. * @brief ,
  11. * 绿
  12. */
  13. static void prv_light_module_set_rgb_mode(rgb_light_mode_t mode) {
  14. if (mode == RGB_COLOR_RED) {
  15. port_led_r_set(true);
  16. port_led_g_set(false);
  17. port_led_b_set(false);
  18. } else if (mode == RGB_COLOR_BLUE) {
  19. port_led_r_set(false);
  20. port_led_g_set(false);
  21. port_led_b_set(true);
  22. } else if (mode == RGB_COLOR_GERRN) {
  23. port_led_r_set(false);
  24. port_led_g_set(true);
  25. port_led_b_set(false);
  26. } else if (mode == RGB_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(timing_light_mode_t mode) {
  34. if (mode == OPEN_ONE_LED) {
  35. port_led0_set(true);
  36. port_led1_set(false);
  37. port_led2_set(false);
  38. port_led3_set(false);
  39. } else if (mode == OPEN_TWO_LED) {
  40. port_led0_set(true);
  41. port_led1_set(true);
  42. port_led2_set(false);
  43. port_led3_set(false);
  44. } else if (mode == OPEN_THREE_LED) {
  45. port_led0_set(true);
  46. port_led1_set(true);
  47. port_led2_set(true);
  48. port_led3_set(false);
  49. } else if (mode == OPEN_FOUR_LED) {
  50. port_led0_set(true);
  51. port_led1_set(true);
  52. port_led2_set(true);
  53. port_led3_set(true);
  54. } else if (mode == CLOSE_ALL_LED) {
  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 == RGB_CLOSE) {
  63. prv_light_module_set_rgb_mode(RGB_CLOSE);
  64. return;
  65. }
  66. if (!s_flicker) {
  67. prv_light_module_set_rgb_mode(s_rgb_light_mode_config);
  68. return;
  69. }
  70. /**
  71. * @brief
  72. */
  73. if (s_flicker) {
  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 == RGB_CLOSE) {
  79. prv_light_module_set_rgb_mode(s_rgb_light_mode_config);
  80. } else {
  81. prv_light_module_set_rgb_mode(RGB_CLOSE);
  82. }
  83. }
  84. }
  85. }
  86. /**
  87. * @brief
  88. */
  89. static void prv_time_light_control_schedule() {
  90. if (s_autoshutdown_light_state) {
  91. /**
  92. * @brief
  93. */
  94. int lightnum = hook_get_autoshutdown_timecount() / AUTO_SHUTDOWN_ONE_LIGHT_EQ_TIME_S;
  95. prv_set_timing_light_mode( //
  96. get_timing_light_mode_by_lightnum(lightnum));
  97. } else if (s_errorlight_display_state) {
  98. /**
  99. * @brief
  100. */
  101. static uint32_t ticket = 0;
  102. static bool state;
  103. if (port_haspassedms(ticket) > 300) {
  104. ticket = get_sys_ticket();
  105. state = !state;
  106. if (state) {
  107. prv_set_timing_light_mode(get_timing_light_mode_by_errornum(s_errornum));
  108. } else {
  109. prv_set_timing_light_mode(CLOSE_ALL_LED);
  110. }
  111. }
  112. }
  113. }
  114. /***********************************************************************************************************************
  115. * ======================================================Extern======================================================= *
  116. ***********************************************************************************************************************/
  117. void light_module_set_rgb_mode(rgb_light_mode_t mode) {
  118. printf("light_module_set_rgb_mode %d\n", mode);
  119. s_rgb_light_mode_config = RGB_COLOR_BLUE;
  120. prv_light_module_set_rgb_mode(mode);
  121. }
  122. void light_module_set_rgb_flicker_mode(bool state) {
  123. printf("light_module_set_rgb_flicker_mode %d\n", state);
  124. s_flicker = state;
  125. }
  126. void light_module_set_autoshutdown_indicator_light(bool open) { s_autoshutdown_light_state = open; }
  127. void light_module_set_error_light_mode(bool open, uint8_t error_mode) {
  128. printf("light_module_set_error_light_mode %d\n", error_mode);
  129. s_errorlight_display_state = open;
  130. s_errornum = error_mode;
  131. }
  132. void light_module_close_all_light(void) {
  133. printf("light_module_close_all_light\n");
  134. light_module_set_rgb_mode(RGB_CLOSE);
  135. light_module_set_timing_light_mode(CLOSE_ALL_LED);
  136. light_module_set_rgb_flicker_mode(false);
  137. s_errornum = 0;
  138. s_flicker = false;
  139. s_autoshutdown_light_state = false;
  140. s_errorlight_display_state = false;
  141. }
  142. void light_module_schedule(void) {
  143. prv_light_module_rgb_light_control_schedule();
  144. prv_time_light_control_schedule();
  145. }