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.

159 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
  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. int lightnum_remainder = hook_get_autoshutdown_timecount() % AUTO_SHUTDOWN_ONE_LIGHT_EQ_TIME_S;
  96. if (lightnum_remainder != 0) {
  97. lightnum += 1;
  98. }
  99. prv_set_timing_light_mode( //
  100. get_timing_light_mode_by_lightnum(lightnum));
  101. } else if (s_errorlight_display_state) {
  102. /**
  103. * @brief
  104. */
  105. static uint32_t ticket = 0;
  106. static bool state;
  107. if (port_haspassedms(ticket) > 300) {
  108. ticket = get_sys_ticket();
  109. state = !state;
  110. if (state) {
  111. prv_set_timing_light_mode(get_timing_light_mode_by_errornum(s_errornum));
  112. } else {
  113. prv_set_timing_light_mode(CLOSE_ALL_LED);
  114. }
  115. }
  116. }
  117. }
  118. /***********************************************************************************************************************
  119. * ======================================================Extern======================================================= *
  120. ***********************************************************************************************************************/
  121. void light_module_set_rgb_mode(rgb_light_mode_t mode) {
  122. printf("light_module_set_rgb_mode %d\n", mode);
  123. s_rgb_light_mode_config = RGB_COLOR_BLUE;
  124. prv_light_module_set_rgb_mode(mode);
  125. }
  126. void light_module_set_rgb_flicker_mode(bool state) {
  127. printf("light_module_set_rgb_flicker_mode %d\n", state);
  128. s_flicker = state;
  129. }
  130. void light_module_set_autoshutdown_indicator_light(bool open) { s_autoshutdown_light_state = open; }
  131. void light_module_set_error_light_mode(bool open, uint8_t error_mode) {
  132. printf("light_module_set_error_light_mode %d\n", error_mode);
  133. s_errorlight_display_state = open;
  134. s_errornum = error_mode;
  135. }
  136. void light_module_close_all_light(void) {
  137. printf("light_module_close_all_light\n");
  138. light_module_set_rgb_mode(RGB_CLOSE);
  139. light_module_set_timing_light_mode(CLOSE_ALL_LED);
  140. light_module_set_rgb_flicker_mode(false);
  141. s_errornum = 0;
  142. s_flicker = false;
  143. s_autoshutdown_light_state = false;
  144. s_errorlight_display_state = false;
  145. }
  146. void light_module_schedule(void) {
  147. prv_light_module_rgb_light_control_schedule();
  148. prv_time_light_control_schedule();
  149. }