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