三色呼吸全灭后切换颜色

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,12 +275,42 @@ 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;
}
}
@@ -396,9 +396,18 @@ __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 &&
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;
@@ -416,6 +425,7 @@ __RAM_CODE void Bridge_Service_1ms(void)
cached_c_mix = (uint16_t)c_mix;
goto dual_output_ready;
}
}
if (next_pdm_enabled) {
cached_w_mix = 0xFFFFU;