123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881 |
- #include "u_effect_normal.h"
- #include "u_effect_color.h"
- #include "u_main.h"
- #include "u_pwm_drive.h"
- LightInfo_t g_light_info = {0x00};
- uint8_t u_fabs(uint8_t x, uint8_t y)
- {
- if (x > y)
- return x - y;
- else
- return y - x;
- }
- uint32_t light_color_bright_create(uint32_t light_color, uint8_t bright)
- {
- uint32_t create_color = 0;
- uint8_t color_buff[3] = {0x00};
- if (bright == 0)
- {
- return 0x00;
- }
- //U_UART_PRINTF("breath_color \n");
- color_buff[0] = (light_color >> 16 & 0xff) * bright / 100;
- color_buff[1] = (light_color >> 8 & 0xff) * bright / 100;
- color_buff[2] = (light_color & 0xff) * bright / 100;
-
- create_color = color_buff[0] << 16 | color_buff[1] << 8 | color_buff[2];
- //U_UART_PRINTF("create_color = %x\n", create_color);
- return create_color;
- }
- uint32_t light_color_bright_alter(uint32_t light_color, uint8_t old_bright, uint8_t new_bright)
- {
- uint32_t create_color = 0;
- uint8_t color_buff[3] = {0x00};
-
- //U_UART_PRINTF("breath_color \n");
- color_buff[0] = (light_color >> 16 & 0xff) * new_bright / old_bright;
- color_buff[1] = (light_color >> 8 & 0xff) * new_bright / old_bright;
- color_buff[2] = (light_color & 0xff) * new_bright / old_bright;
-
- create_color = color_buff[0] << 16 | color_buff[1] << 8 | color_buff[2];
- //U_UART_PRINTF("create_color = %x\n", create_color);
- return create_color;
- }
- /****************************** light_mode_gradual **********************************/
- void light_mode_gradual_timer_cb(LightInfo_t *gradual)
- {
- static uint8_t red_cnt = 0, green_cnt = 0, blue_cnt = 0;
- // float green_cnt=0;
- // float blue_cnt=0;
- static uint8_t index = 0;
- uint8_t temp_cnt = 0;
- if(gradual->change_cnt)
- {
- gradual->change_cnt--;
- if(gradual->clr_buff[gradual->curr_ind][0] < gradual->clr_buff[index][0])
- {
- //red_cnt=(float)(gradual->color_buff[index][0] - gradual->color_buff[gradual->curr_ind][0]) / ((gradual->change_time*100)/20);
- if(gradual->change_cnt > 0)
- {
- gradual->clr_temp[0] += red_cnt;
- }
- else
- {
- gradual->clr_temp[0] = gradual->clr_buff[index][0] * 10;
- }
- }
- else if(gradual->clr_buff[gradual->curr_ind][0] > gradual->clr_buff[index][0])
- {
- //red_cnt = (float)(gradual->color_buff[gradual->curr_ind][0] - gradual->color_buff[index][0]) / ((gradual->change_time*100)/20);
- if(gradual->change_cnt > 0)
- {
- gradual->clr_temp[0] -= red_cnt;
- }
- else
- {
- gradual->clr_temp[0] = gradual->clr_buff[index][0] * 10;
- }
- }
-
- if(gradual->clr_buff[gradual->curr_ind][1] < gradual->clr_buff[index][1])
- {
- //green_cnt=(float)(gradual->color_buff[index][1] - gradual->color_buff[gradual->curr_ind][1]) / ((gradual->change_time*100)/20);
- //U_UART_PRINTF("green_cnt+ = %d\n", (int)green_cnt);
- if(gradual->change_cnt > 0)
- {
- gradual->clr_temp[1] += green_cnt;
- }
- else
- {
- gradual->clr_temp[1] = gradual->clr_buff[index][1] * 10;
- }
-
- }
- else if(gradual->clr_buff[gradual->curr_ind][1] > gradual->clr_buff[index][1])
- {
- //green_cnt=(float)(gradual->color_buff[gradual->curr_ind][1] - gradual->color_buff[index][1]) / ((gradual->change_time*100)/20);
- //U_UART_PRINTF("green_cnt- = %d\n", (int)green_cnt);
- if(gradual->change_cnt > 0)
- {
- gradual->clr_temp[1] -= green_cnt;
- }
- else
- {
- gradual->clr_temp[1] = gradual->clr_buff[index][1] * 10;
- }
- }
-
- if(gradual->clr_buff[gradual->curr_ind][2] < gradual->clr_buff[index][2])
- {
- //blue_cnt=(float)(gradual->color_buff[index][2] - gradual->color_buff[gradual->curr_ind][2]) / ((gradual->change_time*100)/20);
- //U_UART_PRINTF("b_i = %d, b_c = %d, blue_cnt+ = %d\n",gradual->color_buff[index][2], gradual->color_buff[gradual->curr_ind][2], (int)blue_cnt);
- if(gradual->change_cnt > 0)
- {
- gradual->clr_temp[2] += blue_cnt;
- }
- else
- {
- gradual->clr_temp[2] = gradual->clr_buff[index][2] * 10;
- }
-
- }
- else if(gradual->clr_buff[gradual->curr_ind][2] > gradual->clr_buff[index][2])
- {
- //blue_cnt=(float)(gradual->color_buff[gradual->curr_ind][2] - gradual->color_buff[index][2]) / ((gradual->change_time*100)/20);
- //U_UART_PRINTF("b_i = %d, b_c = %d, blue_cnt- = %d\n",gradual->color_buff[index][2], gradual->color_buff[gradual->curr_ind][2], (int)blue_cnt);
- if(gradual->change_cnt > 0)
- {
- gradual->clr_temp[2] -= blue_cnt;
- }
- else
- {
- gradual->clr_temp[2] = gradual->clr_buff[index][2] * 10;
- }
- }
- light_set_color(light_color_bright_create((gradual->clr_temp[0] / 10) << 16 | (gradual->clr_temp[1] / 10) << 8 | (gradual->clr_temp[2] / 10) , gradual->set_bright));
- }
- else
- {
- // gradual->curr_ind = ++gradual->curr_ind % gradual->clr_num_max;
- // index = (gradual->curr_ind + 1) % gradual->clr_num_max;
- // gradual->change_cnt = gradual->set_speed * 18;
- //
- // red_cnt = u_fabs(gradual->clr_buff[index][0] , gradual->clr_buff[gradual->curr_ind][0]) * 10 / gradual->change_cnt;
- // green_cnt = u_fabs(gradual->clr_buff[index][1] , gradual->clr_buff[gradual->curr_ind][1]) * 10 / gradual->change_cnt;
- // blue_cnt = u_fabs(gradual->clr_buff[index][2] , gradual->clr_buff[gradual->curr_ind][2]) * 10 / gradual->change_cnt;
- // //U_UART_PRINTF("change_cnt = %d sp = %d, cnt: %d, %d, %d\n",gradual->change_cnt, gradual->set_speed, red_cnt, green_cnt, blue_cnt);
- // gradual->clr_temp[0] = gradual->clr_buff[gradual->curr_ind][0] * 10;
- // gradual->clr_temp[1] = gradual->clr_buff[gradual->curr_ind][1] * 10;
- // gradual->clr_temp[2] = gradual->clr_buff[gradual->curr_ind][2] * 10;
-
- temp_cnt= ++gradual->curr_ind ;
- gradual->curr_ind =temp_cnt % gradual->clr_num_max;
- index = (gradual->curr_ind + 1) % gradual->clr_num_max;
- gradual->change_cnt = gradual->set_speed * 18;
- if(gradual->change_cnt!=0) //这里非0才运算 不然会异常死机 不能做除0运算 20211011刘浩改
- {
- red_cnt = (u_fabs(gradual->clr_buff[index][0] , gradual->clr_buff[gradual->curr_ind][0]) * 10) / gradual->change_cnt;
- green_cnt = u_fabs(gradual->clr_buff[index][1] , gradual->clr_buff[gradual->curr_ind][1]) * 10 / gradual->change_cnt;
- blue_cnt = u_fabs(gradual->clr_buff[index][2] , gradual->clr_buff[gradual->curr_ind][2]) * 10 / gradual->change_cnt;
- }else
- {
- red_cnt=0;
- green_cnt=0;
- blue_cnt=0;
- }
- gradual->clr_temp[0] = gradual->clr_buff[gradual->curr_ind][0] * 10;
- gradual->clr_temp[1] = gradual->clr_buff[gradual->curr_ind][1] * 10;
- gradual->clr_temp[2] = gradual->clr_buff[gradual->curr_ind][2] * 10;
- }
- }
- #define GRADUAL_COLOR_NUM_MAX (8)
- void light_mode_gradual_cfg(LightInfo_t *gradual_cfg, const uint32_t *color_buff, uint8_t color_num, uint8_t speed, uint8_t bright)
- {
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("gradual_clr_num = %d, speed = %d, bright = %d\n", color_num, speed, bright);
- #endif
- if (color_buff)
- {
- int i = 0;
- memset(gradual_cfg, 0, sizeof(LightInfo_t));
- gradual_cfg->change_cnt = 0;
- gradual_cfg->clr_num_max = color_num;
-
- if (gradual_cfg->clr_num_max > GRADUAL_COLOR_NUM_MAX)
- {
- return;
- }
-
- for (i = 0; i < gradual_cfg->clr_num_max; i++)
- {
- gradual_cfg->clr_buff[i][0] = (color_buff[i] >> 16) & 0xff;
- gradual_cfg->clr_buff[i][1] = (color_buff[i] >> 8) & 0xff;
- gradual_cfg->clr_buff[i][2] = color_buff[i] & 0xff;
- }
- g_light_para.effect = LIGHT_EFFECT_GRADUAL;
- //u_analog_timer_stop(&g_ag_timer_light_effect);
- //u_analog_timer_start(&g_ag_timer_light_effect, 20);
- if (color_num == 1) //只有一种颜色
- {
- gradual_cfg->clr_buff[1][0] = 0x00;
- gradual_cfg->clr_buff[1][1] = 0x00;
- gradual_cfg->clr_buff[1][2] = 0x00;
- gradual_cfg->clr_num_max = 2;
- }
- memset(gradual_cfg->color_temp, 0, 3);
- gradual_cfg->curr_ind = 0;
-
- light_mode_gradual_timer_cb(gradual_cfg);
- //light_effect_timer_stop();
- light_effect_timer_start(20);
- }
-
- if (bright)
- {
- gradual_cfg->set_bright = bright;
- }
-
- if (speed)
- {
- gradual_cfg->change_cnt = 0;
- gradual_cfg->curr_ind = 0;
- gradual_cfg->set_speed = speed;
- }
- }
- /**************************** light_mode_grautal end ********************************/
- /******************************** light_mode_jump ********************************/
- void light_mode_jump_timer_cb(LightInfo_t *jump)
- {
-
- if (jump->clr_num_max > 1)
- {
- jump->clr_ind = ++jump->clr_ind >= jump->clr_num_max ? 0 :jump->clr_ind;
- light_set_color(light_color_bright_create(jump->color_buff[jump->clr_ind], jump->set_bright));
- }
- else
- {
- jump->clr_ind = ++jump->clr_ind >= 2 ? 0 :jump->clr_ind;
- if (jump->clr_ind == 0)
- {
- light_set_color(light_color_bright_create(jump->color_buff[jump->clr_ind], jump->set_bright));
- }
- else
- {
- light_set_color(0x00);
- }
- }
- }
- void light_mode_jump_cfg(LightInfo_t *jump_cfg, const uint32_t *color_buff, uint8_t color_num, uint8_t speed, uint8_t bright)
- {
- static unsigned char i=0;
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("jumpclr_num = %d, speed = %d, bright = %d\n", color_num, speed, bright);
- #endif
- if (color_buff)
- {
- i = 0;
- memset(jump_cfg, 0, sizeof(LightInfo_t));
- jump_cfg->color_buff = color_buff;
- jump_cfg->clr_num_max = color_num;
- jump_cfg->clr_ind = 0;
- }
- if (bright)
- {
- jump_cfg->set_bright = bright;
- }
- if (speed)
- {
- light_effect_timer_stop();
- if( i < jump_cfg->clr_num_max)
- {
- i++;
- }else
- {
- i = 0;
- }
- jump_cfg->clr_ind = i;
- jump_cfg->set_speed = speed - 1;
- g_light_para.effect = LIGHT_EFFECT_JUMP;
- light_effect_timer_start(250 + 275 * jump_cfg->set_speed); //475
- light_mode_jump_timer_cb(jump_cfg);
- }
- }
- /**************************** light_mode_jump end ********************************/
- /**************************** light_mode_breath ********************************/
- void light_mode_breath_timer_cb(LightInfo_t *breath)
- {
- uint32_t breath_color = 0;
- if (breath->bright_dir == BRIGHT_DIR_SUBT)
- {
- breath->curr_bright -= BREATH_BRIGHT_STEP_VAL;
- if (breath->curr_bright <= 10)
- {
- breath->curr_bright = 0;
- breath->bright_dir = !breath->bright_dir;
- breath->clr_ind = ++breath->clr_ind >= breath->clr_num_max ? 0 : breath->clr_ind;
- }
- }
- else
- {
- breath->curr_bright += BREATH_BRIGHT_STEP_VAL;
- if (breath->curr_bright >= breath->set_bright)
- {
- breath->curr_bright = breath->set_bright;
- if (++breath->change_cnt > 5)
- {
- breath->change_cnt = 0;
- breath->bright_dir = !breath->bright_dir;
- }
- }
- }
- breath_color = light_color_bright_create(breath->color_buff[breath->clr_ind], breath->curr_bright);
- //U_UART_PRINTF("c_color = %X \n", breath_color);
- light_set_color(breath_color);
- }
- void light_mode_breath_cfg(LightInfo_t *breath_cfg, const uint32_t *color_buff, uint8_t color_num, uint8_t speed, uint8_t bright)
- {
-
- if (color_buff)
- {
- memset(breath_cfg, 0, sizeof(LightInfo_t));
- breath_cfg->color_buff = color_buff;
- breath_cfg->clr_ind = 0;
- breath_cfg->clr_num_max = color_num;
- breath_cfg->bright_dir = BRIGHT_DIR_PLUS;
- breath_cfg->curr_bright = 100;
- }
- if (bright)
- {
- breath_cfg->set_bright = bright;
- }
- if (speed)
- {
- breath_cfg->set_speed = speed;
- g_light_para.effect = LIGHT_EFFECT_BREATH;
- //u_analog_timer_start(&g_ag_timer_light_effect, breath_cfg->set_speed * 4 + 10);
- light_effect_timer_start(breath_cfg->set_speed * 4 + 10);
- }
- }
- /**************************** light_mode_breath end ********************************/
- /**************************** light_mode_static ********************************/
- void light_mode_static_cfg(LightInfo_t *static_cfg, const uint32_t *color_buff, uint8_t bright)
- {
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("static_clr = %06X\n", color_buff[0]);
- #endif
- if (color_buff)
- {
- memset(static_cfg, 0, sizeof(LightInfo_t));
- static_cfg->color_buff = color_buff;
- }
- if (bright)
- {
- static_cfg->set_bright = bright;
- }
- g_light_para.effect = LIGHT_EFFECT_STATIC;
- light_effect_timer_stop();
- light_set_color(light_color_bright_create(*static_cfg->color_buff, static_cfg->set_bright));
- }
- /******************************* light_mode_static end ********************************/
- /********************************* light_mode_blink ***********************************/
- void light_mode_blink_cfg(LightInfo_t *blink_cfg, const uint32_t *color_buff, uint8_t color_num, uint8_t switch_ration, uint8_t speed, uint8_t bright)
- {
- if (bright)
- {
- blink_cfg->set_bright = bright;
- //blink_cfg->color_buff = light_color_bright_create(blink_cfg->color_buff, blink_cfg->set_bright);
- //U_UART_PRINTF("blink_cfg->color_buff = %X\n", blink_cfg->color_buff);
- }
- if (switch_ration)
- {
- blink_cfg->change_cnt = switch_ration;
- }
- if (speed)
- {
- light_effect_timer_stop();
- blink_cfg->clr_ind = 0;
- blink_cfg->play_dir = 0;
- blink_cfg->set_speed = speed - 1;
- g_light_para.effect = LIGHT_EFFECT_BLINK;
- if (blink_cfg->change_cnt < 5)
- {
- light_effect_timer_start(10 + 9 * blink_cfg->set_speed); //95
- }
- else
- {
- light_effect_timer_start( 25 + 35 * blink_cfg->set_speed); //95
- }
- }
- if (color_buff)
- {
- blink_cfg->clr_ind = 0;
- blink_cfg->clr_num_max = color_num;
- blink_cfg->color_buff = color_buff;
- blink_cfg->play_dir = 0;
- light_mode_blink_timer_cb(blink_cfg);
- }
- }
- void light_mode_blink_timer_cb(LightInfo_t *light_blink)
- {
- //static uint8_t blink_run_cnt = 0;
- light_blink->play_dir = ++light_blink->play_dir > 10 ? 1 : light_blink->play_dir;
- //light_blink->play_dir =
- if (light_blink->play_dir == light_blink->change_cnt)
- {
- light_set_color(0x00);
- light_blink->clr_ind = ++light_blink->clr_ind >= light_blink->clr_num_max ? 0 : light_blink->clr_ind;
- }
- else if(light_blink->play_dir == 10)
- {
- light_set_color(light_color_bright_create(light_blink->color_buff[light_blink->clr_ind], light_blink->set_bright));
- //U_UART_PRINTF("ind = %d, clr = %X \r\n", light_blink->color_ind, light_blink->color_buff[light_blink->color_ind]);
- }
- // else
- // {
- // light_set_color(0x00);
- // }
- //U_UART_PRINTF("blink_timer_run\n");
- }
- /********************************* light_mode_blink end ********************************/
- //static void rhythm_Color_switch(RhythmParam_t *rhythm_info) //轮询颜色,跳变,呼吸完成后跳下一次颜色
- //{
- // uint8_t music_mode_ind = rhythm_info->music_mode_ind;//(*rhythm_info->mode & 0x0f) + 10;
- //
- // rhythm_info->color_ind++;
- // if (rhythm_info->color_ind >= rhythm_info->mode_info[music_mode_ind].cnt)
- // {
- // rhythm_info->color_ind = 0;
- // rhythm_info->color_end = 1;
- // }
- // //U_UART_PRINTF("cnt = %d ,s_color_ind = %d\r\n", rhythm_info->mode_info[music_mode_ind].cnt, rhythm_info->color_ind);
- //}
- /********************************* light_rhythm_mode_gradual ********************************/
- enum _color
- {
- red,
- orange,
- yellow,
- green,
- indigo,
- blue,
- purple,
- white,
- };
- void light_rhythm_mode_fade_timer_cb(RhythmPara_t *Grad_Cfg) //音乐模式呼吸事件处理,
- {
- int16_t temp_val;
- static uint8_t temp_arr[3];
- static uint8_t beyond_arr[3];
- static int16_t s_red_val = 0, s_blue_val= 0, s_green_val = 0;
-
- if(!Grad_Cfg->grad_first)
- {
- Grad_Cfg->grad_first = 1;
- clr_format_transition(CLR_TS_TYPE_32_8, 1, temp_arr, (uint32_t *)&Grad_Cfg->clr_buff[Grad_Cfg->clr_ind]);
-
- Grad_Cfg->grad_r_period = temp_arr[0] / Grad_Cfg->speed;
- Grad_Cfg->grad_g_period = temp_arr[1] / Grad_Cfg->speed;
- Grad_Cfg->grad_b_period = temp_arr[2] / Grad_Cfg->speed;
-
- if(temp_arr[0] == 255)
- {
- beyond_arr[0] = 5;
- Grad_Cfg->grad_refer = red;
- }
- else
- beyond_arr[0] = 0;
-
- if(temp_arr[1] == 255)
- {
- beyond_arr[1] = 5;
- Grad_Cfg->grad_refer = green;
- }
- else
- beyond_arr[1] = 0;
-
- if(temp_arr[2] == 255)
- {
- beyond_arr[2] = 5;
- Grad_Cfg->grad_refer = blue;
- }
- else
- beyond_arr[2] = 0;
-
- s_red_val = beyond_arr[0];
- s_green_val = beyond_arr[1];
- s_blue_val= beyond_arr[2];
- Grad_Cfg->grad_dir = 0;
-
- }
- if (Grad_Cfg->music_start)
- {
- if (!Grad_Cfg->grad_dir)
- {
- // uart_printf("1111 %d %d %d %d %d\r\n",red_val,green_val,blue_val,Grad_Cfg.grad_refer,Rgb_Para.rgb_color);
- s_red_val += Grad_Cfg->grad_r_period;
- s_green_val += Grad_Cfg->grad_g_period;
- s_blue_val += Grad_Cfg->grad_b_period;
-
- if (s_red_val >= temp_arr[0])
- {
- s_red_val = temp_arr[0];
- }
- if(s_green_val >= temp_arr[1])
- {
- s_green_val = temp_arr[1];
- }
- if(s_blue_val >= temp_arr[2])
- {
- s_blue_val = temp_arr[2];
- }
- if(Grad_Cfg->grad_refer == red && s_red_val >= temp_arr[0])
- Grad_Cfg->grad_dir = 1;
- if(Grad_Cfg->grad_refer == green && s_green_val >= temp_arr[1])
- Grad_Cfg->grad_dir = 1;
- if(Grad_Cfg->grad_refer == blue && s_blue_val >= temp_arr[2])
- Grad_Cfg->grad_dir = 1;
- }
- else
- {
- // uart_printf("2222 %d %d %d %d %d\r\n",red_val,green_val,blue_val,Grad_Cfg.grad_refer,Rgb_Para.rgb_color);
- s_red_val -= Grad_Cfg->grad_r_period;
- s_green_val -= Grad_Cfg->grad_g_period;
- s_blue_val -= Grad_Cfg->grad_b_period;
-
- if(s_red_val <= beyond_arr[0])
- s_red_val = beyond_arr[0];
- if(s_green_val <= beyond_arr[1])
- s_green_val = beyond_arr[1];
- if(s_blue_val <= beyond_arr[2])
- s_blue_val = beyond_arr[2];
-
- if(Grad_Cfg->grad_refer == red)
- temp_val = s_red_val;
- else if(Grad_Cfg->grad_refer == green)
- temp_val = s_green_val;
- else if(Grad_Cfg->grad_refer == blue)
- temp_val = s_blue_val;
- if(temp_val <= 5)
- {
- // uart_printf("3333 %d %d %d %d %d\r\n",red_val,green_val,blue_val,Grad_Cfg.grad_refer,Rgb_Para.rgb_color);
- Grad_Cfg->grad_dir = 0;
- Grad_Cfg->grad_first = 0;
- //Grad_Cfg->music_end = 1;
- Grad_Cfg->music_start = 0;
- if (++Grad_Cfg->clr_ind >= Grad_Cfg->clr_max_num)
- {
- Grad_Cfg->clr_ind = 0;
- }
- }
- }
- }
- light_set_color(s_blue_val << 16 | s_red_val << 8 | s_green_val);
- // //u_set_color(rhythm_grad->bright, s_red_val, s_green_val, s_blue_val);
- // static uint8_t s_printf_count = 0;
- // if (++s_printf_count > 50)
- // {
- // s_printf_count = 0;
- // U_UART_PRINTF("music_rgb = %X, %X, %X\r\n", s_red_val, s_green_val, s_blue_val);
- // }
- }
- void light_rhythm_mode_fade_cfg(RhythmPara_t *rhythm_gradual_cfg, const uint32_t *color_buff, uint8_t color_num, uint8_t speed)
- {
- memset(rhythm_gradual_cfg, 0, sizeof(RhythmPara_t));
-
- rhythm_gradual_cfg->clr_buff = color_buff;
- rhythm_gradual_cfg->clr_max_num = color_num;
- //rhythm_gradual_cfg->speed = speed * 10;
- // rhythm_gradual_cfg->music_start = 1;
- // rhythm_gradual_cfg->grad_first = 0;
- rhythm_gradual_cfg->speed = 15;
-
- g_light_para.effect = LIGHT_EFFECT_RHYTHM_BREATH;
-
- }
- /********************************* light_rhythm_mode_gradual end ********************************/
- /********************************* light_rhythm_mode_jump ********************************/
- void light_rhythm_mode_jump_timer_cb(RhythmPara_t *rhythm_jump) //跳变模式处理事件,颜色范围由多种,一种颜色跳另一种颜色
- {
- static uint8_t s_switch_count = 0;
-
- static uint8_t temp_arr[3];
- static uint8_t beyond_arr[3];
- static int16_t s_red_val = 0, s_blue_val= 0, s_green_val = 0;
-
- s_switch_count++;
-
- if (rhythm_jump->speed == 0)
- {
-
- light_set_color(light_color_bright_create((rhythm_jump->clr_buff[rhythm_jump->clr_ind]) , LIGHT_BRIGHT_MIN_MIN ));
- //U_UART_PRINTF(" %d %d \r\n",rhythm_jump->clr_buff[rhythm_jump->clr_ind], rhythm_jump->bright);
- }
- else if(s_switch_count >= rhythm_jump->speed) //判断时间到 切换颜色
- {
- s_switch_count = 0;
- rhythm_jump->clr_ind = ++rhythm_jump->clr_ind % rhythm_jump->clr_max_num;
-
- if (rhythm_jump->bright)
- {
- light_set_color(rhythm_jump->clr_buff[rhythm_jump->clr_ind]);
- }
- else
- {
- light_set_color(NULL);
- }
- //U_UART_PRINTF("bright = %d music_rgb = %X, %X, %X\r\n",rhythm_jump->bright, music_r, music_g, music_b);
- }
- //Rgb_Set(&Rgb_Para.color_arr[Rgb_Para.rgb_color *3]);
- }
- void light_rhythm_mode_jump_cfg(RhythmPara_t *rhythm_jump_cfg, const uint32_t *color_buff, uint8_t color_num, uint8_t speed)
- {
- memset(rhythm_jump_cfg, 0, sizeof(RhythmPara_t));
-
- rhythm_jump_cfg->clr_buff = color_buff;
- rhythm_jump_cfg->clr_max_num = color_num;
- rhythm_jump_cfg->speed = speed * 10;
- g_light_para.effect = LIGHT_EFFECT_RHYTHM_JUMP;
- }
- /********************************* light_rhythm_mode_jump end ********************************/
- /********************************* light_rhythm_mode_jump ********************************/
- void light_rhythm_mode_one_clr_timer_cb(RhythmPara_t *rhythm_one_clr)
- {
- static uint8_t s_run_count = 3, cd_cnt = 0;
- // if (++rhythm_one_clr->grad_first >= rhythm_one_clr->speed)
- // {
- // rhythm_one_clr->grad_first = 0;
- if (++cd_cnt >= 2)
- {
- cd_cnt = 0;
- switch (rhythm_one_clr->clr_ind)
- {
- case 0: //亮度加
- {
- s_run_count += rhythm_one_clr->speed;
- if (s_run_count > 100)
- {
- s_run_count = 100;
- rhythm_one_clr->clr_ind = 1;
- }
- light_set_color(light_color_bright_create(rhythm_one_clr->clr_buff[0], s_run_count));
- }
- break;
- case 1: //亮度减
- {
- s_run_count -= rhythm_one_clr->speed;
- if (s_run_count <= 5)
- {
- s_run_count = 5;
- rhythm_one_clr->clr_ind = 2;
- }
- light_set_color(light_color_bright_create(rhythm_one_clr->clr_buff[0], s_run_count));
- }
- break;
- case 2:
- {
- if (++rhythm_one_clr->grad_first >= 3 && rhythm_one_clr->bright)
- {
- rhythm_one_clr->grad_first = 0;
- rhythm_one_clr->clr_ind = 0;
- }
- }
- break;
- }
- }
- }
- void light_rhythm_mode_one_clr_cfg(RhythmPara_t *one_clr_cfg, const uint32_t *color_buff, uint8_t speed)
- {
- memset(one_clr_cfg, 0, sizeof(RhythmPara_t));
-
- one_clr_cfg->clr_buff = color_buff;
- one_clr_cfg->grad_dir = 0;
- one_clr_cfg->bright = LIGHT_BRIGHT_MAX;
- one_clr_cfg->clr_ind = 0; //流程
- one_clr_cfg->grad_first = 0;
- one_clr_cfg->speed = speed * 10;
-
- g_light_para.effect = LIGHT_EFFECT_RHYTHM_ONE_CLR;
- }
- /********************************* light_rhythm_mode_jump end ********************************/
- /****************************** light_rhythm_mode_gradual **********************************/
- void light_rhythm_mode_gradual_timer_cb(RhythmPara_t *gradual_rhythm)
- {
-
- static uint8_t index = 0;
-
- if (gradual_rhythm->bright <= LIGHT_BRIGHT_MIN)
- {
- return;
- }
- if(gradual_rhythm->grad_refer)
- {
- gradual_rhythm->grad_refer--;
- if(gradual_rhythm->color_buff[gradual_rhythm->grad_first][0] < gradual_rhythm->color_buff[index][0])
- {
- //gradual_rhythm->grad_r_period=(float)(gradual_rhythm->color_buff[index][0] - gradual_rhythm->color_buff[gradual_rhythm->grad_first][0]) / ((gradual_rhythm->change_time*100)/20);
- if(gradual_rhythm->grad_refer > 0)
- {
- gradual_rhythm->clr_temp[0] += gradual_rhythm->grad_r_period;
- }
- else
- {
- gradual_rhythm->clr_temp[0] = gradual_rhythm->color_buff[index][0] * 10;
- }
- }
- else if(gradual_rhythm->color_buff[gradual_rhythm->grad_first][0] > gradual_rhythm->color_buff[index][0])
- {
- //gradual_rhythm->grad_r_period = (float)(gradual_rhythm->color_buff[gradual_rhythm->grad_first][0] - gradual_rhythm->color_buff[index][0]) / ((gradual_rhythm->change_time*100)/20);
- if(gradual_rhythm->grad_refer > 0)
- {
- gradual_rhythm->clr_temp[0] -= gradual_rhythm->grad_r_period;
- }
- else
- {
- gradual_rhythm->clr_temp[0] = gradual_rhythm->color_buff[index][0] * 10;
- }
- }
-
- if(gradual_rhythm->color_buff[gradual_rhythm->grad_first][1] < gradual_rhythm->color_buff[index][1])
- {
- //gradual_rhythm->grad_g_period=(float)(gradual_rhythm->color_buff[index][1] - gradual_rhythm->color_buff[gradual_rhythm->grad_first][1]) / ((gradual_rhythm->change_time*100)/20);
- //U_UART_PRINTF("gradual_rhythm->grad_g_period+ = %d\n", (int)gradual_rhythm->grad_g_period);
- if(gradual_rhythm->grad_refer > 0)
- {
- gradual_rhythm->clr_temp[1] += gradual_rhythm->grad_g_period;
- }
- else
- {
- gradual_rhythm->clr_temp[1] = gradual_rhythm->color_buff[index][1] * 10;
- }
-
- }
- else if(gradual_rhythm->color_buff[gradual_rhythm->grad_first][1] > gradual_rhythm->color_buff[index][1])
- {
- //gradual_rhythm->grad_g_period=(float)(gradual_rhythm->color_buff[gradual_rhythm->grad_first][1] - gradual_rhythm->color_buff[index][1]) / ((gradual_rhythm->change_time*100)/20);
- //U_UART_PRINTF("gradual_rhythm->grad_g_period- = %d\n", (int)gradual_rhythm->grad_g_period);
- if(gradual_rhythm->grad_refer > 0)
- {
- gradual_rhythm->clr_temp[1] -= gradual_rhythm->grad_g_period;
- }
- else
- {
- gradual_rhythm->clr_temp[1] = gradual_rhythm->color_buff[index][1] * 10;
- }
- }
-
- if(gradual_rhythm->color_buff[gradual_rhythm->grad_first][2] < gradual_rhythm->color_buff[index][2])
- {
- //gradual_rhythm->grad_b_period=(float)(gradual_rhythm->color_buff[index][2] - gradual_rhythm->color_buff[gradual_rhythm->grad_first][2]) / ((gradual_rhythm->change_time*100)/20);
- //U_UART_PRINTF("b_i = %d, b_c = %d, gradual_rhythm->grad_b_period+ = %d\n",gradual_rhythm->color_buff[index][2], gradual_rhythm->color_buff[gradual_rhythm->grad_first][2], (int)gradual_rhythm->grad_b_period);
- if(gradual_rhythm->grad_refer > 0)
- {
- gradual_rhythm->clr_temp[2] += gradual_rhythm->grad_b_period;
- }
- else
- {
- gradual_rhythm->clr_temp[2] = gradual_rhythm->color_buff[index][2] * 10;
- }
-
- }
- else if(gradual_rhythm->color_buff[gradual_rhythm->grad_first][2] > gradual_rhythm->color_buff[index][2])
- {
- //gradual_rhythm->grad_b_period=(float)(gradual_rhythm->color_buff[gradual_rhythm->grad_first][2] - gradual_rhythm->color_buff[index][2]) / ((gradual_rhythm->change_time*100)/20);
- //U_UART_PRINTF("b_i = %d, b_c = %d, gradual_rhythm->grad_b_period- = %d\n",gradual_rhythm->color_buff[index][2], gradual_rhythm->color_buff[gradual_rhythm->grad_first][2], (int)gradual_rhythm->grad_b_period);
- if(gradual_rhythm->grad_refer > 0)
- {
- gradual_rhythm->clr_temp[2] -= gradual_rhythm->grad_b_period;
- }
- else
- {
- gradual_rhythm->clr_temp[2] = gradual_rhythm->color_buff[index][2] * 10;
- }
- }
-
- light_set_color(light_color_bright_create((gradual_rhythm->clr_temp[0] / 10) << 16 | (gradual_rhythm->clr_temp[1] / 10) << 8 | (gradual_rhythm->clr_temp[2] / 10) , gradual_rhythm->bright));
- }
- else
- {
- // extern uint8_t g_speed;
- gradual_rhythm->grad_first = ++gradual_rhythm->grad_first % gradual_rhythm->clr_max_num;
- index = (gradual_rhythm->grad_first + 1) % gradual_rhythm->clr_max_num;
- gradual_rhythm->grad_refer = 40 - gradual_rhythm->speed * 5;
-
- gradual_rhythm->grad_r_period = u_fabs(gradual_rhythm->color_buff[index][0] , gradual_rhythm->color_buff[gradual_rhythm->grad_first][0]) * 10 / gradual_rhythm->grad_refer;
- gradual_rhythm->grad_g_period = u_fabs(gradual_rhythm->color_buff[index][1] , gradual_rhythm->color_buff[gradual_rhythm->grad_first][1]) * 10 / gradual_rhythm->grad_refer;
- gradual_rhythm->grad_b_period = u_fabs(gradual_rhythm->color_buff[index][2] , gradual_rhythm->color_buff[gradual_rhythm->grad_first][2]) * 10 / gradual_rhythm->grad_refer;
- //U_UART_PRINTF("grad_refer = %d sp = %d, cnt: %d, %d, %d\n",gradual_rhythm->grad_refer, gradual_rhythm->speed, gradual_rhythm->grad_r_period, gradual_rhythm->grad_g_period, gradual_rhythm->grad_b_period);
-
- gradual_rhythm->clr_temp[0] = gradual_rhythm->color_buff[gradual_rhythm->grad_first][0] * 10;
- gradual_rhythm->clr_temp[1] = gradual_rhythm->color_buff[gradual_rhythm->grad_first][1] * 10;
- gradual_rhythm->clr_temp[2] = gradual_rhythm->color_buff[gradual_rhythm->grad_first][2] * 10;
- }
- }
- void light_rhythm_mode_gradual_cfg(RhythmPara_t *gradual_rhythm_cfg, const uint32_t *color_buff, uint8_t color_num, uint8_t speed)
- {
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("r_gradual_clr_num = %d, speed = %d\n", color_num, speed);
- #endif
- if (color_buff)
- {
- int i = 0;
- memset(gradual_rhythm_cfg, 0, sizeof(RhythmPara_t));
- gradual_rhythm_cfg->grad_refer = 0;
- gradual_rhythm_cfg->clr_max_num = color_num;
- gradual_rhythm_cfg->bright = 100;
- gradual_rhythm_cfg->speed = 5;
- gradual_rhythm_cfg->clr_buff=app_static_clr;
- //gradual_rhythm_cfg->clr_buff 被上面memset清零后内存地址指向了0 防止后面程序调用gradual_rhythm_cfg->clr_buff[0]访问空指针导致异常添加一个静态初值app_static_clr 防止异常死机 2021/11/13 LH加
-
- if (gradual_rhythm_cfg->clr_max_num > GRADUAL_COLOR_NUM_MAX)
- {
- return;
- }
-
- for (i = 0; i < gradual_rhythm_cfg->clr_max_num; i++)
- {
- gradual_rhythm_cfg->color_buff[i][0] = (color_buff[i] >> 16) & 0xff;
- gradual_rhythm_cfg->color_buff[i][1] = (color_buff[i] >> 8) & 0xff;
- gradual_rhythm_cfg->color_buff[i][2] = color_buff[i] & 0xff;
- }
-
- memset(gradual_rhythm_cfg->clr_temp, 0, 3);
- gradual_rhythm_cfg->grad_first = 0;
-
- light_rhythm_mode_gradual_timer_cb(gradual_rhythm_cfg);
-
- light_set_color( light_color_bright_create( (gradual_rhythm_cfg->clr_buff[0]) << 16 | (gradual_rhythm_cfg->clr_buff[0]) << 8 | (gradual_rhythm_cfg->clr_buff[0]) , LIGHT_BRIGHT_MIN_MIN));
- //gradual_rhythm_cfg->clr_buff=app_static_clr 实现了切换到音乐模式下时调整到粉红色 亮度最小
- }
-
- // if (speed)
- // {
- // gradual_rhythm_cfg->speed = speed;
- // }
- }
- /**************************** light_rhythm_mode_gradual end ********************************/
|