平滑三色呼吸颜色交接

This commit is contained in:
2026-07-28 11:03:30 +08:00
parent 5edc9d0ba2
commit 049adfc05b
2 changed files with 26 additions and 7 deletions
@@ -19,6 +19,8 @@ uint8_t Mode=mode0; //mode0 1 2 3 4
uint8_t Speed=5; //速度 uint8_t Speed=5; //速度
uint8_t direction = 1; // 呼吸灯的亮度变化方向,1表示增加,0表示减小 uint8_t direction = 1; // 呼吸灯的亮度变化方向,1表示增加,0表示减小
#define THREE_COLOR_SINGLE_JOIN_LEVEL 41U
uint8_t choose_mode_falsg=0; //模式值 uint8_t choose_mode_falsg=0; //模式值
uint8_t choose_mode_bh=0; //模式变化 uint8_t choose_mode_bh=0; //模式变化
static uint8_t mode_entry_initialized; static uint8_t mode_entry_initialized;
@@ -230,11 +232,11 @@ void Mode1(){ //
breathespeed_flag=0; breathespeed_flag=0;
W_PWM -= 1; W_PWM -= 1;
C_PWM = 0; C_PWM = 0;
if (W_PWM <= 1) { if (W_PWM <= THREE_COLOR_SINGLE_JOIN_LEVEL) {
direction = 2; direction = 2;
driveMode=0; driveMode=0;
W_PWM = 1; W_PWM = 1;
C_PWM = 0; C_PWM = 1;
} }
break; break;
case 2: case 2:
@@ -254,8 +256,8 @@ void Mode1(){ //
if (W_PWM <=1) { if (W_PWM <=1) {
driveMode=2; driveMode=2;
direction = 4; direction = 4;
W_PWM = 1; W_PWM = 0;
C_PWM = 1; C_PWM = THREE_COLOR_SINGLE_JOIN_LEVEL;
} }
break; break;
case 4: case 4:
@@ -272,11 +274,11 @@ void Mode1(){ //
breathespeed_flag=0; breathespeed_flag=0;
W_PWM = 0; W_PWM = 0;
C_PWM -= 1; C_PWM -= 1;
if (C_PWM <=1){ if (C_PWM <= THREE_COLOR_SINGLE_JOIN_LEVEL){
direction = 0; direction = 0;
driveMode=1; driveMode=1;
W_PWM = 1; W_PWM = THREE_COLOR_SINGLE_JOIN_LEVEL;
C_PWM = 1; C_PWM = 0;
} }
break; break;
@@ -13,6 +13,7 @@ volatile uint32_t Light_Transition_C_Output_Q12;
#define LIGHT_OUTPUT_SCALE 1000U #define LIGHT_OUTPUT_SCALE 1000U
#define BREATH_MIN_OUTPUT (LIGHT_OUTPUT_SCALE / 100U) #define BREATH_MIN_OUTPUT (LIGHT_OUTPUT_SCALE / 100U)
#define DUAL_MIN_STABLE_CHANNEL_OUTPUT 102U #define DUAL_MIN_STABLE_CHANNEL_OUTPUT 102U
#define THREE_COLOR_JOIN_OUTPUT (2U * DUAL_MIN_STABLE_CHANNEL_OUTPUT)
#define POWER_FADE_Q12_MAX 4096U #define POWER_FADE_Q12_MAX 4096U
#define POWER_FADE_ON_TICKS 140U #define POWER_FADE_ON_TICKS 140U
#define POWER_FADE_OFF_TICKS 160U #define POWER_FADE_OFF_TICKS 160U
@@ -353,6 +354,22 @@ void Light_Transition_Task(void)
(LIGHT_OUTPUT_SCALE / 100U) + 2048U) >> 12); (LIGHT_OUTPUT_SCALE / 100U) + 2048U) >> 12);
} }
/*
* The three-color breathing effect joins a single-color phase to a
* 50:50 phase. Keep the single-color side at the same physical minimum
* as the stable dual-color side, otherwise the first mixed step jumps
* from about 10/1000 to at least 204/1000.
*/
if(Mode == mode1 && choose_mode_falsg == 5U)
{
if(W_PWM != 0U && C_PWM == 0U &&
target_w < THREE_COLOR_JOIN_OUTPUT)
target_w = THREE_COLOR_JOIN_OUTPUT;
else if(C_PWM != 0U && W_PWM == 0U &&
target_c < THREE_COLOR_JOIN_OUTPUT)
target_c = THREE_COLOR_JOIN_OUTPUT;
}
/* /*
* Keep the weaker mixed-light direction at the measured stable threshold. * Keep the weaker mixed-light direction at the measured stable threshold.
* Raise the combined output only when the requested W:C ratio needs it. * Raise the combined output only when the requested W:C ratio needs it.