1. 新增单双色温的支持 =》 已测试
2. 新增离家模式的支持 => 等待测试
This commit is contained in:
@ -11,9 +11,17 @@ typedef enum elightMode {
|
||||
LIGHT_MODE_HOME, // 回家模式
|
||||
LIGHT_MODE_WINTER, // 冬天模式
|
||||
LIGHT_MODE_SUMMER, // 夏天模式
|
||||
LIGHT_MODE_LEAVE, // 离家模式
|
||||
LIGHT_MODE_MAX // 模式数量
|
||||
} lightMode_e;
|
||||
|
||||
// 位掩码定义
|
||||
#define LIGHT_MODE_LEAVE_BIT (1 << 7) // 离家模式位
|
||||
#define LIGHT_MODE_MASK (0x7F) // 基础模式掩码(7位)
|
||||
#define LIGHT_MODE_IS_LEAVE(mode) ((mode) & LIGHT_MODE_LEAVE_BIT)
|
||||
#define LIGHT_MODE_GET_BASE(mode) ((mode) & LIGHT_MODE_MASK)
|
||||
#define LIGHT_MODE_SET_LEAVE(base_mode) ((base_mode) | LIGHT_MODE_LEAVE_BIT)
|
||||
|
||||
typedef enum {
|
||||
INIT_POWER_ON,
|
||||
NET_CONFIGING,
|
||||
@ -27,6 +35,7 @@ typedef enum {
|
||||
#define SVC_ID_CCT "cct" // 色温控制
|
||||
#define SVC_ID_LIGHT_MODE "lightMode" // 场景模式控制
|
||||
#define SVC_ID_FADE_TIME "progressSwitch" // 渐变时长的控制
|
||||
#define SVC_ID_COLOUR_MODE "colourMode" // 色温模式控制
|
||||
|
||||
// JSON字段名定义
|
||||
#define JSON_FIELD_ON "on" // 开关状态字段
|
||||
@ -34,6 +43,7 @@ typedef enum {
|
||||
#define JSON_FIELD_CCT "colorTemperature" // 色温字段
|
||||
#define JSON_FIELD_MODE "mode" // 场景模式字段
|
||||
#define JSON_FIELD_FADE_TIME "fadeTime" // 渐变时长字段
|
||||
#define JSON_FIELD_COLOUR_MODE "mode" // 色温模式字段
|
||||
|
||||
typedef enum {
|
||||
REPORT_SWITCH = 1 << 0,
|
||||
@ -41,8 +51,16 @@ typedef enum {
|
||||
REPORT_CCT = 1 << 2,
|
||||
REPORT_LIGHT_MODE = 1 << 3,
|
||||
REPORT_FADE_TIME = 1 << 4,
|
||||
REPORT_ALL = REPORT_SWITCH | REPORT_BRIGHTNESS | REPORT_CCT | REPORT_LIGHT_MODE | REPORT_FADE_TIME,
|
||||
REPORT_COLOUR_MODE = 1 << 5,
|
||||
REPORT_ALL = REPORT_SWITCH | REPORT_BRIGHTNESS | REPORT_CCT | REPORT_LIGHT_MODE | REPORT_FADE_TIME | REPORT_COLOUR_MODE,
|
||||
} report_mask_e;
|
||||
|
||||
// 色温模式定义
|
||||
typedef enum {
|
||||
COLOUR_MODE_SINGLE = 0, // 单色温模式
|
||||
COLOUR_MODE_DUAL = 1, // 双色温模式
|
||||
} colourMode_e;
|
||||
|
||||
// 当前亮度和色温状态
|
||||
typedef struct __attribute__((packed, aligned(1))) {
|
||||
// 物模型同步需要 持久化维持
|
||||
@ -51,10 +69,13 @@ typedef struct __attribute__((packed, aligned(1))) {
|
||||
uint16_t brightness_local; // 当前亮度 (0-1000)
|
||||
uint16_t fade_time; // 渐变时长(s)
|
||||
uint16_t cct_local; // 当前色温 (2700-6500)
|
||||
uint8_t colourMode; // 色温模式 (0:单色温, 1:双色温)
|
||||
// 持久化维持
|
||||
int32_t power_on_cnt; // 上电次数计数
|
||||
uint8_t is_networked; // 是否已配网
|
||||
uint8_t is_net_configured; // 设备是否曾经配网成功过
|
||||
|
||||
uint32_t reserve[10]; // 保留字段
|
||||
//运行时的数据
|
||||
uint16_t duty_cw; // 冷白LED占空比
|
||||
uint16_t duty_ww; // 暖白LED占空比
|
||||
@ -165,6 +186,20 @@ typedef enum {
|
||||
DEV_POWER_ON,
|
||||
} light_ctrl_source_e;
|
||||
|
||||
// 单色温模式的固定色温值
|
||||
#define SINGLE_COLOUR_CCT 6000 // 单色温模式固定色温 6000K
|
||||
#define SINGLE_COLOUR_CCT_LOCAL CCT_REMOTE2LOCAL(SINGLE_COLOUR_CCT) // 转换为本地值
|
||||
|
||||
#define BRIGHTNESS_PIN GPIO_04 // 冷白LED (CW)
|
||||
#define CCT_PIN GPIO_00 // 暖白LED (WW)
|
||||
#define SWITCH_PIN GPIO_13
|
||||
|
||||
#define CONFIG_PWM_GROUP_ID 2
|
||||
|
||||
#define OPEN_LIGHT GPIO_LEVEL_HIGH
|
||||
#define CLOSE_LIGHT GPIO_LEVEL_LOW
|
||||
|
||||
|
||||
#define DEFAULT_DEVICE_DATA { \
|
||||
.read_done = false, \
|
||||
.on = true, \
|
||||
@ -172,6 +207,7 @@ typedef enum {
|
||||
.cct_local = CCT_REMOTE2LOCAL(INIT_STA__CCT), \
|
||||
.brightness_local = BRIGHTNESS_REMOTE2LOCAL(INIT_STA__BRIGHTNESS), \
|
||||
.fade_time = NET_CFG_DEFAULT_FADE_TIME, \
|
||||
.colourMode = COLOUR_MODE_DUAL, \
|
||||
.is_networked = false, \
|
||||
.is_net_configured = false, \
|
||||
.duty_cw = 0, \
|
||||
@ -184,6 +220,9 @@ int set_light(light_ctrl_source_e source,
|
||||
int set_smooth_time(uint32_t smooth_time); // 设置渐变时长
|
||||
void update_pwm_output(bool on_state, uint16_t duty_cw, uint16_t duty_ww);
|
||||
|
||||
// 模式转换函数
|
||||
lightMode_e convert_mode_for_report(lightMode_e current_mode); // 将bitmask转换为上报用的枚举值
|
||||
|
||||
void stop_net_config(void);
|
||||
extern int fast_report(const char* svc_id);
|
||||
|
||||
|
Reference in New Issue
Block a user