1. 新增单双色温的支持 =》 已测试
2. 新增离家模式的支持 => 等待测试
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user