123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |
- #include "u_effect_rhythm.h"
- #include "u_main.h"
- #include "drv_mic.h"
- #include "user_driver.h"
- RhythmPara_t g_normal_rhythm = {0x00}; //全彩律动
- static uint8_t s_app_rhythm_val = 0x00;
- extern void delay_ms(unsigned int tt);
- void u_set_one_rhythm_color(void)
- {
- //u_set_color(m_rhythm.vol_value, m_rhythm.mode_info[12].data[0], m_rhythm.mode_info[12].data[1], m_rhythm.mode_info[12].data[2]);
- }
- void app_rhythm_val_up(uint8_t rhythm_val)
- {
- s_app_rhythm_val = rhythm_val;
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("v = %d\n", s_app_rhythm_val);
- #endif
- }
- void rhythm_timer_cd(void)//app控制律动模式
- {
- #define RHYTHM_SENSIT_K (3)
- static uint8_t s_run_cnt = 0, vol_val = 0;
- uint8_t adc_vol;
- //static uint8_t s_music_keep = 0;
- uint8_t rhythm_pvt = 10;
- if( g_light_para.mic == 0)
- {
- adc_vol = s_app_rhythm_val;//rhythm_vol_get_cb();
- }
- else
- {
- if(g_light_para.mic_AppOrDriver == 1)
- {
- adc_vol = rhythm_vol_get_cb();
- //U_UART_PRINTF("i am driver mic \r\n");
- }else
- {
- adc_vol = s_app_rhythm_val;
- //U_UART_PRINTF("i am app mic \r\n");
- }
- }
- switch (g_light_para.rhythm_mode)
- {
- case RHYTHM_MODE_JUMP_7:
- case RHYTHM_MODE_JUMP_3:
- {
- rhythm_pvt = g_light_para.rhythm_sensit + VOT_JUMP_VPT;
- //U_UART_PRINTF(" u_pvt = %d\n", rhythm_pvt);
- if (adc_vol > rhythm_pvt)
- {
- int16_t speed = (adc_vol - rhythm_pvt) / 8;
- if (speed >= 4)
- speed = 4;
- else if (speed <= 0)
- speed = 0;
- //U_UART_PRINTF("speed = %d\n", speed);
- g_normal_rhythm.bright = MODE_JUMP_BRIGHT;
- //U_UART_PRINTF("MODE_JUMP_BRIGHT\n");
- g_normal_rhythm.speed = 27 - speed * 5;
- //U_UART_PRINTF("f3_sd = %d\n", g_normal_rhythm.speed);
- }
- else
- {
- g_normal_rhythm.bright = LIGHT_BRIGHT_MIN;
- g_normal_rhythm.speed = 0;
- //U_UART_PRINTF("MODE_JUMP_MIN_BRIGHT\n");
- }
- light_rhythm_mode_jump_timer_cb(&g_normal_rhythm);
- }
- break;
- case RHYTHM_MODE_GRADUAL_7:
- {
- rhythm_pvt = 30; //g_light_para.rhythm_sensit + 10;
- if (adc_vol > rhythm_pvt)
- {
- int16_t speed = (adc_vol - rhythm_pvt) / 14;
- if (speed >= 4)
- speed = 4;
- else if (speed <= 0)
- speed = 0;
- g_normal_rhythm.bright = adc_vol;
- g_normal_rhythm.speed = speed;
- }
- else
- {
- g_normal_rhythm.bright = LIGHT_BRIGHT_MIN;
- }
- light_rhythm_mode_gradual_timer_cb(&g_normal_rhythm);
- }
- break;
- case RHYTHM_MODE_FADE_7:
- {
- rhythm_pvt = g_light_para.rhythm_sensit + VOT_GRADUAL_7_VPT;
- if (adc_vol > rhythm_pvt )
- {
- //U_UART_PRINTF(" u_pvt = %d\n", rhythm_pvt);
- int16_t speed = (adc_vol - rhythm_pvt) / 8;
- if (speed >= 4)
- speed = 4;
- else if (speed <= 0)
- speed = 0;
- g_normal_rhythm.speed = 27 - speed * 5;
- g_normal_rhythm.music_start = 1;
- //U_UART_PRINTF("f7_sd = %d\n", g_normal_rhythm.speed);
- }
- light_rhythm_mode_fade_timer_cb(&g_normal_rhythm);
- }
- break;
- case RHYTHM_MODE_FADE_3:
- {
- rhythm_pvt = g_light_para.rhythm_sensit + VOT_GRADUAL_3_VPT;
- if (adc_vol > rhythm_pvt )
- {
- //U_UART_PRINTF(" u_pvt = %d\n", rhythm_pvt);
- g_normal_rhythm.music_start = 1;
- g_normal_rhythm.speed = 15;
- //U_UART_PRINTF("f3_sd = %d\n", g_normal_rhythm.speed);
- }
- light_rhythm_mode_fade_timer_cb(&g_normal_rhythm);
- }
- break;
- }
- }
- void driver_rhythm_timer_cd(void)//设备mic律动模式
- {
- #define RHYTHM_SENSIT_K (3)
- static uint8_t s_run_cnt = 0, vol_val = 0;
- uint8_t adc_vol=0;
- uint8_t rhythm_pvt = 10;
- if( g_light_para.mic ==0)
- {
- adc_vol = s_app_rhythm_val;//rhythm_vol_get_cb();
- }
- else
- {
- if(g_light_para.mic_AppOrDriver == 1)
- {
- adc_vol = rhythm_vol_get_cb();
- }else if(g_light_para.mic_AppOrDriver == 0)
- {
- adc_vol = s_app_rhythm_val;
- }
- }
- switch (g_light_para.rhythm_mode)
- {
- case RHYTHM_MODE_JUMP_7:
- case RHYTHM_MODE_JUMP_3:
- {
- rhythm_pvt = g_light_para.rhythm_sensit * 100 / 125 + VOT_JUMP_VPT;//rhythm_pvt 最大为50
- if (adc_vol > rhythm_pvt)
- {
- int16_t speed = (adc_vol - rhythm_pvt) / 26; //计算速度
- if (speed >= 4)
- speed = 4;
- else if (speed <= 0)
- speed = 0;
- //U_UART_PRINTF("speed = %d\n", speed);
- g_normal_rhythm.bright = MODE_JUMP_BRIGHT; //律动模式
- //U_UART_PRINTF("MODE_JUMP_BRIGHT\n");
- g_normal_rhythm.speed = 27 - speed * 5; //律动速度
- //U_UART_PRINTF("f3_sd = %d\n", g_normal_rhythm.speed);
- }
- else
- {
- g_normal_rhythm.bright = LIGHT_BRIGHT_MIN;
- g_normal_rhythm.speed = 0;
- //U_UART_PRINTF("MODE_JUMP_MIN_BRIGHT\n");
- }
- light_rhythm_mode_jump_timer_cb(&g_normal_rhythm);
- }
- break;
- case RHYTHM_MODE_GRADUAL_7://渐变律动模式
- {
- rhythm_pvt = 30; //g_light_para.rhythm_sensit + 10;
- if (adc_vol > rhythm_pvt)
- {
- int16_t speed = (adc_vol - rhythm_pvt) / 14;
- if (speed >= 4)
- speed = 4;
- else if (speed <= 0)
- speed = 0;
- g_normal_rhythm.bright = adc_vol;
- g_normal_rhythm.speed = speed;
- }
- else
- {
- g_normal_rhythm.bright = 0;
- }
- light_rhythm_mode_gradual_timer_cb(&g_normal_rhythm);
- }
- break;
- case RHYTHM_MODE_FADE_7:
- {
- rhythm_pvt = g_light_para.rhythm_sensit * 100 / 125 + VOT_GRADUAL_7_VPT;
- if (adc_vol > rhythm_pvt )
- {
- //U_UART_PRINTF(" u_pvt = %d\n", rhythm_pvt);
- int16_t speed = (adc_vol - rhythm_pvt) / 26;
- if (speed >= 4)
- speed = 4;
- else if (speed <= 0)
- speed = 0;
- g_normal_rhythm.speed = 27 - speed * 5;
- g_normal_rhythm.music_start = 1;
- //U_UART_PRINTF("f7_sd = %d\n", g_normal_rhythm.speed);
- }
- light_rhythm_mode_fade_timer_cb(&g_normal_rhythm);
- }
- break;
- case RHYTHM_MODE_FADE_3:
- {
- rhythm_pvt = g_light_para.rhythm_sensit + VOT_GRADUAL_3_VPT;
- if (adc_vol > rhythm_pvt )
- {
- //U_UART_PRINTF(" u_pvt = %d\n", rhythm_pvt);
- g_normal_rhythm.music_start = 1;
- g_normal_rhythm.speed = 15;
- //U_UART_PRINTF("f3_sd = %d\n", g_normal_rhythm.speed);
- }
- light_rhythm_mode_fade_timer_cb(&g_normal_rhythm);
- }
- break;
- }
- }
- /****************************** mic_adc **********************************/
- static void bubble_sort(uint8_t *sample_data,uint16_t len) //冒泡
- {
- uint16_t i,j;
- uint16_t temp;
- for(j = 0; j < (len - 1); j++)
- {
- for(i=0;i < (len - 1 - j);i++)
- {
- if(sample_data[i] > sample_data[i+1])
- {
- temp = sample_data[i];
- sample_data[i] = sample_data[i+1];
- sample_data[i+1] = temp;
- }
- }
- }
- }
- #if 0
- uint8_t rhythm_vol_get_cb(void)
- {
- static uint8_t buff_ind = 0, vol_value = 0;
- static uint8_t adc_sample[10] = {0};
- //adc_temp = ADC_Get_Value();
- //初始化ADC
- // ADC_Deinit(2);
- ADC_Init(1);
- //delay_ms(2);
- ADC_Get_Value();
- adc_sample[buff_ind] = ADC_Get_Value();
- //U_UART_PRINTF("adc_sample = %d\n", adc_sample[buff_ind]);
- buff_ind++;
- if (buff_ind >= 10)
- {
- int i = 0;
- uint16_t sample_num = 0;
- buff_ind = 0;
- bubble_sort(adc_sample, 10);
- for (i = 0; i < 5; i++)
- {
- sample_num += adc_sample[i+5];
- }
- vol_value = sample_num / 5;
- //U_UART_PRINTF("%d\n", vol_value);
- }
- return vol_value;
- }
- #endif
- //char show_buffer[10]={0};
- //#include "stdio.h"
- uint8_t rhythm_vol_get_cb(void)
- {
- static uint8_t buff_ind = 0, vol_value = 0;
- static uint8_t adc_sample[10] = {0};
- adc_sample[buff_ind] = Get_Audio_val();
- //U_UART_PRINTF("adc_sample = %d\n", adc_sample[buff_ind]);
- buff_ind++;
- if (buff_ind >= 10)
- {
- int i = 0;
- uint16_t sample_num = 0;
- buff_ind = 0;
- bubble_sort(adc_sample, 10);
- for (i = 0; i < 5; i++)
- {
- sample_num += adc_sample[i+5];
- }
- vol_value = sample_num / 5;
-
- // U_UART_PRINTF("adc_val:");
- // for(i=0;i<10;i++)
- // {
- // U_UART_PRINTF(" %d ", (int)adc_sample[i]);
- // }
- // U_UART_PRINTF("\r\n");
- // sprintf(show_buffer,"v:%3d ",vol_value);
- // u_ble_data_send(show_buffer,strlen(show_buffer));
- //U_UART_PRINTF("%d\n", vol_value);
- }
- // vol_value = Get_Audio_val();
- return vol_value;
- }
- /****************************** mic_adc end **********************************/
- /*
- sensit_step 红外遥控调节灵敏度加减
- rhythm_sensit app调节灵敏度
- */
- void rhythm_sensit_ctrl(const int8_t sensit_step, const uint8_t rhythm_sensit)// 调整mic灵敏度
- {
- uint8_t dri_rhythm_sensit = LIGHT_SENSIT_MAX - rhythm_sensit / APP_SENSIT_K;
- if (dri_rhythm_sensit > LIGHT_SENSIT_MAX)
- {
- return;
- }
- if (sensit_step != 0)
- {
- int8_t sensit = 0;
- sensit = g_light_para.rhythm_sensit + sensit_step;
- if (sensit >= LIGHT_SENSIT_MIN && sensit <= LIGHT_SENSIT_MAX)
- {
- g_light_para.rhythm_sensit = sensit;
- }
- else if (sensit <= LIGHT_SENSIT_MIN)
- {
- g_light_para.rhythm_sensit = LIGHT_SENSIT_MIN;
- }
- else if (sensit >= LIGHT_SENSIT_MAX)
- {
- g_light_para.rhythm_sensit = LIGHT_SENSIT_MAX;
- }
- }
- else
- {
- g_light_para.rhythm_sensit = dri_rhythm_sensit;
- }
- // sprintf(show_buffer,"s:%3d ",(int)g_light_para.rhythm_sensit);
- // u_ble_data_send(show_buffer,strlen(show_buffer));
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("sensit = [%d] [%d] \n", g_light_para.rhythm_sensit, g_light_para.rhythm_sensit);
- #endif
- }
- /*
- void rhythm_speed_ctrl(const uint8_t rhythm_mode, const int8_t speed_step, uint8_t rhythm_speed)
- {
- uint8_t rhythm_speed_ind = 0;
-
- if (rhythm_speed > LIGHT_SPEED_MAX)
- {
- rhythm_speed = LIGHT_SPEED_MAX;
- }
- else if (rhythm_speed < LIGHT_SPEED_MIN)
- {
- rhythm_speed = LIGHT_SPEED_MIN;
- }
-
- if (rhythm_mode > RHYTHM_MODE_FULL_MAX)
- {
- rhythm_speed_ind = RHYTHM_SPEED_IND_DREAM;
- }
- else
- {
- rhythm_speed_ind = RHYTHM_SPEED_IND_FULL;
- }
-
- if (speed_step != 0)
- {
- int8_t speed = 0;
- speed = g_light_para.rhythm_speed[rhythm_speed_ind] + speed_step;
-
- if (speed >= LIGHT_SPEED_MIN && speed <= LIGHT_SPEED_MAX)
- {
- g_light_para.rhythm_speed[rhythm_speed_ind] = speed;
- }
- else if (speed <= LIGHT_SPEED_MIN)
- {
- g_light_para.rhythm_speed[rhythm_speed_ind] = LIGHT_SPEED_MIN;
- }
- else if (speed >= LIGHT_SPEED_MAX)
- {
- g_light_para.rhythm_speed[rhythm_speed_ind] = LIGHT_SPEED_MAX;
- }
- }
- else
- {
- g_light_para.rhythm_speed[rhythm_speed_ind] = rhythm_speed;
- }
-
- U_UART_PRINTF("speed = [%d] [%d] \n", g_light_para.rhythm_speed[0], g_light_para.rhythm_speed[1]);
- }
- */
|