From 625cdb585d45144d845e7d08dc11f6c7945af576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E7=90=AA?= Date: Tue, 28 Jul 2026 13:32:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=B8=90=E5=8F=98=E4=BA=92?= =?UTF-8?q?=E8=A1=A5=E4=B8=8E=E9=97=AA=E7=83=81=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/ble/ble_peripheral/app/src/Mode.c | 3 ++- .../ble/ble_peripheral/app/src/bridge_pwm.c | 10 ++++++++ .../ble_peripheral/app/src/light_transition.c | 24 ++++++++++++++++--- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/project/example/ble/ble_peripheral/app/src/Mode.c b/project/example/ble/ble_peripheral/app/src/Mode.c index b7bd741..e1d797b 100644 --- a/project/example/ble/ble_peripheral/app/src/Mode.c +++ b/project/example/ble/ble_peripheral/app/src/Mode.c @@ -62,7 +62,6 @@ void Stop_PWM(){ void set_mode(){ - Light_Transition_Task(); if(choose_mode_bh==0){ choose_mode_bh=1; switch(choose_mode_falsg){ @@ -122,6 +121,7 @@ void set_mode(){ else { Light_Transition_ModeActive=0U; + Light_Transition_SyncBrightness(Brightness); } startTimer(&timer1,1); } @@ -130,6 +130,7 @@ void set_mode(){ mode_entry_initialized=1; } } + Light_Transition_Task(); } void Mode0(){ //³£Á¿ (void)0;/* transition */ diff --git a/project/example/ble/ble_peripheral/app/src/bridge_pwm.c b/project/example/ble/ble_peripheral/app/src/bridge_pwm.c index ac46d1f..ba78776 100644 --- a/project/example/ble/ble_peripheral/app/src/bridge_pwm.c +++ b/project/example/ble/ble_peripheral/app/src/bridge_pwm.c @@ -456,6 +456,16 @@ __RAM_CODE void Bridge_Service_1ms(void) single_state = (w_mix != 0U) ? BRIDGE_W : BRIDGE_C; pwm_duty = (uint16_t)((total * BRIDGE_PWM_SCALE + (BRIDGE_MIX_SCALE / 2U)) / BRIDGE_MIX_SCALE); + /* + * A mixed H-bridge frame has 450 us of active time after deadtime. + * Use the same 450/500 energy at both single-color endpoints of the + * continuous gradient so its total brightness does not jump there. + */ + if (Mode == mode3 && choose_mode_falsg == 7U) { + pwm_duty = (uint16_t)( + ((uint32_t)pwm_duty * BRIDGE_DUAL_ACTIVE_US + + (BRIDGE_FRAME_US / 2U)) / BRIDGE_FRAME_US); + } if (output_mode == BRIDGE_MODE_SINGLE && active_state == single_state && diff --git a/project/example/ble/ble_peripheral/app/src/light_transition.c b/project/example/ble/ble_peripheral/app/src/light_transition.c index 36fe976..3acd90c 100644 --- a/project/example/ble/ble_peripheral/app/src/light_transition.c +++ b/project/example/ble/ble_peripheral/app/src/light_transition.c @@ -293,6 +293,7 @@ void Light_Transition_Task(void) uint8_t powered_on = deviceStatus != POWEROFF; uint16_t target_w; uint16_t target_c; + uint16_t target_total; uint16_t target_brightness_scale; uint16_t brightness_scale; uint16_t fade_scale; @@ -337,7 +338,22 @@ void Light_Transition_Task(void) powered_on ? (power_fade_progress_q12 < POWER_FADE_Q12_MAX) : (power_fade_progress_q12 != 0U); - if(Mode == mode1) + if(Mode == mode3 && choose_mode_falsg == 7U) + { + /* + * Continuous CCT uses one shared brightness envelope. Derive one + * side from the other so every visible step is strictly complementary + * and W + C remains constant throughout the sweep. + */ + target_total = (uint16_t)( + ((uint32_t)LIGHT_OUTPUT_SCALE * brightness_scale + 2048U) >> 12); + target_w = (uint16_t)( + ((uint32_t)target_total * W_PWM + 50U) / 100U); + if(target_w > target_total) + target_w = target_total; + target_c = target_total - target_w; + } + else if(Mode == mode1) { target_w = (uint16_t)( ((uint32_t)effect_gamma_output(W_PWM) * @@ -364,7 +380,8 @@ void Light_Transition_Task(void) */ if(W_PWM != 0U && C_PWM != 0U && !(Mode == mode1 && - (choose_mode_falsg == 5U || choose_mode_falsg == 6U))) + (choose_mode_falsg == 5U || choose_mode_falsg == 6U)) && + !(Mode == mode3 && choose_mode_falsg == 7U)) { mix_total = (uint16_t)(W_PWM + C_PWM); weak_mix = (W_PWM < C_PWM) ? W_PWM : C_PWM; @@ -419,7 +436,8 @@ void Light_Transition_Task(void) if(mode_transition_tick >= MODE_TRANSITION_TICKS) Light_Transition_ModeActive = 0U; } - else if((Mode == mode2 && powered_on) || power_transitioning || + else if(((Mode == mode2 || Mode == mode3) && powered_on) || + power_transitioning || transition_sync_pending) { W_PWM_duty = target_w;