P0/P1/P2功能实现:接入业务组合根(按键/LED/过零/配网/OTA),联动、11B定时、运行记录、灯泡寿命(DP3/DP4/DP25)、CBR0 VM、512分包
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
/******************************************************************************
|
||||
* @file led.h
|
||||
* @brief LED 事件框架:按通道掩码独立开关,红绿可同时亮
|
||||
* @author cyWu <1917507415@qq.com>
|
||||
* @date 2026.08.25
|
||||
* @version V1.1.0
|
||||
* @history
|
||||
* - V1.0.0, 2026.08.25, cyWu, 首次发布,实现按通道掩码独立开关的 LED 事件框架
|
||||
* - V1.1.0, 2026.08.27, cyWu, 新增 LED_EVENT_BOOT_REJECT(拒绝开机低电闪),
|
||||
* 与运行时 LED_EVENT_EMPTY 参数解耦,各自独立可调
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __LED_H__
|
||||
#define __LED_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
/*============================================================================*/
|
||||
/* 宏定义 */
|
||||
/*============================================================================*/
|
||||
|
||||
#define BLINK_ENABLE 1
|
||||
#define ALTERNATING_BLINK_ENABLE 1
|
||||
#define BREATH_ENABLE 0
|
||||
#define RUNNING_ENABLE 0
|
||||
#define MARQUEE_ENABLE 0
|
||||
|
||||
#define LED_ON 1
|
||||
#define LED_OFF 0
|
||||
|
||||
#define LED_CHANNEL(user_led) (1u << (user_led))
|
||||
|
||||
#define ledPrintf(level, fmt, ...) ((void)0)
|
||||
|
||||
/*============================================================================*/
|
||||
/* 类型 */
|
||||
/*============================================================================*/
|
||||
|
||||
typedef enum {
|
||||
LED_LIGHT = 0, /**< 常亮 */
|
||||
LED_BLINKING, /**< 闪烁 */
|
||||
LED_ALTERNATING_BLINK /**< 红绿交替 */
|
||||
} LED_State_t;
|
||||
|
||||
typedef enum {
|
||||
LED_EVENT_NONE = 0,
|
||||
LED_EVENT_HEAT_OFF, /**< 跟继电器-关:绿灯常亮,红灯灭(低优先级) */
|
||||
LED_EVENT_HEAT_ON, /**< 跟继电器-开:红灯常亮,绿灯灭(低优先级) */
|
||||
LED_EVENT_PAIRING, /**< 按住满5s提示/配对中:绿灯100ms快闪,红灯灭 */
|
||||
LED_EVENT_PAIR_OK, /**< 配对成功:绿灯常亮若干秒,再回跟继电器 */
|
||||
LED_EVENT_PAIR_FAIL, /**< 配对失败:红绿交替若干秒,再回跟继电器 */
|
||||
LED_EVENT_OTA, /**< OTA:红绿交替,直到升级结束/复位(最高) */
|
||||
LED_EVENT_MAX
|
||||
} LED_Event_t;
|
||||
|
||||
/**
|
||||
* 优先级:高者覆盖低者(handler 返回 1 会拦下更低优先级)。
|
||||
* 加热垫红绿互斥:HEAT 只占最低槽,配对/结果/OTA 事件添加前先全清灯,
|
||||
* 结束后 app_led_run 按继电器实际态自动重新挂 HEAT(无需显式恢复)。
|
||||
*/
|
||||
typedef enum {
|
||||
PRIORITY_1 = 0, /**< 跟继电器(HEAT_OFF / HEAT_ON) */
|
||||
PRIORITY_2, /**< 配对提示 / 配对结果 */
|
||||
PRIORITY_3, /**< OTA(最高) */
|
||||
PRIORITY_MAX
|
||||
} LED_EventPriority_t;
|
||||
|
||||
#if (BLINK_ENABLE)
|
||||
typedef struct {
|
||||
uint8_t orDer; /**< 1=先灭后亮,0=先亮后灭 */
|
||||
uint32_t onTime; /**< 亮时间 ms */
|
||||
uint32_t offTime; /**< 灭时间 ms */
|
||||
} LED_BlinkParams_t;
|
||||
#endif
|
||||
|
||||
#if (ALTERNATING_BLINK_ENABLE)
|
||||
#define ALTERNAT_GROUP 2
|
||||
typedef struct {
|
||||
uint16_t Group[ALTERNAT_GROUP]; /**< 交替两组的通道掩码 */
|
||||
uint32_t Cycle; /**< 一整轮交替周期 ms */
|
||||
} LED_AlternatingBlinkParams_t;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
LED_State_t state;
|
||||
uint16_t ledMask; /**< 本事件只动这些通道,其它灯不受影响 */
|
||||
uint16_t runNum; /**< 0=无限;常亮按秒计,闪烁按周期计 */
|
||||
uint32_t currentTime;
|
||||
#if (BLINK_ENABLE)
|
||||
LED_BlinkParams_t blinkParams;
|
||||
#endif
|
||||
#if (ALTERNATING_BLINK_ENABLE)
|
||||
LED_AlternatingBlinkParams_t alternatingBlinkParams;
|
||||
#endif
|
||||
} LED_Config_t;
|
||||
|
||||
typedef struct {
|
||||
LED_Event_t event;
|
||||
LED_EventPriority_t priority;
|
||||
LED_Config_t config;
|
||||
uint8_t (*ledEventHandler)(LED_Config_t *config);
|
||||
} LED_EventTableItem_t;
|
||||
|
||||
typedef void (*LED_SetState_t)(uint16_t led, uint8_t state);
|
||||
typedef uint32_t (*TIME_Get_t)(void);
|
||||
|
||||
/*============================================================================*/
|
||||
/* 外部接口 */
|
||||
/*============================================================================*/
|
||||
|
||||
void LED_SetStateInit(LED_SetState_t setState);
|
||||
void SET_TimeGetInit(TIME_Get_t getTime);
|
||||
void LED_EventTableInit(LED_EventTableItem_t ledEvent[]);
|
||||
void LED_EventAdd(LED_Event_t ledEvent);
|
||||
void LED_EventDelete(LED_Event_t ledEvent);
|
||||
void LED_EventAllDelete(void);
|
||||
void LED_EventHandle(void);
|
||||
uint8_t LED_IsEventActive(void);
|
||||
uint8_t LED_IsEventExist(LED_Event_t ledEvent);
|
||||
uint8_t LED_Update(LED_Config_t *led);
|
||||
|
||||
#endif /* __LED_H__ */
|
||||
Reference in New Issue
Block a user