1. 新增单双色温的支持 =》 已测试
2. 新增离家模式的支持 => 等待测试
This commit is contained in:
@ -30,7 +30,7 @@ extern "C" {
|
||||
|
||||
#define DEVICE_HIVERSION "1.0.0"
|
||||
/* 设备固件版本号 */
|
||||
#define FIRMWARE_VER "1.0.3"
|
||||
#define FIRMWARE_VER "1.0.4"
|
||||
/* 设备硬件版本号 */
|
||||
#define HARDWARE_VER "1.0.0"
|
||||
/* 设备软件版本号 */
|
||||
|
@ -24,11 +24,13 @@ extern int myhandle_put_cct(const char* svc_id, const char* payload, unsigned in
|
||||
extern int myhandle_put_lightMode(const char* svc_id, const char* payload, unsigned int len);
|
||||
extern int myhandle_put_switch(const char* svc_id, const char* payload, unsigned int len);
|
||||
extern int myhandle_put_progressSwitch(const char* svc_id, const char* payload, unsigned int len);
|
||||
extern int myhandle_put_colourMode(const char* svc_id, const char* payload, unsigned int len);
|
||||
extern int myhandle_get_brightness(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len);
|
||||
extern int myhandle_get_cct(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len);
|
||||
extern int myhandle_get_lightMode(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len);
|
||||
extern int myhandle_get_switch(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len);
|
||||
extern int myhandle_get_progressSwitch(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len);
|
||||
extern int myhandle_get_colourMode(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len);
|
||||
// 声明外部函数
|
||||
extern int myhandle_put_cmd(const char* svc_id, const char* payload, unsigned int len);
|
||||
extern int myhandle_get_cmd(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len);
|
||||
@ -42,9 +44,10 @@ extern int myhandle_get_cmd(const char* svc_id, const char* in, unsigned int in_
|
||||
static const HILINK_SvcInfo SVC_INFO[] = {
|
||||
{ "brightness", "brightness" },
|
||||
{ "cct", "cct" },
|
||||
{ "mode", "colourMode" },
|
||||
{ "mode", "lightMode" },
|
||||
{ "progressSwitch", "progressSwitch" },
|
||||
{ "switch", "switch" },
|
||||
{ "switch", "switch" }
|
||||
#ifdef CONFIG_SUPPORT_HILINK_INDIE_UPGRADE
|
||||
// { "checkSum", "checkSum" },
|
||||
#endif
|
||||
@ -145,6 +148,7 @@ int HILINK_GetSvcInfo(HILINK_SvcInfo *svcInfo[], unsigned int size)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
e_printf("HILINK_GetSvcInfo svcNum:%d\r\n", svcNum);
|
||||
return svcNum;
|
||||
}
|
||||
/* AC参数 */
|
||||
@ -166,6 +170,7 @@ extern int HILINK_HILINK_Printf(const char *format, ...);
|
||||
typedef struct{
|
||||
int brightness_brightness;
|
||||
int cct_colorTemperature;
|
||||
int colourMode_mode;
|
||||
int lightMode_mode;
|
||||
int progressSwitch_fadeTime;
|
||||
int switch_on;
|
||||
@ -218,7 +223,8 @@ int handle_get_switch(const char* svc_id, const char* in, unsigned int in_len,ch
|
||||
HILINK_Printf("%s:%d svcId:%s, *out:%s\r\n",__FUNCTION__ , __LINE__,svc_id, *out);
|
||||
return 0;
|
||||
}
|
||||
// 服务处理信息注册
|
||||
|
||||
#ifndef CONFIG_USE_CUSTOMER_SVC_INFO
|
||||
|
||||
int handle_put_brightness(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
@ -268,6 +274,30 @@ int handle_get_cct(const char* svc_id, const char* in, unsigned int in_len, char
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_put_colourMode(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
cJSON* pJson = cJSON_Parse(payload);
|
||||
if (!pJson)
|
||||
return -1;
|
||||
cJSON* mode_item = cJSON_GetObjectItem(pJson, "mode");
|
||||
if (mode_item)
|
||||
g_device_info.colourMode_mode = mode_item->valueint;
|
||||
HILINK_Printf("%s:%d svcId:%s, payload:%s\r\n", __FUNCTION__, __LINE__, svc_id, payload);
|
||||
cJSON_Delete(pJson);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_get_colourMode(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
*out_len = 64;
|
||||
*out = (char*)malloc(*out_len);
|
||||
if (*out == NULL)
|
||||
return -1;
|
||||
*out_len = sprintf_s(*out, *out_len, "{\"mode\":%d}", g_device_info.colourMode_mode);
|
||||
HILINK_Printf("%s:%d svcId:%s, *out:%s\r\n", __FUNCTION__, __LINE__, svc_id, *out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_put_lightMode(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
cJSON* pJson = cJSON_Parse(payload);
|
||||
@ -315,22 +345,23 @@ int handle_get_progressSwitch(const char* svc_id, const char* in, unsigned int i
|
||||
HILINK_Printf("%s:%d svcId:%s, *out:%s\r\n", __FUNCTION__, __LINE__, svc_id, *out);
|
||||
return 0;
|
||||
}
|
||||
#ifdef CONFIG_USE_CUSTOMER_SVC_INFO
|
||||
HANDLE_SVC_INFO g_device_profile[] = {
|
||||
{"brightness", myhandle_put_brightness, myhandle_get_brightness},
|
||||
{"cct", myhandle_put_cct, myhandle_get_cct},
|
||||
{"lightMode", myhandle_put_lightMode, myhandle_get_lightMode},
|
||||
{"progressSwitch", myhandle_put_progressSwitch, myhandle_get_progressSwitch},
|
||||
{"switch", myhandle_put_switch, myhandle_get_switch},
|
||||
};
|
||||
#else
|
||||
HANDLE_SVC_INFO g_device_profile[] = {
|
||||
{"brightness", handle_put_brightness, handle_get_brightness},
|
||||
{"cct", handle_put_cct, handle_get_cct},
|
||||
{"colourMode", handle_put_colourMode, handle_get_colourMode},
|
||||
{"lightMode", handle_put_lightMode, handle_get_lightMode},
|
||||
{"progressSwitch", handle_put_progressSwitch, handle_get_progressSwitch},
|
||||
{"switch", handle_put_switch, handle_get_switch},
|
||||
};
|
||||
#else
|
||||
HANDLE_SVC_INFO g_device_profile[] = {
|
||||
{"brightness", myhandle_put_brightness, myhandle_get_brightness},
|
||||
{"cct", myhandle_put_cct, myhandle_get_cct},
|
||||
{"colourMode", myhandle_put_colourMode, myhandle_get_colourMode},
|
||||
{"lightMode", myhandle_put_lightMode, myhandle_get_lightMode},
|
||||
{"progressSwitch", myhandle_put_progressSwitch, myhandle_get_progressSwitch},
|
||||
{"switch", myhandle_put_switch, myhandle_get_switch},
|
||||
};
|
||||
#endif // end of CONFIG_USE_CUSTOMER_SVC_INFO
|
||||
// 服务总数量
|
||||
int g_device_profile_count = sizeof(g_device_profile) / sizeof(HANDLE_SVC_INFO);
|
||||
@ -514,7 +545,7 @@ void HILINK_NotifyDevStatus(int status)
|
||||
/* 设备与云端连接断开,请在此处添加实现 */
|
||||
#if defined(SUPPORT_MINIMALIST_NETCFG) || defined(SUPPORT_BLE_ANCILLAY_NETCFG)
|
||||
BLE_CfgNetAdvUpdate(NULL);
|
||||
// BLE_CfgNetAdvCtrl(0);
|
||||
BLE_CfgNetAdvCtrl(0);
|
||||
(void)BLE_CfgNetAdvCtrl(0xFFFFFFFF);
|
||||
#endif
|
||||
handle_device_offline();
|
||||
@ -524,7 +555,7 @@ void HILINK_NotifyDevStatus(int status)
|
||||
#if defined(SUPPORT_MINIMALIST_NETCFG) || defined(SUPPORT_BLE_ANCILLAY_NETCFG)
|
||||
BLE_CfgNetAdvUpdate(NULL);
|
||||
BLE_CfgNetAdvCtrl(0);
|
||||
// (void)BLE_CfgNetAdvCtrl(0xFFFFFFFF);
|
||||
(void)BLE_CfgNetAdvCtrl(0xFFFFFFFF);
|
||||
#endif
|
||||
/* 设备连接云端成功,请在此处添加实现 */
|
||||
handle_device_online(); // 处理设备上线
|
||||
|
@ -22,6 +22,7 @@ static const scene_preset_t scene_presets[] = {
|
||||
{(80), (3500)}, // 模式4:回家模式 - 较高亮度,自然光
|
||||
{(100), (CCT_MIN)}, // 模式5:冬天模式 - 中等亮度,暖色调
|
||||
{(100), (CCT_MAX)}, // 模式6:夏天模式 - 较高亮度,冷色调
|
||||
{(0), (0)}, // 模式7 离家模式- 关闭
|
||||
};
|
||||
|
||||
#define SCENE_MODE_COUNT (sizeof(scene_presets) / sizeof(scene_presets[0]))
|
||||
@ -68,6 +69,13 @@ int myhandle_put_cct(const char* svc_id, const char* payload, unsigned int len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// // 在单色温模式下,不允许修改色温
|
||||
// if (g_device_control.colourMode == COLOUR_MODE_SINGLE) {
|
||||
// e_printf("Cannot change CCT in single colour mode\r\n");
|
||||
// cJSON_Delete(json);
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
int cct = item->valueint;
|
||||
if (cct < CCT_MIN) cct = CCT_MIN;
|
||||
if (cct > CCT_MAX) cct = CCT_MAX;
|
||||
@ -97,10 +105,15 @@ int myhandle_put_lightMode(const char* svc_id, const char* payload, unsigned int
|
||||
|
||||
uint16_t mode = item->valueint;
|
||||
if (mode >= 0 && mode < SCENE_MODE_COUNT) {
|
||||
g_device_control.elightMode = mode;
|
||||
|
||||
// 同时更新亮度和色温
|
||||
ret = set_light(APP_CHANGE_LIGHT_MODE, BRIGHTNESS_REMOTE2LOCAL(scene_presets[mode].brightness), CCT_REMOTE2LOCAL(scene_presets[mode].cct));
|
||||
// 如果切换到离家模式,设置bitmask并直接关灯
|
||||
if (mode == LIGHT_MODE_LEAVE) {
|
||||
g_device_control.elightMode = LIGHT_MODE_SET_LEAVE(LIGHT_MODE_GET_BASE(g_device_control.elightMode));
|
||||
ret = set_light(APP_CLOSE_LIGHT, -1, -1);
|
||||
} else {
|
||||
// 普通模式切换,清除离家模式位
|
||||
g_device_control.elightMode = mode;
|
||||
ret = set_light(APP_CHANGE_LIGHT_MODE, BRIGHTNESS_REMOTE2LOCAL(scene_presets[mode].brightness), CCT_REMOTE2LOCAL(scene_presets[mode].cct));
|
||||
}
|
||||
}
|
||||
|
||||
cJSON_Delete(json);
|
||||
@ -124,6 +137,12 @@ int myhandle_put_switch(const char* svc_id, const char* payload, unsigned int le
|
||||
|
||||
bool on = (item->valueint != 0);
|
||||
if (on) {
|
||||
// 如果当前是离家模式,取消离家模式并恢复到基础模式
|
||||
if (LIGHT_MODE_IS_LEAVE(g_device_control.elightMode)) {
|
||||
lightMode_e base_mode = LIGHT_MODE_GET_BASE(g_device_control.elightMode);
|
||||
g_device_control.elightMode = base_mode;
|
||||
e_printf("从离家模式恢复,基础模式:%d\r\n", base_mode);
|
||||
}
|
||||
ret = set_light(APP_OPEN_LIGHT, -1, -1);
|
||||
} else {
|
||||
ret = set_light(APP_CLOSE_LIGHT, -1, -1);
|
||||
@ -164,7 +183,9 @@ int myhandle_get_lightMode(const char* svc_id, const char* in, unsigned int in_l
|
||||
if (NULL == *out) {
|
||||
return -1;
|
||||
}
|
||||
*out_len = sprintf_s(*out, *out_len, "{\"%s\":%d}", JSON_FIELD_MODE, g_device_control.elightMode);
|
||||
// 使用转换函数确保上报正确的模式
|
||||
lightMode_e report_mode = convert_mode_for_report(g_device_control.elightMode);
|
||||
*out_len = sprintf_s(*out, *out_len, "{\"%s\":%d}", JSON_FIELD_MODE, report_mode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -219,3 +240,42 @@ int myhandle_get_progressSwitch(const char* svc_id, const char* in, unsigned int
|
||||
*out_len = sprintf_s(*out, *out_len, "{\"%s\":%d}", JSON_FIELD_FADE_TIME, g_device_control.fade_time);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 处理色温模式控制
|
||||
int myhandle_put_colourMode(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
int ret = -1;
|
||||
cJSON *json = cJSON_Parse(payload);
|
||||
if (json == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cJSON *item = cJSON_GetObjectItem(json, JSON_FIELD_COLOUR_MODE);
|
||||
if (item == NULL || !cJSON_IsNumber(item)) {
|
||||
cJSON_Delete(json);
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint8_t mode = item->valueint;
|
||||
g_device_control.colourMode = mode;
|
||||
if (mode == COLOUR_MODE_SINGLE) {
|
||||
ret = set_light(APP_CHANGE_LIGHT_BRIGHTNESS_CCT, -1, SINGLE_COLOUR_CCT_LOCAL);
|
||||
} else {
|
||||
ret = set_light(APP_CHANGE_LIGHT_BRIGHTNESS_CCT, g_device_control.brightness_local, g_device_control.cct_local);
|
||||
}
|
||||
|
||||
cJSON_Delete(json);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 获取色温模式状态
|
||||
int myhandle_get_colourMode(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
*out_len = 32;
|
||||
*out = (char*)malloc(*out_len);
|
||||
if (NULL == *out) {
|
||||
return -1;
|
||||
}
|
||||
*out_len = sprintf_s(*out, *out_len, "{\"%s\":%d}", JSON_FIELD_COLOUR_MODE, g_device_control.colourMode);
|
||||
return 0;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -41,15 +41,6 @@ static bool write_device_data_to_addr(uint32_t addr, const device_data_t* data);
|
||||
static void report_device_online_status(void);
|
||||
|
||||
|
||||
#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 REPORT_TASK_PRIO 80
|
||||
#define REPORT_TASK_STACK_SIZE 0x1000
|
||||
@ -256,7 +247,9 @@ static void *fade_task(const char *arg)
|
||||
g_device_control.duty_ww = device_control.duty_ww;
|
||||
g_device_control.duty_cw = device_control.duty_cw;
|
||||
g_device_control.brightness_local = fade_ctx.current_brightness;
|
||||
g_device_control.cct_local = fade_ctx.current_cct;
|
||||
if (g_device_control.colourMode == COLOUR_MODE_DUAL) {
|
||||
g_device_control.cct_local = fade_ctx.current_cct;
|
||||
}
|
||||
e_printf("[fade_task] Status report: local brightness=%d, CCT=%d\r\n",
|
||||
g_device_control.brightness_local,
|
||||
g_device_control.cct_local);
|
||||
@ -464,12 +457,12 @@ static void stop_breath_timer(void)
|
||||
stop_breath_task();
|
||||
}
|
||||
|
||||
// 计算PWM占空比
|
||||
// 计算PWM占空比
|
||||
void calculate_pwm_duty(device_control_t* pdevice_control)
|
||||
{ // 如果开关关闭,则占空比为0
|
||||
uint32_t total_brightness_pwm = pdevice_control->brightness_local;
|
||||
// 计算色温比例 (0-10000)
|
||||
uint16_t cct_ratio = ((pdevice_control->cct_local - CCT_LOCAL_MIN) * 10000) / CCT_RANGE;
|
||||
uint32_t cct_ratio = ((pdevice_control->cct_local - CCT_LOCAL_MIN) * 10000) / CCT_RANGE;
|
||||
|
||||
// 根据色温比例计算CW和WW的占空比
|
||||
// 总亮度保持不变,只调整CW和WW的比例
|
||||
@ -716,12 +709,16 @@ void read_device_data(void)
|
||||
e_printf("灯光模式: %d => %d\r\n", g_device_control.elightMode, data.control.elightMode);
|
||||
e_printf("亮度: %d => %d\r\n", g_device_control.brightness_local, data.control.brightness_local);
|
||||
e_printf("色温: %d => %d\r\n", g_device_control.cct_local, data.control.cct_local);
|
||||
e_printf("色温模式: %d => %d\r\n", g_device_control.colourMode, data.control.colourMode);
|
||||
e_printf("冷白LED: %d => %d\r\n", g_device_control.duty_cw, data.control.duty_cw);
|
||||
e_printf("暖白LED: %d => %d\r\n", g_device_control.duty_ww, data.control.duty_ww);
|
||||
e_printf("渐变时间: %d => %d\r\n", g_device_control.fade_time, data.control.fade_time);
|
||||
|
||||
data.control.read_done = false;
|
||||
g_device_control = data.control;
|
||||
// fastboot的时候就已经亮起来了,所以当前测温直接变为目标值
|
||||
fade_ctx.current_brightness = g_device_control.brightness_local;
|
||||
fade_ctx.current_cct = g_device_control.cct_local;
|
||||
lab_exit:
|
||||
#endif
|
||||
g_device_control.read_done = true;
|
||||
@ -742,6 +739,7 @@ void save_device_data(void)
|
||||
last_control.brightness_local != g_device_control.brightness_local ||
|
||||
last_control.fade_time != g_device_control.fade_time ||
|
||||
last_control.cct_local != g_device_control.cct_local ||
|
||||
last_control.colourMode != g_device_control.colourMode ||
|
||||
last_control.power_on_cnt != g_device_control.power_on_cnt ||
|
||||
last_control.is_networked != g_device_control.is_networked ||
|
||||
last_control.is_net_configured != g_device_control.is_net_configured;
|
||||
@ -872,9 +870,20 @@ int set_light(light_ctrl_source_e source,
|
||||
if (APP_OPEN_LIGHT == source) {
|
||||
g_device_control.on = true;
|
||||
fade_ctx.current_brightness = 0;
|
||||
fade_ctx.current_cct = g_device_control.cct_local;
|
||||
brightness_local_target = g_device_control.brightness_local;
|
||||
cct_local_target = g_device_control.cct_local;
|
||||
if (g_device_control.colourMode == COLOUR_MODE_DUAL) {
|
||||
fade_ctx.current_cct = g_device_control.cct_local;
|
||||
cct_local_target = g_device_control.cct_local;
|
||||
} else {
|
||||
fade_ctx.current_cct = SINGLE_COLOUR_CCT_LOCAL;
|
||||
cct_local_target = SINGLE_COLOUR_CCT_LOCAL;
|
||||
}
|
||||
}
|
||||
else if (DEV_POWER_ON == source) {
|
||||
if (g_device_control.colourMode == COLOUR_MODE_SINGLE) {
|
||||
fade_ctx.current_cct = SINGLE_COLOUR_CCT_LOCAL;
|
||||
cct_local_target = SINGLE_COLOUR_CCT_LOCAL;
|
||||
}
|
||||
}
|
||||
memcpy(&tmp_fade_ctx, &fade_ctx, FADE_CTRL_DATA_SIZE(fade_ctx));
|
||||
// tmp_fade_ctx.target_brightness = tmp_fade_ctx.current_brightness;
|
||||
@ -901,7 +910,9 @@ int set_light(light_ctrl_source_e source,
|
||||
tmp_fade_ctx.fade_time = NORMAL_FADE_TIME; // 上电时,直接设置为默认渐变时长
|
||||
case APP_CHANGE_LIGHT_MODE:
|
||||
// 直接将信息更新到目标值
|
||||
g_device_control.cct_local = tmp_fade_ctx.target_cct;
|
||||
if (g_device_control.colourMode == COLOUR_MODE_DUAL) {
|
||||
g_device_control.cct_local = tmp_fade_ctx.target_cct;
|
||||
}
|
||||
g_device_control.brightness_local = tmp_fade_ctx.target_brightness;
|
||||
//情景模式或者上电时直接切换到对应的色温和亮度
|
||||
tmp_fade_ctx.is_fading = true;
|
||||
@ -913,13 +924,15 @@ int set_light(light_ctrl_source_e source,
|
||||
memcpy(&fade_ctx, &tmp_fade_ctx, FADE_CTRL_DATA_SIZE(tmp_fade_ctx));
|
||||
e_printf("start fade\r\n");
|
||||
uapi_timer_start(fade_ctx.timer_handle, fade_ctx.update_interval, fade_timer_callback, 0);
|
||||
start_report_task(REPORT_SWITCH | REPORT_BRIGHTNESS | REPORT_CCT);
|
||||
start_report_task(REPORT_SWITCH | REPORT_BRIGHTNESS | REPORT_CCT | REPORT_LIGHT_MODE);
|
||||
req_save_device_data();
|
||||
return 0; // 异步上报
|
||||
break;
|
||||
case APP_CHANGE_LIGHT_BRIGHTNESS_CCT:
|
||||
// 直接将信息更新到目标值
|
||||
g_device_control.cct_local = tmp_fade_ctx.target_cct;
|
||||
if (g_device_control.colourMode == COLOUR_MODE_DUAL) { //只有双色温模式下,色温才会变化
|
||||
g_device_control.cct_local = tmp_fade_ctx.target_cct;
|
||||
}
|
||||
g_device_control.brightness_local = tmp_fade_ctx.target_brightness;
|
||||
tmp_fade_ctx.is_fading = true;
|
||||
tmp_fade_ctx.fade_completed = false;
|
||||
@ -1055,6 +1068,7 @@ static void report_device_online_status(void)
|
||||
fast_report(SVC_ID_CCT);
|
||||
fast_report(SVC_ID_LIGHT_MODE);
|
||||
fast_report(SVC_ID_FADE_TIME);
|
||||
fast_report(SVC_ID_COLOUR_MODE);
|
||||
// fast_report(SVC_ID_NET_INFO);
|
||||
e_printf("Status report completed\r\n");
|
||||
}
|
||||
@ -1086,6 +1100,7 @@ static const struct {
|
||||
[REPORT_CCT] = {SVC_ID_CCT},
|
||||
[REPORT_LIGHT_MODE] = {SVC_ID_LIGHT_MODE},
|
||||
[REPORT_FADE_TIME] = {SVC_ID_FADE_TIME},
|
||||
[REPORT_COLOUR_MODE] = {SVC_ID_COLOUR_MODE},
|
||||
};
|
||||
|
||||
// 状态上报任务函数
|
||||
@ -1127,6 +1142,10 @@ static void *report_task(const char *arg)
|
||||
g_report_mask &= ~REPORT_FADE_TIME;
|
||||
fast_report(SVC_ID_FADE_TIME);
|
||||
}
|
||||
if (g_report_mask & REPORT_COLOUR_MODE) {
|
||||
g_report_mask &= ~REPORT_COLOUR_MODE;
|
||||
fast_report(SVC_ID_COLOUR_MODE);
|
||||
}
|
||||
}
|
||||
|
||||
e_printf("[report_task] Task exited\r\n");
|
||||
@ -1352,7 +1371,12 @@ int spotlight_main(void) {
|
||||
handle_network_status();
|
||||
//上电亮灯也是需要缓慢亮起来, 如果是在配网的话就不用了。交给配网的代码进行控制
|
||||
if (g_net_breath_state == NET_CFG_IDLE && g_device_control.on == true){
|
||||
set_light(DEV_POWER_ON, g_device_control.brightness_local, g_device_control.cct_local);
|
||||
if (g_device_control.colourMode == COLOUR_MODE_SINGLE) {
|
||||
set_light(DEV_POWER_ON, g_device_control.brightness_local, SINGLE_COLOUR_CCT_LOCAL);
|
||||
} else {
|
||||
set_light(DEV_POWER_ON, g_device_control.brightness_local, g_device_control.cct_local);
|
||||
}
|
||||
// set_light(DEV_POWER_ON, g_device_control.brightness_local, g_device_control.cct_local);
|
||||
}
|
||||
|
||||
if (!g_device_control.is_networked && !g_device_control.is_net_configured) {
|
||||
@ -1415,3 +1439,14 @@ static void start_breath_timer(void)
|
||||
uapi_timer_start(breath_ctx.timer_handle, breath_ctx.update_interval, breath_timer_callback, 0);
|
||||
}
|
||||
|
||||
// 模式转换函数:将bitmask转换为上报用的枚举值
|
||||
lightMode_e convert_mode_for_report(lightMode_e current_mode)
|
||||
{
|
||||
// 如果处于离家模式,上报离家模式
|
||||
if (LIGHT_MODE_IS_LEAVE(current_mode)) {
|
||||
return LIGHT_MODE_LEAVE;
|
||||
}
|
||||
// 否则上报基础模式
|
||||
return LIGHT_MODE_GET_BASE(current_mode);
|
||||
}
|
||||
|
||||
|
BIN
output/SR_light-LPT262_hilink-20250703-1.0.4.fwpkg
Normal file
BIN
output/SR_light-LPT262_hilink-20250703-1.0.4.fwpkg
Normal file
Binary file not shown.
BIN
output/package(SR_light-LPT262_hilink-20250703-1.0.4).zip
Normal file
BIN
output/package(SR_light-LPT262_hilink-20250703-1.0.4).zip
Normal file
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user