修复切模式闪完多一闪,以及配对失败灯因休眠又慢又少。

切模式/配对快闪用优先级拦住待机绿,闪完同一拍衔上常亮;短灯效播完前禁睡,避免节拍被拉长。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-10 14:16:42 +08:00
co-authored by Cursor
parent c141c7e0aa
commit c7adda3711
4 changed files with 46 additions and 26 deletions
+23 -15
View File
@@ -2,8 +2,8 @@
* @file app_led.c
* @brief CBC2 灯效适配:充电红与待机绿可同时亮,不再 if-else 互斥
* @author cyWu <1917507415@qq.com>
* @date 2026.08.25
* @version V2.0.0
* @date 2026.09.10
* @version V2.5.0
* @history
* - V1.0.0, 2026.08.21, cyWu, 首次发布
* - V1.1.0, 2026.08.25, cyWu, 开机绿灯只提示几秒
@@ -12,6 +12,7 @@
* - V2.2.0, 2026.08.25, cyWu, 重启/清场逻辑各提一个小函数,把意图写进注释
* - V2.3.0, 2026.08.27, cyWu, 新增 OTA 红绿交替灯效
* - V2.4.0, 2026.08.27, cyWu, 新增空电关机红闪 5 下灯效
* - V2.5.0, 2026.09.10, cyWu, 切模式时保留待机绿,闪完不再多一闪
******************************************************************************/
#include "app_led.h"
@@ -53,15 +54,6 @@ static uint8_t green_pattern_busy(void)
|| LED_IsEventExist(LED_EVENT_PAIR_FAIL));
}
/**
* @brief 绿灯正被配对/切模式/结果占用时,不要再挂待机绿
* @return 1=绿灯忙
*/
static uint8_t green_busy(void)
{
return (uint8_t)(LED_IsEventExist(LED_EVENT_PAIRING) || green_pattern_busy());
}
/**
* @brief 灯效初始化
* @return APP_LED_OK=成功
@@ -157,6 +149,20 @@ uint8_t app_led_is_empty_off(void)
return s_empty_off;
}
/**
* @brief 短灯效还在播时不要进休眠
* @return 1=应禁睡,0=可以睡
*/
uint8_t app_led_need_nosleep(void)
{
if (s_ota || s_empty_off) {
return 1;
}
return (uint8_t)(LED_IsEventExist(LED_EVENT_PAIR_FAIL)
|| LED_IsEventExist(LED_EVENT_PAIR_OK)
|| LED_IsEventExist(LED_EVENT_MODE));
}
/**
* @brief 播放一次性配对结果灯
* @param ok 1=成功常绿,0=失败红绿交替
@@ -263,11 +269,13 @@ void app_led_run(uint16_t dt, uint8_t app_power)
led_clear_function_events();
} else {
#if BOARD_LED_STANDBY_ON
/* 正在充电(红)或已充满(绿)时都不叠加待机绿,只有完全没接电才显示待机 */
if ((charge_led == 0) && !pairing && !green_busy()) {
LED_EventAdd(LED_EVENT_STANDBY);
} else {
/* 配对/切模式/配对失败用 return 1 拦住待机,这里不用删。
* 充电红不占用绿灯:拦截只是不跑待机 handler,绿灯会停在上次的亮。
* 所以充电时要删待机,把绿灯掐灭。 */
if (charge_led == 1) {
LED_EventDelete(LED_EVENT_STANDBY);
} else {
LED_EventAdd(LED_EVENT_STANDBY);
}
#endif
}