增加双色交叠渐变模式

This commit is contained in:
2026-07-28 14:03:33 +08:00
parent 60ec4838f2
commit 71e4bb628a
5 changed files with 90 additions and 25 deletions
@@ -84,26 +84,29 @@ void set_mode(){
W_PWM=1U; C_PWM=1U; driveMode=0U; direction=0U; Mode=mode1;
break;
case 6:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=1U; Mode=mode1;
W_PWM=1U; C_PWM=0U; driveMode=1U; direction=0U; Mode=mode1;
break;
case 7:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=1U; Mode=mode3;
break;
case 8:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=1U; Mode=mode2;
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=0U; Mode=mode3;
break;
case 9:
W_PWM=0U; C_PWM=100U; driveMode=2U; direction=1U; Mode=mode2;
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=1U; Mode=mode2;
break;
case 10:
W_PWM=50U; C_PWM=50U; driveMode=0U; direction=1U; Mode=mode2;
W_PWM=0U; C_PWM=100U; driveMode=2U; direction=1U; Mode=mode2;
break;
case 11:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=2U; Mode=mode2;
W_PWM=50U; C_PWM=50U; driveMode=0U; direction=1U; Mode=mode2;
break;
case 12:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=2U; Mode=mode2;
break;
case 13:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=2U; Mode=mode2;
break;
case CUSTOM_TEMPERATURE_MODE:
Mode=mode0;
break;
@@ -151,6 +154,7 @@ void Mode0(){ //
#define THREE_COLOR_WAIT_NEUTRAL 6U
#define THREE_COLOR_WAIT_COLD 7U
#define THREE_COLOR_WAIT_WARM 8U
#define OVERLAP_GRADIENT_LEVEL 40U
static uint8_t breathespeed_flag=0; //该变量只是用来处理三种颜色呼吸时候,对中性光的速度变大
static void breathe_fun(uint16_t *PWM_1, uint16_t *PWM_2, uint8_t flag) {
@@ -294,13 +298,13 @@ void jump_fun(uint16_t *PWM_1, uint16_t *PWM_2, uint8_t flag){
void Mode2(void)
{
if(choose_mode_falsg==8U){
if(choose_mode_falsg==9U){
jump_fun(&C_PWM,&W_PWM,0U);
}else if(choose_mode_falsg==9U){
jump_fun(&W_PWM,&C_PWM,0U);
}else if(choose_mode_falsg==10U){
jump_fun(&W_PWM,&C_PWM,1U);
jump_fun(&W_PWM,&C_PWM,0U);
}else if(choose_mode_falsg==11U){
jump_fun(&W_PWM,&C_PWM,1U);
}else if(choose_mode_falsg==12U){
switch(direction){
case 1U:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=2U;
@@ -312,7 +316,7 @@ void Mode2(void)
W_PWM=50U; C_PWM=50U; driveMode=0U; direction=1U;
break;
}
}else if(choose_mode_falsg==12U){
}else if(choose_mode_falsg==13U){
switch(direction){
case 1U:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=2U;
@@ -338,15 +342,52 @@ void Mode2(void)
void Mode3(void)
{
if(choose_mode_falsg!=7U) return;
if(direction==1U){
if(C_PWM<100U) C_PWM++;
W_PWM=100U-C_PWM;
if(C_PWM>=100U){ C_PWM=100U; W_PWM=0U; direction=0U; }
if(choose_mode_falsg==7U){
if(direction==1U){
if(C_PWM<100U) C_PWM++;
W_PWM=100U-C_PWM;
if(C_PWM>=100U){ C_PWM=100U; W_PWM=0U; direction=0U; }
}else{
if(C_PWM>0U) C_PWM--;
W_PWM=100U-C_PWM;
if(C_PWM==0U){ W_PWM=100U; direction=1U; }
}
}else if(choose_mode_falsg==8U){
switch(direction){
case 0U:
C_PWM=0U; driveMode=1U;
if(W_PWM>OVERLAP_GRADIENT_LEVEL) W_PWM--;
if(W_PWM<=OVERLAP_GRADIENT_LEVEL){ W_PWM=OVERLAP_GRADIENT_LEVEL; direction=1U; }
break;
case 1U:
if(W_PWM>0U){ W_PWM--; C_PWM++; }
driveMode=0U;
if(W_PWM==0U){ C_PWM=OVERLAP_GRADIENT_LEVEL; driveMode=2U; direction=2U; }
break;
case 2U:
W_PWM=0U; driveMode=2U;
if(C_PWM<100U) C_PWM++;
if(C_PWM>=100U){ C_PWM=100U; direction=3U; }
break;
case 3U:
W_PWM=0U; driveMode=2U;
if(C_PWM>OVERLAP_GRADIENT_LEVEL) C_PWM--;
if(C_PWM<=OVERLAP_GRADIENT_LEVEL){ C_PWM=OVERLAP_GRADIENT_LEVEL; direction=4U; }
break;
case 4U:
if(C_PWM>0U){ C_PWM--; W_PWM++; }
driveMode=0U;
if(C_PWM==0U){ W_PWM=OVERLAP_GRADIENT_LEVEL; driveMode=1U; direction=5U; }
break;
case 5U:
default:
C_PWM=0U; driveMode=1U;
if(W_PWM<100U) W_PWM++;
if(W_PWM>=100U){ W_PWM=100U; direction=0U; }
break;
}
}else{
if(C_PWM>0U) C_PWM--;
W_PWM=100U-C_PWM;
if(C_PWM==0U){ W_PWM=100U; direction=1U; }
return;
}
if(C_PWM==0U) driveMode=1U;
else if(W_PWM==0U) driveMode=2U;
@@ -14,8 +14,8 @@ extern "C" {
typedef void (*pfunc)(void);
#define EFFECT_MODE_MIN 0U
#define EFFECT_MODE_MAX 12U
#define CUSTOM_TEMPERATURE_MODE 13U
#define EFFECT_MODE_MAX 13U
#define CUSTOM_TEMPERATURE_MODE 14U
extern uint8_t deviceStatus; //开机标志位
@@ -492,8 +492,22 @@ __RAM_CODE void Bridge_Service_1ms(void)
* split evenly between W->C and C->W, which both absorbs interrupt
* latency and spreads the two optical pulses across the 500 us frame.
*/
total_on_us = (BRIDGE_DUAL_ACTIVE_US * total +
(BRIDGE_MIX_SCALE / 2U)) / BRIDGE_MIX_SCALE;
if (Mode == mode3 && choose_mode_falsg == 8U) {
/*
* The overlap gradient intentionally carries only 40% combined
* output through its crossover. Base that section on the complete
* 500 us frame so entering/leaving dual output does not create a
* 10% brightness step. The 450 us safety ceiling still applies.
*/
total_on_us = (BRIDGE_FRAME_US * total +
(BRIDGE_MIX_SCALE / 2U)) / BRIDGE_MIX_SCALE;
if (total_on_us > BRIDGE_DUAL_ACTIVE_US) {
total_on_us = BRIDGE_DUAL_ACTIVE_US;
}
} else {
total_on_us = (BRIDGE_DUAL_ACTIVE_US * total +
(BRIDGE_MIX_SCALE / 2U)) / BRIDGE_MIX_SCALE;
}
/* Keep a non-zero timer interval without imposing a brightness floor. */
if (total_on_us < (2U * BRIDGE_MIN_DUAL_PULSE_US)) {
total_on_us = 2U * BRIDGE_MIN_DUAL_PULSE_US;
@@ -71,6 +71,8 @@ unsigned char get_checksum(unsigned char *ptrdata, unsigned char length)
#define FLASH_BRIGHTNESS_FORMAT_INDEX 14U
#define FLASH_BRIGHTNESS_PERCENT_MARK 0xA5U
#define FLASH_MODE_LAYOUT_INDEX 26U
#define FLASH_MODE_LAYOUT_MARK 0xA6U
void read_user_data(void)
{
@@ -131,6 +133,12 @@ void read_user_data(void)
adress_H_array[4]=r_data[24];
adress_L_array[4]=r_data[25];
choose_mode_falsg=r_data[30];
/* Preserve old mode meanings after inserting new mode 9. */
if(r_data[FLASH_MODE_LAYOUT_INDEX] != FLASH_MODE_LAYOUT_MARK &&
choose_mode_falsg >= 8U && choose_mode_falsg <= 13U)
{
choose_mode_falsg++;
}
if(choose_mode_falsg > CUSTOM_TEMPERATURE_MODE)
choose_mode_falsg = EFFECT_MODE_MIN;
//choose_mode_bh=r_data[31];
@@ -178,7 +186,7 @@ void wright_user_data(void)
app_data[23]=adress_L_array[3];
app_data[24]=adress_H_array[4];
app_data[25]=adress_L_array[4];
app_data[26]=0;
app_data[FLASH_MODE_LAYOUT_INDEX]=FLASH_MODE_LAYOUT_MARK;
app_data[27]=0;
app_data[28]=0;
app_data[29]=0;
@@ -103,7 +103,8 @@ static uint16_t output_brightness_scale_for_level(uint8_t level)
if(level < BRIGHTNESS_MIN_PERCENT) level = BRIGHTNESS_MIN_PERCENT;
if(level > BRIGHTNESS_MAX_PERCENT) level = BRIGHTNESS_MAX_PERCENT;
if(Mode == mode3 && choose_mode_falsg == 7U)
if(Mode == mode3 &&
(choose_mode_falsg == 7U || choose_mode_falsg == 8U))
return brightness_scale_for_level(level);
if(W_PWM != 0U && C_PWM != 0U)
@@ -381,7 +382,8 @@ void Light_Transition_Task(void)
if(W_PWM != 0U && C_PWM != 0U &&
!(Mode == mode1 &&
(choose_mode_falsg == 5U || choose_mode_falsg == 6U)) &&
!(Mode == mode3 && choose_mode_falsg == 7U))
!(Mode == mode3 &&
(choose_mode_falsg == 7U || choose_mode_falsg == 8U)))
{
mix_total = (uint16_t)(W_PWM + C_PWM);
weak_mix = (W_PWM < C_PWM) ? W_PWM : C_PWM;