#include "light.h" static bool s_flicker; static rgb_light_mode_t s_rgb_now_state; static rgb_light_mode_t s_rgb_light_mode_config; static int s_errornum = 0; static bool s_errorlight_display_state; static bool s_autoshutdown_light_state; static timing_light_mode_t get_timing_light_mode_by_errornum(int errornum) { return (timing_light_mode_t)errornum; } /** * @brief 设置灯的模式,高低中分别亮不同颜色的灯 * 高档红色,中档蓝色,低档绿色 */ static void prv_light_module_set_rgb_mode(rgb_light_mode_t mode) { if (mode == RGB_COLOR_RED) { port_led_r_set(true); port_led_g_set(false); port_led_b_set(false); } else if (mode == RGB_COLOR_BLUE) { port_led_r_set(false); port_led_g_set(false); port_led_b_set(true); } else if (mode == RGB_COLOR_GERRN) { port_led_r_set(false); port_led_g_set(true); port_led_b_set(false); } else if (mode == RGB_CLOSE) { port_led_r_set(false); port_led_g_set(false); port_led_b_set(false); } s_rgb_now_state = mode; } static void prv_set_timing_light_mode(timing_light_mode_t mode) { if (mode == OPEN_ONE_LED) { port_led0_set(true); port_led1_set(false); port_led2_set(false); port_led3_set(false); } else if (mode == OPEN_TWO_LED) { port_led0_set(true); port_led1_set(true); port_led2_set(false); port_led3_set(false); } else if (mode == OPEN_THREE_LED) { port_led0_set(true); port_led1_set(true); port_led2_set(true); port_led3_set(false); } else if (mode == OPEN_FOUR_LED) { port_led0_set(true); port_led1_set(true); port_led2_set(true); port_led3_set(true); } else if (mode == CLOSE_ALL_LED) { port_led0_set(false); port_led1_set(false); port_led2_set(false); port_led3_set(false); } } void prv_light_module_rgb_light_control_schedule() { if (s_rgb_light_mode_config == RGB_CLOSE) { prv_light_module_set_rgb_mode(RGB_CLOSE); return; } if (!s_flicker) { prv_light_module_set_rgb_mode(s_rgb_light_mode_config); return; } /** * @brief 闪烁效果 */ if (s_flicker) { static uint32_t rgb_flicker_ticket = 0; static uint8_t rgb_ticket_count = 0; if (port_haspassedms(rgb_flicker_ticket) > 1000) { rgb_flicker_ticket = get_sys_ticket(); if (s_rgb_now_state == RGB_CLOSE) { prv_light_module_set_rgb_mode(s_rgb_light_mode_config); } else { prv_light_module_set_rgb_mode(RGB_CLOSE); } } } } /** * @brief 倒计时指示灯状态控制 */ static void prv_time_light_control_schedule() { if (s_autoshutdown_light_state) { /** * @brief 显示自动关机倒计时指示灯 */ int lightnum = hook_get_autoshutdown_timecount() / AUTO_SHUTDOWN_ONE_LIGHT_EQ_TIME_S; int lightnum_remainder = hook_get_autoshutdown_timecount() % AUTO_SHUTDOWN_ONE_LIGHT_EQ_TIME_S; if (lightnum_remainder != 0) { lightnum += 1; } prv_set_timing_light_mode( // get_timing_light_mode_by_lightnum(lightnum)); } else if (s_errorlight_display_state) { /** * @brief 显示异常指示灯 */ static uint32_t ticket = 0; static bool state; if (port_haspassedms(ticket) > 300) { ticket = get_sys_ticket(); state = !state; if (state) { prv_set_timing_light_mode(get_timing_light_mode_by_errornum(s_errornum)); } else { prv_set_timing_light_mode(CLOSE_ALL_LED); } } } } /*********************************************************************************************************************** * ======================================================Extern======================================================= * ***********************************************************************************************************************/ void light_module_set_rgb_mode(rgb_light_mode_t mode) { printf("light_module_set_rgb_mode %d\n", mode); s_rgb_light_mode_config = RGB_COLOR_BLUE; prv_light_module_set_rgb_mode(mode); } void light_module_set_rgb_flicker_mode(bool state) { printf("light_module_set_rgb_flicker_mode %d\n", state); s_flicker = state; } void light_module_set_autoshutdown_indicator_light(bool open) { s_autoshutdown_light_state = open; } void light_module_set_error_light_mode(bool open, uint8_t error_mode) { printf("light_module_set_error_light_mode %d\n", error_mode); s_errorlight_display_state = open; s_errornum = error_mode; } void light_module_close_all_light(void) { printf("light_module_close_all_light\n"); light_module_set_rgb_mode(RGB_CLOSE); light_module_set_autoshutdown_indicator_light(false); light_module_set_rgb_flicker_mode(false); s_errornum = 0; s_flicker = false; s_autoshutdown_light_state = false; s_errorlight_display_state = false; } void light_module_schedule(void) { prv_light_module_rgb_light_control_schedule(); prv_time_light_control_schedule(); }