三色呼吸全灭后切换颜色

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 uint8_t breathespeed_flag=0; //该变量只是用来处理三种颜色呼吸时候,对中性光的速度变大
static void breathe_fun(uint16_t *PWM_1, uint16_t *PWM_2, uint8_t flag) { static void breathe_fun(uint16_t *PWM_1, uint16_t *PWM_2, uint8_t flag) {
if (flag == 0) { if (flag == 0) {
@@ -231,10 +235,9 @@ void Mode1(){ //
W_PWM -= 1; W_PWM -= 1;
C_PWM = 0; C_PWM = 0;
if (W_PWM <= 1) { if (W_PWM <= 1) {
direction = 2; direction = THREE_COLOR_WAIT_NEUTRAL;
driveMode=0; W_PWM = 0;
W_PWM = 1; C_PWM = 0;
C_PWM = 1;
} }
break; break;
case 2: case 2:
@@ -252,10 +255,9 @@ void Mode1(){ //
W_PWM -= 1; W_PWM -= 1;
C_PWM -= 1; C_PWM -= 1;
if (W_PWM <=1) { if (W_PWM <=1) {
driveMode=2; direction = THREE_COLOR_WAIT_COLD;
direction = 4;
W_PWM = 0; W_PWM = 0;
C_PWM = 1; C_PWM = 0;
} }
break; break;
case 4: case 4:
@@ -273,13 +275,43 @@ void Mode1(){ //
W_PWM = 0; W_PWM = 0;
C_PWM -= 1; C_PWM -= 1;
if (C_PWM <=1){ if (C_PWM <=1){
direction = 0; direction = THREE_COLOR_WAIT_WARM;
driveMode=1; W_PWM = 0;
W_PWM = 1;
C_PWM = 0; C_PWM = 0;
} }
break; 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 */ //(void)0;/* transition */
@@ -396,25 +396,35 @@ __RAM_CODE void Bridge_Service_1ms(void)
*/ */
if (deviceStatus != POWEROFF && if (deviceStatus != POWEROFF &&
Mode == mode1 && choose_mode_falsg == 5U && Mode == mode1 && choose_mode_falsg == 5U &&
w_mix != 0U && c_mix != 0U && w_mix != 0U && c_mix != 0U) {
pdm_w_step != 0U && pdm_c_step != 0U && /*
pdm_w_step < BRIDGE_TRICOLOR_PDM_THRESHOLD && * Follow the smoothed physical output rather than the next logical
pdm_c_step < BRIDGE_TRICOLOR_PDM_THRESHOLD) { * target. This lets the old color reach zero before the wait state
next_w_us = BRIDGE_TRICOLOR_PDM_PULSE_US; * starts the next color.
next_c_us = BRIDGE_TRICOLOR_PDM_PULSE_US; */
total_off_us = pdm_w_step =
BRIDGE_FRAME_US - BRIDGE_DUAL_ACTIVE_US * ((uint32_t)w_mix << 12);
(2U * BRIDGE_TRICOLOR_PDM_PULSE_US); pdm_c_step =
next_wc_off_us = (uint16_t)(total_off_us / 2U); BRIDGE_DUAL_ACTIVE_US * ((uint32_t)c_mix << 12);
next_cw_off_us =
(uint16_t)(total_off_us - next_wc_off_us); if (pdm_w_step < BRIDGE_TRICOLOR_PDM_THRESHOLD &&
next_pdm_w_step = pdm_w_step; pdm_c_step < BRIDGE_TRICOLOR_PDM_THRESHOLD) {
next_pdm_c_step = pdm_c_step; next_w_us = BRIDGE_TRICOLOR_PDM_PULSE_US;
next_pdm_threshold = BRIDGE_TRICOLOR_PDM_THRESHOLD; next_c_us = BRIDGE_TRICOLOR_PDM_PULSE_US;
next_pdm_enabled = 1U; total_off_us =
cached_w_mix = (uint16_t)w_mix; BRIDGE_FRAME_US -
cached_c_mix = (uint16_t)c_mix; (2U * BRIDGE_TRICOLOR_PDM_PULSE_US);
goto dual_output_ready; 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) { if (next_pdm_enabled) {