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.

102 lines
3.3 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
  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) > 300) {
  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 do_level_light_flash() {
  39. //只有最后一个定时指示灯闪烁效果
  40. static uint32_t lastticket = 0;
  41. static bool statenow;
  42. if (systicket_haspassedms(lastticket) > 300) {
  43. lastticket = systicket_get_now_ms();
  44. statenow = !statenow;
  45. if (statenow) {
  46. mf_set_status_light_by_level(thisDevice.level);
  47. } else {
  48. mf_set_status_light_state(/*rgb:*/ 0, 0, 0);
  49. }
  50. }
  51. }
  52. void lcs_schedule_process() {
  53. /**
  54. * @brief
  55. */
  56. if (thisDevice.active_input != knone_active && systicket_haspassedms(thisDevice.active_start_ticket) >= 3000) {
  57. thisDevice.active_input = knone_active;
  58. }
  59. /**
  60. * @brief
  61. *
  62. *
  63. *
  64. *
  65. */
  66. if (thisDevice.active_input == kchange_countdonw_time_input || //
  67. thisDevice.active_input == kchange_intermittentmode_time_input) {
  68. do_countdown_flash_light_effect();
  69. } else {
  70. port_led0_set(thisDevice.countdonwnum > 0);
  71. port_led1_set(thisDevice.countdonwnum > 1);
  72. port_led2_set(thisDevice.countdonwnum > 2);
  73. port_led3_set(thisDevice.countdonwnum > 3);
  74. }
  75. /**
  76. * @brief
  77. *
  78. *
  79. * 绿
  80. *
  81. */
  82. if (thisDevice.active_input == kchange_level_input) {
  83. } else {
  84. if (thisDevice.mode == kintermittentMode && thisDevice.intermittentMode_idle) {
  85. mf_set_status_light_state(/*rgb:*/ 0, 1, 0);
  86. } else {
  87. mf_set_status_light_by_level(thisDevice.level);
  88. }
  89. }
  90. }
  91. void lcs_shcedule() {
  92. static uint32_t ticket = 0;
  93. if (systicket_haspassedms(ticket) > 30) {
  94. ticket = systicket_get_now_ms();
  95. lcs_schedule_process();
  96. }
  97. }