喷淋器 P0 功能实现
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
/******************************************************************************
|
||||
* @file led.h
|
||||
* @brief LED 事件框架:按通道掩码独立开关,红绿可同时亮
|
||||
* @author cyWu <1917507415@qq.com>
|
||||
* @date 2026.09.09
|
||||
* @version V1.0.0
|
||||
* @history
|
||||
* - V1.0.0, 2026.09.09, cyWu, CBR2 独立通道版:绿=喷淋作业,红=配对态,
|
||||
* 两路互不关闭(区别于加热垫互斥灯)
|
||||
******************************************************************************/
|
||||
|
||||
#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;
|
||||
|
||||
/* 事件枚举数值 = 事件表下标(led.c LED_EventDelete 依赖),追加事件只能插尾部 */
|
||||
typedef enum {
|
||||
LED_EVENT_NONE = 0,
|
||||
LED_EVENT_GRN_IDLE, /**< 绿灯常亮:空闲(DP1=0) */
|
||||
LED_EVENT_GRN_SPRAY, /**< 绿灯闪:作业中(含间隔等待,DP1=1) */
|
||||
LED_EVENT_RED_PAIRED, /**< 红灯常亮:已配对(粘住,空闲/喷淋都不关) */
|
||||
LED_EVENT_RED_PAIRING, /**< 红灯快闪:配网键满 5s 提示 / 配对进行中 */
|
||||
LED_EVENT_PAIR_FAIL, /**< 配对失败:红绿交替 3s(临时占双灯,自删) */
|
||||
LED_EVENT_OTA, /**< OTA:红绿交替,直到升级结束/复位(最高) */
|
||||
LED_EVENT_MAX
|
||||
} LED_Event_t;
|
||||
|
||||
/**
|
||||
* 优先级:高者覆盖低者(handler 返回 1 会拦下更低优先级)。
|
||||
* 红绿独立通道:绿灯(作业)占 PRIORITY_1、红灯(配对)占 PRIORITY_2,
|
||||
* 红灯 handler 返回 0 放行绿灯;只有 OTA / 配对失败临时占双灯(返回 1)。
|
||||
*/
|
||||
typedef enum {
|
||||
PRIORITY_1 = 0, /**< 绿灯通道:作业态(空闲常亮 / 作业闪) */
|
||||
PRIORITY_2, /**< 红灯通道:配对态(已配常亮 / 配网快闪) */
|
||||
PRIORITY_3, /**< 配对失败动画(红绿交替,临时占双灯) */
|
||||
PRIORITY_4, /**< 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