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.

168 lines
4.4 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
  1. #include "light.h"
  2. rgb_message_t rgb_message;
  3. TIMING_MODE_T timing_mode;
  4. timing_message_t timing_message;
  5. /**
  6. * @brief ,
  7. * 绿
  8. */
  9. void light_module_set_rgb_mode(RGB_MODE_T mode) {
  10. if (mode == RGB_COLOR_RED) {
  11. port_led_r_set(true);
  12. port_led_g_set(false);
  13. port_led_b_set(false);
  14. rgb_message.turn_off_the_mode_before_rgb = RGB_COLOR_RED;
  15. } else if (mode == RGB_COLOR_BLUE) {
  16. port_led_r_set(false);
  17. port_led_g_set(false);
  18. port_led_b_set(true);
  19. rgb_message.turn_off_the_mode_before_rgb = RGB_COLOR_BLUE;
  20. } else if (mode == RGB_COLOR_GERRN) {
  21. port_led_r_set(false);
  22. port_led_g_set(true);
  23. port_led_b_set(false);
  24. rgb_message.turn_off_the_mode_before_rgb = RGB_COLOR_GERRN;
  25. } else if (mode == RGB_CLOSE) {
  26. // rgb_message.turn_off_the_mode_before_rgb = RGB_CLOSE;
  27. port_led_r_set(false);
  28. port_led_g_set(false);
  29. port_led_b_set(false);
  30. }
  31. }
  32. /**
  33. * @brief rgb闪烁或者不闪烁
  34. *
  35. * @param mode
  36. */
  37. void light_module_set_rgb_flicker_mode(bool state) {
  38. if (state == false) {
  39. rgb_message.rgb_flicker_mode = false;
  40. } else if (state == true) {
  41. rgb_message.rgb_flicker_mode = true;
  42. }
  43. }
  44. void process_rgb_flicker_mode() {
  45. static uint32_t rgb_flicker_ticket = 0;
  46. static uint8_t rgb_ticket_count = 0;
  47. if (port_haspassedms(rgb_flicker_ticket) > 1000) {
  48. rgb_flicker_ticket = get_sys_ticket();
  49. if (rgb_ticket_count < 3) {
  50. // turn_off_the_mode_before_rgb保存了关闭之前的RGB亮灯的模式
  51. light_module_set_rgb_mode(rgb_message.turn_off_the_mode_before_rgb);
  52. } else {
  53. light_module_set_rgb_mode(RGB_CLOSE);
  54. rgb_ticket_count = 0;
  55. }
  56. rgb_ticket_count++;
  57. }
  58. }
  59. /**
  60. * @brief 30min 60min 90min 120min分别打开led3 led2 led1 led0灯
  61. *
  62. * @param mode
  63. */
  64. void light_module_set_timing_light_mode(TIMING_MODE_T mode) {
  65. if (mode == OPEN_ONE_LED) {
  66. port_led0_set(true);
  67. port_led1_set(false);
  68. port_led2_set(false);
  69. port_led3_set(false);
  70. } else if (mode == OPEN_TWO_LED) {
  71. port_led0_set(true);
  72. port_led1_set(true);
  73. port_led2_set(false);
  74. port_led3_set(false);
  75. } else if (mode == OPEN_THREE_LED) {
  76. port_led0_set(true);
  77. port_led1_set(true);
  78. port_led2_set(true);
  79. port_led3_set(false);
  80. } else if (mode == OPEN_FOUR_LED) {
  81. port_led0_set(true);
  82. port_led1_set(true);
  83. port_led2_set(true);
  84. port_led3_set(true);
  85. } else if (mode == CLOSE_ALL_LED) {
  86. port_led0_set(false);
  87. port_led1_set(false);
  88. port_led2_set(false);
  89. port_led3_set(false);
  90. }
  91. timing_message.now_timing_mode = mode;
  92. }
  93. /**
  94. * @brief rgbled0~led3
  95. *
  96. */
  97. void light_module_close_all_light(void) {
  98. light_module_set_rgb_mode(RGB_CLOSE);
  99. light_module_set_timing_light_mode(CLOSE_ALL_LED);
  100. light_module_set_rgb_flicker_mode(false);
  101. }
  102. /**
  103. * @brief RGB的亮灭
  104. *
  105. */
  106. void test_set_rgb_mode(void) {
  107. printf("try_test_set_rgb_mode\r\n");
  108. static int i = 0;
  109. if (i == 0) {
  110. i = 1;
  111. light_module_set_rgb_mode(RGB_COLOR_RED);
  112. } else if (i == 1) {
  113. i = 2;
  114. light_module_set_rgb_mode(RGB_COLOR_BLUE);
  115. } else if (i == 2) {
  116. i = 3;
  117. light_module_set_rgb_mode(RGB_COLOR_GERRN);
  118. } else if (i == 3) {
  119. i = 0;
  120. light_module_set_rgb_mode(RGB_CLOSE);
  121. }
  122. }
  123. /**
  124. * @brief led0~led3的亮灭
  125. *
  126. */
  127. void test_set_led_mode(void) {
  128. printf("try_test_set_led_mode\r\n");
  129. static int j = 0;
  130. if (j == 0) {
  131. j = 1;
  132. light_module_set_timing_light_mode(OPEN_ONE_LED);
  133. } else if (j == 1) {
  134. j = 2;
  135. light_module_set_timing_light_mode(OPEN_TWO_LED);
  136. } else if (j == 2) {
  137. j = 3;
  138. light_module_set_timing_light_mode(OPEN_THREE_LED);
  139. } else if (j == 3) {
  140. j = 4;
  141. light_module_set_timing_light_mode(OPEN_FOUR_LED);
  142. } else if (j == 4) {
  143. j = 0;
  144. light_module_set_timing_light_mode(CLOSE_ALL_LED);
  145. }
  146. }
  147. /**
  148. * @brief rgb闪烁或者不闪烁
  149. *
  150. */
  151. void test_set_rgb_flicker_mode(void) {
  152. printf("test_light_module_set_rgb_flicker_mode\r\n");
  153. static bool m = false;
  154. if (m == 0) {
  155. light_module_set_rgb_flicker_mode(true);
  156. } else if (m == 1) {
  157. light_module_set_rgb_flicker_mode(false);
  158. }
  159. m = !m;
  160. }