三色呼吸全灭后切换颜色

This commit is contained in:
2026-07-28 11:33:02 +08:00
parent deb935e544
commit 5a29f94c70
2 changed files with 71 additions and 29 deletions
@@ -171,6 +171,10 @@ void Mode0(){ //
}
#define THREE_COLOR_WAIT_NEUTRAL 6U
#define THREE_COLOR_WAIT_COLD 7U
#define THREE_COLOR_WAIT_WARM 8U
static uint8_t breathespeed_flag=0; //该变量只是用来处理三种颜色呼吸时候,对中性光的速度变大
static void breathe_fun(uint16_t *PWM_1, uint16_t *PWM_2, uint8_t flag) {
if (flag == 0) {
@@ -231,10 +235,9 @@ void Mode1(){ //
W_PWM -= 1;
C_PWM = 0;
if (W_PWM <= 1) {
direction = 2;
driveMode=0;
W_PWM = 1;
C_PWM = 1;
direction = THREE_COLOR_WAIT_NEUTRAL;
W_PWM = 0;
C_PWM = 0;
}
break;
case 2:
@@ -252,10 +255,9 @@ void Mode1(){ //
W_PWM -= 1;
C_PWM -= 1;
if (W_PWM <=1) {
driveMode=2;
direction = 4;
direction = THREE_COLOR_WAIT_COLD;
W_PWM = 0;
C_PWM = 1;
C_PWM = 0;
}
break;
case 4:
@@ -273,13 +275,43 @@ void Mode1(){ //
W_PWM = 0;
C_PWM -= 1;
if (C_PWM <=1){
direction = 0;
driveMode=1;
W_PWM = 1;
direction = THREE_COLOR_WAIT_WARM;
W_PWM = 0;
C_PWM = 0;
}
break;
case THREE_COLOR_WAIT_NEUTRAL:
breathespeed_flag=1;
W_PWM = 0;
C_PWM = 0;
if(W_PWM_duty == 0U && C_PWM_duty == 0U){
driveMode=0;
W_PWM = 1;
C_PWM = 1;
direction = 2;
}
break;
case THREE_COLOR_WAIT_COLD:
breathespeed_flag=0;
W_PWM = 0;
C_PWM = 0;
if(W_PWM_duty == 0U && C_PWM_duty == 0U){
driveMode=2;
C_PWM = 1;
direction = 4;
}
break;
case THREE_COLOR_WAIT_WARM:
breathespeed_flag=0;
W_PWM = 0;
C_PWM = 0;
if(W_PWM_duty == 0U && C_PWM_duty == 0U){
driveMode=1;
W_PWM = 1;
direction = 0;
}
break;
}
}
//(void)0;/* transition */
@@ -396,25 +396,35 @@ __RAM_CODE void Bridge_Service_1ms(void)
*/
if (deviceStatus != POWEROFF &&
Mode == mode1 && choose_mode_falsg == 5U &&
w_mix != 0U && c_mix != 0U &&
pdm_w_step != 0U && pdm_c_step != 0U &&
pdm_w_step < BRIDGE_TRICOLOR_PDM_THRESHOLD &&
pdm_c_step < BRIDGE_TRICOLOR_PDM_THRESHOLD) {
next_w_us = BRIDGE_TRICOLOR_PDM_PULSE_US;
next_c_us = BRIDGE_TRICOLOR_PDM_PULSE_US;
total_off_us =
BRIDGE_FRAME_US -
(2U * BRIDGE_TRICOLOR_PDM_PULSE_US);
next_wc_off_us = (uint16_t)(total_off_us / 2U);
next_cw_off_us =
(uint16_t)(total_off_us - next_wc_off_us);
next_pdm_w_step = pdm_w_step;
next_pdm_c_step = pdm_c_step;
next_pdm_threshold = BRIDGE_TRICOLOR_PDM_THRESHOLD;
next_pdm_enabled = 1U;
cached_w_mix = (uint16_t)w_mix;
cached_c_mix = (uint16_t)c_mix;
goto dual_output_ready;
w_mix != 0U && c_mix != 0U) {
/*
* Follow the smoothed physical output rather than the next logical
* target. This lets the old color reach zero before the wait state
* starts the next color.
*/
pdm_w_step =
BRIDGE_DUAL_ACTIVE_US * ((uint32_t)w_mix << 12);
pdm_c_step =
BRIDGE_DUAL_ACTIVE_US * ((uint32_t)c_mix << 12);
if (pdm_w_step < BRIDGE_TRICOLOR_PDM_THRESHOLD &&
pdm_c_step < BRIDGE_TRICOLOR_PDM_THRESHOLD) {
next_w_us = BRIDGE_TRICOLOR_PDM_PULSE_US;
next_c_us = BRIDGE_TRICOLOR_PDM_PULSE_US;
total_off_us =
BRIDGE_FRAME_US -
(2U * BRIDGE_TRICOLOR_PDM_PULSE_US);
next_wc_off_us = (uint16_t)(total_off_us / 2U);
next_cw_off_us =
(uint16_t)(total_off_us - next_wc_off_us);
next_pdm_w_step = pdm_w_step;
next_pdm_c_step = pdm_c_step;
next_pdm_threshold = BRIDGE_TRICOLOR_PDM_THRESHOLD;
next_pdm_enabled = 1U;
cached_w_mix = (uint16_t)w_mix;
cached_c_mix = (uint16_t)c_mix;
goto dual_output_ready;
}
}
if (next_pdm_enabled) {