diff --git a/application/samples/wifi/ohos_connect/hilink_adapt/product/device_profile.h b/application/samples/wifi/ohos_connect/hilink_adapt/product/device_profile.h index 40b63df..d28bf61 100755 --- a/application/samples/wifi/ohos_connect/hilink_adapt/product/device_profile.h +++ b/application/samples/wifi/ohos_connect/hilink_adapt/product/device_profile.h @@ -30,7 +30,7 @@ extern "C" { #define DEVICE_HIVERSION "1.0.0" /* 设备固件版本号 */ -#define FIRMWARE_VER "1.0.6" +#define FIRMWARE_VER "1.0.8" /* 设备硬件版本号 */ #define HARDWARE_VER "1.0.0" /* 设备软件版本号 */ diff --git a/application/ws63/user_main/spotlight/spotlight_main.c b/application/ws63/user_main/spotlight/spotlight_main.c index cdb542e..8d239be 100755 --- a/application/ws63/user_main/spotlight/spotlight_main.c +++ b/application/ws63/user_main/spotlight/spotlight_main.c @@ -106,6 +106,7 @@ static struct fade_ctx_t { int32_t step_cct; bool is_fading; bool fade_completed; + bool is_closing_fade; // 标记是否为关灯渐变 uint16_t fade_time; //s uint32_t smooth_time_us; // 渐变总时长(us) uint32_t update_interval; // 更新间隔(us) @@ -199,13 +200,13 @@ static void *fade_task(const char *arg) // 使用打印限制器控制打印频率 if (should_print(&fade_ctx.print_limiter)) { - e_printf("%s Brightness: curr:%d, target:%d, step:%d, cct:curr:%d, target:%d, step:%d\r\n", + e_printf("%s Brightness: curr:%d, target:%d, step:%d, cct:curr:%d, target:%d, step:%d, closing:%d\r\n", fade_ctx.print_limiter.prefix, fade_ctx.current_brightness, fade_ctx.target_brightness, fade_ctx.step_brightness, - fade_ctx.current_cct, fade_ctx.target_cct,fade_ctx.step_cct); + fade_ctx.current_cct, fade_ctx.target_cct, fade_ctx.step_cct, fade_ctx.is_closing_fade); } - // 检查是否达到目标值 + // 检查是否达到目标值(恢复原始逻辑) bool brightness_reached = (fade_ctx.step_brightness > 0) ? (fade_ctx.current_brightness >= fade_ctx.target_brightness) : (fade_ctx.current_brightness <= fade_ctx.target_brightness); @@ -213,20 +214,17 @@ static void *fade_task(const char *arg) bool cct_reached = (fade_ctx.step_cct > 0) ? (fade_ctx.current_cct >= fade_ctx.target_cct) : (fade_ctx.current_cct <= fade_ctx.target_cct); - // 更新当前值 - if (!brightness_reached) - { + // 更新当前值(恢复原始逻辑) + if (!brightness_reached) { fade_ctx.current_brightness += fade_ctx.step_brightness; } - if (!cct_reached) - { + if (!cct_reached) { fade_ctx.current_cct += fade_ctx.step_cct; } - // 如果达到目标值,停止渐变 + // 如果达到目标值,停止渐变(恢复原始逻辑) if (brightness_reached && cct_reached) { - e_printf("[fade_task] Fade completed, Final brightness: %d, CCT: %d\r\n", - fade_ctx.target_brightness, - fade_ctx.target_cct); + e_printf("[fade_task] Fade completed, Final brightness: %d, CCT: %d, closing_fade: %d\r\n", + fade_ctx.target_brightness, fade_ctx.target_cct, fade_ctx.is_closing_fade); fade_ctx.is_fading = false; fade_ctx.fade_completed = true; fade_ctx.current_brightness = fade_ctx.target_brightness; @@ -240,16 +238,34 @@ static void *fade_task(const char *arg) device_control.brightness_local = fade_ctx.current_brightness; device_control.cct_local = fade_ctx.current_cct; calculate_pwm_duty(&device_control); - update_pwm_output(g_device_control.on, device_control.duty_cw, device_control.duty_ww); + + // 根据is_closing_fade标志判断PWM开关状态 + bool effective_on_state = fade_ctx.is_closing_fade ? true : g_device_control.on; + + update_pwm_output(effective_on_state, device_control.duty_cw, device_control.duty_ww); if (fade_ctx.fade_completed) { fade_ctx.fade_completed = false; - 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; - if (g_device_control.colourMode == COLOUR_MODE_DUAL) { - g_device_control.cct_local = fade_ctx.current_cct; + + if (fade_ctx.is_closing_fade) { + // 关灯渐变完成:不更新g_device_control.brightness_local,保持原有目标亮度 + fade_ctx.is_closing_fade = false; + update_pwm_output(false, 0, 0); + g_device_control.duty_cw = 0; + g_device_control.duty_ww = 0; + // 注意:这里不更新 g_device_control.brightness_local,保持之前的亮度值 + e_printf("[fade_task] Close light fade completed, PWM turned off, brightness_local preserved: %d\r\n", + g_device_control.brightness_local); + } else { + // 正常渐变完成:正常更新所有值 + 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; + 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); @@ -902,9 +918,24 @@ int set_light(light_ctrl_source_e source, tmp_fade_ctx.fade_time = g_device_control.fade_time; switch (source) { case APP_CLOSE_LIGHT: - close_light(); + // 使用渐变方式关灯:设置目标亮度为0,使用is_closing_fade标志 + g_device_control.on = false; // 设置开关状态为关闭(用于状态上报) + tmp_fade_ctx.is_closing_fade = true; // 标记为关灯渐变 + tmp_fade_ctx.target_brightness = 0; // 目标亮度设为0 + tmp_fade_ctx.target_cct = tmp_fade_ctx.current_cct; // 色温保持不变 + tmp_fade_ctx.fade_time = NORMAL_FADE_TIME; // 使用默认渐变时长 + tmp_fade_ctx.is_fading = true; + tmp_fade_ctx.fade_completed = false; + if (tmp_fade_ctx.is_fading) { + cancel_current_light_fade(); + } + calculate_fade_steps(&tmp_fade_ctx); // 复用原有计算流程 + memcpy(&fade_ctx, &tmp_fade_ctx, FADE_CTRL_DATA_SIZE(tmp_fade_ctx)); + e_printf("start close light fade\r\n"); + uapi_timer_start(fade_ctx.timer_handle, fade_ctx.update_interval, fade_timer_callback, 0); start_report_task(REPORT_SWITCH | REPORT_LIGHT_MODE); - return -111; + req_save_device_data(); + return -111; // 异步上报 break; case DEV_POWER_ON: case APP_OPEN_LIGHT: diff --git a/output/SR_light-LPT262_hilink-20250805-1.0.8.fwpkg b/output/SR_light-LPT262_hilink-20250805-1.0.8.fwpkg new file mode 100644 index 0000000..de62ce3 Binary files /dev/null and b/output/SR_light-LPT262_hilink-20250805-1.0.8.fwpkg differ diff --git a/output/package(SR_light-LPT262_hilink-20250805-1.0.8).zip b/output/package(SR_light-LPT262_hilink-20250805-1.0.8).zip new file mode 100644 index 0000000..a30b930 Binary files /dev/null and b/output/package(SR_light-LPT262_hilink-20250805-1.0.8).zip differ