#include "u_effect_rhythm.h" #include "u_main.h" RhythmPara_t g_normal_rhythm = {0x00}; //全彩律动 static uint8_t s_app_rhythm_val = 0x00; 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; U_UART_PRINTF("v = %d\n", s_app_rhythm_val); } void rhythm_timer_cd(void) { #define RHYTHM_SENSIT_K (3) static uint8_t s_run_cnt = 0, vol_val = 0; //static uint8_t s_music_keep = 0; uint8_t rhythm_pvt = 10; uint8_t adc_vol = s_app_rhythm_val;//rhythm_vol_get_cb(); 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; if (adc_vol > rhythm_pvt) { int16_t speed = (adc_vol - rhythm_pvt) / 8; if (speed >= 4) speed = 4; else if (speed <= 0) speed = 0; g_normal_rhythm.bright = MODE_JUMP_BRIGHT; g_normal_rhythm.speed = 27 - speed * 5; } else { g_normal_rhythm.bright = MODE_JUMP_MIN_BRIGHT; } 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 + 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; } } /****************************** 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; } } } } 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_sample[buff_ind] = ADC_Get_Value(); //读取adc值控制律动 //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", m_rhythm.vol_value); } return vol_value; } /****************************** mic_adc end **********************************/ void rhythm_sensit_ctrl(const int8_t sensit_step, const uint8_t rhythm_sensit) { 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; } U_UART_PRINTF("sensit = [%d] [%d] \n", g_light_para.rhythm_sensit, g_light_para.rhythm_sensit); } /* 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]); } */