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.

121 lines
3.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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. #include "light_control_service.h"
  2. #include "port.h"
  3. #include "zes8p5066lib/systicket.h"
  4. #include "zsimple_timer/zsimple_timer.h"
  5. void lcs_active_input(active_input_t input) {
  6. thisDevice.active_start_ticket = systicket_get_now_ms();
  7. thisDevice.active_input = input;
  8. }
  9. bool lcs_input_is_active(active_input_t input) { return (thisDevice.active_input == input); }
  10. /***********************************************************************************************************************
  11. * =====================================================schedule====================================================== *
  12. ***********************************************************************************************************************/
  13. void mf_set_status_light_state(bool r, bool g, bool b) {
  14. port_led_r_set(r);
  15. port_led_g_set(g);
  16. port_led_b_set(b);
  17. }
  18. static void mf_set_status_light_by_level(level_t level) {
  19. if (level == klevel1) {
  20. mf_set_status_light_state(/*rgb:*/ 1, 0, 0);
  21. } else if (level == klevel2) {
  22. mf_set_status_light_state(/*rgb:*/ 0, 0, 1);
  23. }
  24. }
  25. void do_countdown_flash_light_effect() {
  26. //所有定时指示灯闪烁效果
  27. static uint32_t lastticket = 0;
  28. static bool statenow;
  29. if (systicket_haspassedms(lastticket) > kconst_active_input_light_flick_interval_ms) {
  30. lastticket = systicket_get_now_ms();
  31. statenow = !statenow;
  32. port_led0_set(statenow && thisDevice.countdonwnum > 0);
  33. port_led1_set(statenow && thisDevice.countdonwnum > 1);
  34. port_led2_set(statenow && thisDevice.countdonwnum > 2);
  35. port_led3_set(statenow && thisDevice.countdonwnum > 3);
  36. }
  37. }
  38. void close_all_light() {
  39. port_led0_set(0);
  40. port_led1_set(0);
  41. port_led2_set(0);
  42. port_led3_set(0);
  43. mf_set_status_light_state(0, 0, 0);
  44. }
  45. void process_countdonwlight() {
  46. /**
  47. * @brief
  48. *
  49. *
  50. *
  51. *
  52. */
  53. if (thisDevice.active_input == kchange_countdonw_time_input || //
  54. thisDevice.active_input == kchange_intermittentmode_time_input) {
  55. do_countdown_flash_light_effect();
  56. } else {
  57. port_led0_set(thisDevice.countdonwnum > 0);
  58. port_led1_set(thisDevice.countdonwnum > 1);
  59. port_led2_set(thisDevice.countdonwnum > 2);
  60. port_led3_set(thisDevice.countdonwnum > 3);
  61. }
  62. }
  63. void process_level_light() {
  64. /**
  65. * @brief
  66. *
  67. *
  68. * 绿
  69. *
  70. */
  71. if (thisDevice.active_input == kchange_level_input) {
  72. /**
  73. * @brief
  74. */
  75. static uint32_t lastticket = 0;
  76. static bool statenow;
  77. if (systicket_haspassedms(lastticket) > kconst_active_input_light_flick_interval_ms) {
  78. lastticket = systicket_get_now_ms();
  79. statenow = !statenow;
  80. if (statenow) {
  81. mf_set_status_light_by_level(thisDevice.level);
  82. } else {
  83. mf_set_status_light_state(/*rgb:*/ 0, 0, 0);
  84. }
  85. }
  86. } else {
  87. if (thisDevice.mode == kintermittentMode && thisDevice.intermittentMode_idle) {
  88. mf_set_status_light_state(/*rgb:*/ 0, 1, 0);
  89. } else {
  90. mf_set_status_light_by_level(thisDevice.level);
  91. }
  92. }
  93. }
  94. void lcs_schedule_process() {
  95. if (!thisDevice.poweron) {
  96. close_all_light();
  97. return;
  98. }
  99. //自动失能active_input
  100. if (thisDevice.active_input != knone_active && systicket_haspassedms(thisDevice.active_start_ticket) >= kconst_flash_auto_close_time) {
  101. thisDevice.active_input = knone_active;
  102. }
  103. //控制定时指示灯
  104. process_countdonwlight();
  105. //控制等级指示灯
  106. process_level_light();
  107. }
  108. void lcs_shcedule() {
  109. static uint32_t ticket = 0;
  110. if (systicket_haspassedms(ticket) > 30) {
  111. ticket = systicket_get_now_ms();
  112. lcs_schedule_process();
  113. }
  114. }