扩展十三种灯光效果模式

This commit is contained in:
2026-07-28 13:14:11 +08:00
parent 6532524f81
commit e66570c005
7 changed files with 185 additions and 229 deletions
+167 -223
View File
@@ -66,88 +66,52 @@ void set_mode(){
if(choose_mode_bh==0){
choose_mode_bh=1;
switch(choose_mode_falsg){
//
case 0:
//暖光
W_PWM=Color_table_static[0][0];
C_PWM=Color_table_static[0][1];
driveMode=1;//切换为暖光的底层输出
Mode=mode0;
W_PWM=100U; C_PWM=0U; driveMode=1U; Mode=mode0;
break;
case 1:
//冷光
W_PWM=Color_table_static[2][0];
C_PWM=Color_table_static[2][1];
driveMode=2;//切换为冷光的底层输出
Mode=mode0;
W_PWM=0U; C_PWM=100U; driveMode=2U; Mode=mode0;
break;
case 2:
//中性光
W_PWM=Color_table_static[1][0];
C_PWM=Color_table_static[1][1];
driveMode=0;//切换为中性光的底层输出
Mode=mode0;
W_PWM=50U; C_PWM=50U; driveMode=0U; Mode=mode0;
break;
case 3:
//暖光呼吸
W_PWM=Color_table[0][0];
C_PWM=Color_table[0][1];
driveMode=1;//切换为暖光的底层输出
direction=1;//呼吸方向恢复默认值
Mode=mode1;
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=1U; Mode=mode1;
break;
case 4:
//冷光呼吸
W_PWM=Color_table[2][0];
C_PWM=Color_table[2][1];
driveMode=2;//切换为中性光的底层输出
direction=1;//呼吸方向恢复默认值
Mode=mode1;
case 4:
W_PWM=0U; C_PWM=100U; driveMode=2U; direction=1U; Mode=mode1;
break;
case 5:
//三个色温轮询呼吸//先从暖光开始呼吸
W_PWM=Color_table[0][0];
C_PWM=Color_table[0][1];
driveMode=1;//切换为暖光的底层输出
direction=1;//呼吸方向恢复默认值
Mode=mode1;
case 5:
W_PWM=68U; C_PWM=68U; driveMode=0U; direction=1U; Mode=mode1;
break;
case 6:
//暖光跳变
W_PWM=Color_table[0][0];
C_PWM=Color_table[0][1];
driveMode=1;//切换为暖光的底层输出
direction=1;//呼吸方向恢复默认值
Mode=mode2;
case 6:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=1U; Mode=mode1;
break;
case 7:
//中性光跳变
W_PWM=Color_table[1][0];
C_PWM=Color_table[1][1];
driveMode=0;//切换为中性光的底层输出
Mode=mode2;
case 7:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=1U; Mode=mode3;
break;
case 8:
//冷光跳变
W_PWM=Color_table[2][0];
C_PWM=Color_table[2][1];
driveMode=2;//切换为中性光的底层输出
direction=1;//呼吸方向恢复默认值
Mode=mode2;
case 8:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=1U; Mode=mode2;
break;
case 9:
//暖光中性光冷交替跳变,先从暖光跳变
W_PWM=Color_table[0][0];
C_PWM=Color_table[0][1];
driveMode=1;//切换为暖光的底层输出
direction=1;//呼吸方向恢复默认值
Mode=mode2;
case 9:
W_PWM=0U; C_PWM=100U; driveMode=2U; direction=1U; Mode=mode2;
break;
case 10:
W_PWM=50U; C_PWM=50U; driveMode=0U; direction=1U; Mode=mode2;
break;
case 11:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=2U; Mode=mode2;
break;
case 12:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=2U; Mode=mode2;
break;
case CUSTOM_TEMPERATURE_MODE:
Mode=mode0;
break;
default:
choose_mode_falsg=0U;
W_PWM=100U; C_PWM=0U; driveMode=1U; Mode=mode0;
break;
case 10://圆环模式
Mode=mode0;
break;
}
if(mode_entry_initialized)
{
@@ -214,112 +178,85 @@ static void breathe_fun(uint16_t *PWM_1, uint16_t *PWM_2, uint8_t flag) {
// }
}
}
void Mode1(){ //呼吸
if(choose_mode_falsg==3){ //暖光呼吸
breathe_fun(&C_PWM,&W_PWM,0);
}else if(choose_mode_falsg==4){//冷光呼吸
breathe_fun(&W_PWM,&C_PWM,0);
}else if(choose_mode_falsg==5){
switch (direction) {
case 0:
breathespeed_flag=0;
W_PWM += 1;
C_PWM = 0;
if (W_PWM >= 100) {
direction = 1;
}
break;
case 1:
breathespeed_flag=0;
W_PWM -= 1;
C_PWM = 0;
if (W_PWM <= 1) {
direction = THREE_COLOR_WAIT_NEUTRAL;
W_PWM = 0;
C_PWM = 0;
}
break;
case 2:
breathespeed_flag=1;
W_PWM += 1;
C_PWM += 1;
if (W_PWM >= 68) {
W_PWM=68;
C_PWM=68;
direction = 3;
}
break;
case 3:
breathespeed_flag=1;
W_PWM -= 1;
C_PWM -= 1;
if (W_PWM <=1) {
direction = THREE_COLOR_WAIT_COLD;
W_PWM = 0;
C_PWM = 0;
}
break;
case 4:
breathespeed_flag=0;
W_PWM = 0;
C_PWM += 1;
if (C_PWM >= 100) {
direction = 5;
}
break;
case 5:
breathespeed_flag=0;
W_PWM = 0;
C_PWM -= 1;
if (C_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;
}
static void neutral_breathe_fun(void)
{
breathespeed_flag=1U;
if(direction==1U){
if(W_PWM>1U){ W_PWM--; C_PWM--; }
if(W_PWM<=1U){ W_PWM=1U; C_PWM=1U; direction=0U; }
}else{
if(W_PWM<68U){ W_PWM++; C_PWM++; }
if(W_PWM>=68U){ W_PWM=68U; C_PWM=68U; direction=1U; }
}
//(void)0;/* transition */
(void)0;/* transition */
}
void Mode1(void)
{
if(choose_mode_falsg==3U){
breathespeed_flag=0U;
breathe_fun(&C_PWM,&W_PWM,0U);
}else if(choose_mode_falsg==4U){
breathespeed_flag=0U;
breathe_fun(&W_PWM,&C_PWM,0U);
}else if(choose_mode_falsg==5U){
neutral_breathe_fun();
}else if(choose_mode_falsg==6U){
switch(direction){
case 0U:
breathespeed_flag=0U;
W_PWM++; C_PWM=0U;
if(W_PWM>=100U){ W_PWM=100U; direction=1U; }
break;
case 1U:
breathespeed_flag=0U;
if(W_PWM>0U) W_PWM--;
C_PWM=0U;
if(W_PWM<=1U){ W_PWM=0U; direction=THREE_COLOR_WAIT_COLD; }
break;
case 4U:
breathespeed_flag=0U;
W_PWM=0U; C_PWM++;
if(C_PWM>=100U){ C_PWM=100U; direction=5U; }
break;
case 5U:
breathespeed_flag=0U;
W_PWM=0U;
if(C_PWM>0U) C_PWM--;
if(C_PWM<=1U){ C_PWM=0U; direction=THREE_COLOR_WAIT_NEUTRAL; }
break;
case 2U:
breathespeed_flag=1U;
W_PWM++; C_PWM++;
if(W_PWM>=68U){ W_PWM=68U; C_PWM=68U; direction=3U; }
break;
case 3U:
breathespeed_flag=1U;
if(W_PWM>0U) W_PWM--;
if(C_PWM>0U) C_PWM--;
if(W_PWM<=1U){ W_PWM=0U; C_PWM=0U; direction=THREE_COLOR_WAIT_WARM; }
break;
case THREE_COLOR_WAIT_COLD:
breathespeed_flag=0U; W_PWM=0U; C_PWM=0U;
if(W_PWM_duty==0U && C_PWM_duty==0U){
driveMode=2U; C_PWM=1U; direction=4U;
}
break;
case THREE_COLOR_WAIT_NEUTRAL:
breathespeed_flag=1U; W_PWM=0U; C_PWM=0U;
if(W_PWM_duty==0U && C_PWM_duty==0U){
driveMode=0U; W_PWM=1U; C_PWM=1U; direction=2U;
}
break;
case THREE_COLOR_WAIT_WARM:
default:
breathespeed_flag=0U; W_PWM=0U; C_PWM=0U;
if(W_PWM_duty==0U && C_PWM_duty==0U){
driveMode=1U; W_PWM=1U; direction=0U;
}
break;
}
}
}
void jump_fun(uint16_t *PWM_1, uint16_t *PWM_2, uint8_t flag){
if(flag==0){
*PWM_1 = 0;
@@ -332,8 +269,8 @@ void jump_fun(uint16_t *PWM_1, uint16_t *PWM_2, uint8_t flag){
}
}else if(flag==1){
if (!direction){
*PWM_1 = 40;
*PWM_2 = 40;
*PWM_1 = 50;
*PWM_2 = 50;
direction = 1;
} else {
*PWM_1 = 0;
@@ -343,58 +280,65 @@ void jump_fun(uint16_t *PWM_1, uint16_t *PWM_2, uint8_t flag){
}
}
void Mode2(){ //跳变
//printf("dd=%d--%d\r\n",W_PWM,W_PWM);
if(choose_mode_falsg==6){
jump_fun(&C_PWM,&W_PWM,0); //暖光跳变
}else if(choose_mode_falsg==7){
jump_fun(&W_PWM,&C_PWM,1); //中光跳变
}else if(choose_mode_falsg==8){
jump_fun(&W_PWM,&C_PWM,0); //冷光跳变
}else if(choose_mode_falsg==9){
switch (direction) {
case 1:
W_PWM =100;
C_PWM = 0;
direction = 2;
break;
case 2:
W_PWM = 0;
C_PWM = 0;
direction = 3;
driveMode=0;
break;
case 3:
W_PWM =40;
C_PWM =40;
direction = 4;
break;
case 4:
W_PWM =0;
C_PWM =0;
direction = 5;
driveMode=2;
break;
case 5:
W_PWM = 0;
C_PWM = 100;
direction = 6;
break;
case 6:
W_PWM = 0;
C_PWM = 0;
direction = 1;
driveMode=1;
break;
}
void Mode2(void)
{
if(choose_mode_falsg==8U){
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);
}else if(choose_mode_falsg==11U){
switch(direction){
case 1U:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=2U;
break;
case 2U:
W_PWM=0U; C_PWM=100U; driveMode=2U; direction=3U;
break;
default:
W_PWM=50U; C_PWM=50U; driveMode=0U; direction=1U;
break;
}
(void)0;/* transition */
}else if(choose_mode_falsg==12U){
switch(direction){
case 1U:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=2U;
break;
case 2U:
W_PWM=0U; C_PWM=0U; driveMode=2U; direction=3U;
break;
case 3U:
W_PWM=0U; C_PWM=100U; direction=4U;
break;
case 4U:
W_PWM=0U; C_PWM=0U; driveMode=0U; direction=5U;
break;
case 5U:
W_PWM=50U; C_PWM=50U; direction=6U;
break;
default:
W_PWM=0U; C_PWM=0U; driveMode=1U; direction=1U;
break;
}
}
}
void Mode3(){ //爆闪 //无
(void)0;/* transition */
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; }
}else{
if(C_PWM>0U) C_PWM--;
W_PWM=100U-C_PWM;
if(C_PWM==0U){ W_PWM=100U; direction=1U; }
}
if(C_PWM==0U) driveMode=1U;
else if(W_PWM==0U) driveMode=2U;
else driveMode=0U;
}
pfunc modefunctin[] = { //模式切换,一共15个模式
Mode0,
@@ -417,7 +361,7 @@ void choice_mode(){
}else if(Mode==mode2){
startTimer(&timer1,time_2[Speed]);
}else if(Mode==mode3){
startTimer(&timer1,time_3[Speed]);//
startTimer(&timer1,time_1[Speed]);//
}
modefunctin[Mode]();
@@ -13,6 +13,10 @@ extern "C" {
#include <stdint.h>
typedef void (*pfunc)(void);
#define EFFECT_MODE_MIN 0U
#define EFFECT_MODE_MAX 12U
#define CUSTOM_TEMPERATURE_MODE 13U
extern uint8_t deviceStatus; //开机标志位
extern uint8_t Mode; //mode0 1 2 3 4
@@ -438,7 +438,7 @@ void rf433_receive(void)//RF433 sample, called every 100 us
uint16_t spee_dealy_time=0; //速度缓慢变换
#define REMOTE_MODE_MIN 0U
#define REMOTE_MODE_MAX 9U
#define REMOTE_MODE_MAX EFFECT_MODE_MAX
void _433_fun(){
if(Light_Transition_FeedbackActive()) return;
@@ -527,7 +527,7 @@ void _433_fun(){
if(res_data>=16&&res_data<=255){
Mode=mode0;
choose_mode_bh=0;
choose_mode_falsg=10;//圆环模式
choose_mode_falsg=CUSTOM_TEMPERATURE_MODE;//圆环模式
driveMode=0;
temperature((uint8_t)(((uint16_t)(255U - res_data) * 255U + 119U) / 239U));
startTimer(&timer1,1);
@@ -403,7 +403,8 @@ __RAM_CODE void Bridge_Service_1ms(void)
* PWM all the way down to zero.
*/
if (deviceStatus != POWEROFF &&
Mode == mode1 && choose_mode_falsg == 5U &&
Mode == mode1 &&
(choose_mode_falsg == 5U || choose_mode_falsg == 6U) &&
w_mix != 0U && c_mix != 0U) {
pdm_w_step =
BRIDGE_DUAL_ACTIVE_US * ((uint32_t)w_mix << 12);
@@ -131,6 +131,8 @@ 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];
if(choose_mode_falsg > CUSTOM_TEMPERATURE_MODE)
choose_mode_falsg = EFFECT_MODE_MIN;
//choose_mode_bh=r_data[31];
driveMode=r_data[32];
flag_1h = (r_data[36] << 24) | (r_data[35] << 16) | (r_data[34] << 8) | r_data[33];
@@ -103,6 +103,9 @@ 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)
return brightness_scale_for_level(level);
if(W_PWM != 0U && C_PWM != 0U)
return mixed_brightness_gamma_q12[level - 1U];
@@ -360,7 +363,8 @@ void Light_Transition_Task(void)
* brightness is treated as single color.
*/
if(W_PWM != 0U && C_PWM != 0U &&
!(Mode == mode1 && choose_mode_falsg == 5U))
!(Mode == mode1 &&
(choose_mode_falsg == 5U || choose_mode_falsg == 6U)))
{
mix_total = (uint16_t)(W_PWM + C_PWM);
weak_mix = (W_PWM < C_PWM) ? W_PWM : C_PWM;
@@ -124,8 +124,9 @@ void scan_uart(uint8_t *arr)
break;
case 2:
if(POWEROFF==deviceStatus)break;
if(user_rx_buf[1] < 1U || user_rx_buf[1] > (EFFECT_MODE_MAX + 1U)) break;
choose_mode_bh=0;
choose_mode_falsg=user_rx_buf[1]-1;
choose_mode_falsg=user_rx_buf[1]-1U;
startTimer(&timer1,1);
break;
case 3:
@@ -153,7 +154,7 @@ void scan_uart(uint8_t *arr)
temperature(user_rx_buf[1]);
Mode=mode0;
choose_mode_bh=0;
choose_mode_falsg=10;//圆环模式
choose_mode_falsg=CUSTOM_TEMPERATURE_MODE;//圆环模式
startTimer(&timer1,1);
break;
case 10: