u_effect_rhythm.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #include "u_effect_rhythm.h"
  2. #include "u_main.h"
  3. RhythmPara_t g_normal_rhythm = {0x00}; //全彩律动
  4. static uint8_t s_app_rhythm_val = 0x00;
  5. void u_set_one_rhythm_color(void)
  6. {
  7. //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]);
  8. }
  9. void app_rhythm_val_up(uint8_t rhythm_val)
  10. {
  11. s_app_rhythm_val = rhythm_val;
  12. U_UART_PRINTF("v = %d\n", s_app_rhythm_val);
  13. }
  14. void rhythm_timer_cd(void)
  15. {
  16. #define RHYTHM_SENSIT_K (3)
  17. static uint8_t s_run_cnt = 0, vol_val = 0;
  18. //static uint8_t s_music_keep = 0;
  19. uint8_t rhythm_pvt = 10;
  20. uint8_t adc_vol = s_app_rhythm_val;//rhythm_vol_get_cb();
  21. switch (g_light_para.rhythm_mode)
  22. {
  23. case RHYTHM_MODE_JUMP_7:
  24. case RHYTHM_MODE_JUMP_3://跳跃模式
  25. {
  26. rhythm_pvt = g_light_para.rhythm_sensit + VOT_JUMP_VPT;
  27. if (adc_vol > rhythm_pvt)
  28. {
  29. int16_t speed = (adc_vol - rhythm_pvt) / 8;
  30. if (speed >= 4)
  31. speed = 4;
  32. else if (speed <= 0)
  33. speed = 0;
  34. g_normal_rhythm.bright = MODE_JUMP_BRIGHT;
  35. g_normal_rhythm.speed = 27 - speed * 5;
  36. }
  37. else
  38. {
  39. g_normal_rhythm.bright = MODE_JUMP_MIN_BRIGHT;
  40. }
  41. light_rhythm_mode_jump_timer_cb(&g_normal_rhythm);
  42. }
  43. break;
  44. case RHYTHM_MODE_GRADUAL_7://渐变的
  45. {
  46. rhythm_pvt = 30; //g_light_para.rhythm_sensit + 10;
  47. if (adc_vol > rhythm_pvt)
  48. {
  49. int16_t speed = (adc_vol - rhythm_pvt) / 14;
  50. if (speed >= 4)
  51. speed = 4;
  52. else if (speed <= 0)
  53. speed = 0;
  54. g_normal_rhythm.bright = adc_vol;
  55. g_normal_rhythm.speed = speed;
  56. }
  57. else
  58. {
  59. g_normal_rhythm.bright = 0;
  60. }
  61. light_rhythm_mode_gradual_timer_cb(&g_normal_rhythm);
  62. }
  63. break;
  64. case RHYTHM_MODE_FADE_7:
  65. {
  66. rhythm_pvt = g_light_para.rhythm_sensit + VOT_GRADUAL_7_VPT;
  67. if (adc_vol > rhythm_pvt )
  68. {
  69. //U_UART_PRINTF(" u_pvt = %d\n", rhythm_pvt);
  70. int16_t speed = (adc_vol - rhythm_pvt) / 8;
  71. if (speed >= 4)
  72. speed = 4;
  73. else if (speed <= 0)
  74. speed = 0;
  75. g_normal_rhythm.speed = 27 - speed * 5;
  76. g_normal_rhythm.music_start = 1;
  77. //U_UART_PRINTF("f7_sd = %d\n", g_normal_rhythm.speed);
  78. }
  79. light_rhythm_mode_fade_timer_cb(&g_normal_rhythm);
  80. }
  81. break;
  82. case RHYTHM_MODE_FADE_3:
  83. {
  84. rhythm_pvt = g_light_para.rhythm_sensit + VOT_GRADUAL_3_VPT;
  85. if (adc_vol > rhythm_pvt )
  86. {
  87. //U_UART_PRINTF(" u_pvt = %d\n", rhythm_pvt);
  88. g_normal_rhythm.music_start = 1;
  89. g_normal_rhythm.speed = 15;
  90. //U_UART_PRINTF("f3_sd = %d\n", g_normal_rhythm.speed);
  91. }
  92. light_rhythm_mode_fade_timer_cb(&g_normal_rhythm);
  93. }
  94. break;
  95. }
  96. }
  97. /****************************** mic_adc **********************************/
  98. static void bubble_sort(uint8_t *sample_data,uint16_t len)
  99. {
  100. uint16_t i,j;
  101. uint16_t temp;
  102. for(j = 0; j < (len - 1); j++)
  103. {
  104. for(i=0;i<(len - 1 - j);i++)
  105. {
  106. if(sample_data[i] > sample_data[i+1])
  107. {
  108. temp = sample_data[i];
  109. sample_data[i] = sample_data[i+1];
  110. sample_data[i+1] = temp;
  111. }
  112. }
  113. }
  114. }
  115. uint8_t rhythm_vol_get_cb(void)
  116. {
  117. static uint8_t buff_ind = 0, vol_value = 0;
  118. static uint8_t adc_sample[10] = {0};
  119. //adc_temp = ADC_Get_Value();
  120. // adc_sample[buff_ind] = ADC_Get_Value(); //读取adc值控制律动
  121. //U_UART_PRINTF("adc_sample = %d\n", adc_sample[buff_ind]);
  122. buff_ind++;
  123. if (buff_ind >= 10)
  124. {
  125. int i = 0;
  126. uint16_t sample_num = 0;
  127. buff_ind = 0;
  128. bubble_sort(adc_sample, 10);
  129. for (i = 0; i < 5; i++)
  130. {
  131. sample_num += adc_sample[i+5];
  132. }
  133. vol_value = sample_num / 5;
  134. //U_UART_PRINTF("%d\n", m_rhythm.vol_value);
  135. }
  136. return vol_value;
  137. }
  138. /****************************** mic_adc end **********************************/
  139. void rhythm_sensit_ctrl(const int8_t sensit_step, const uint8_t rhythm_sensit)
  140. {
  141. uint8_t dri_rhythm_sensit = LIGHT_SENSIT_MAX - rhythm_sensit / APP_SENSIT_K;
  142. if (dri_rhythm_sensit > LIGHT_SENSIT_MAX)
  143. {
  144. return;
  145. }
  146. if (sensit_step != 0)
  147. {
  148. int8_t sensit = 0;
  149. sensit = g_light_para.rhythm_sensit + sensit_step;
  150. if (sensit >= LIGHT_SENSIT_MIN && sensit <= LIGHT_SENSIT_MAX)
  151. {
  152. g_light_para.rhythm_sensit = sensit;
  153. }
  154. else if (sensit <= LIGHT_SENSIT_MIN)
  155. {
  156. g_light_para.rhythm_sensit = LIGHT_SENSIT_MIN;
  157. }
  158. else if (sensit >= LIGHT_SENSIT_MAX)
  159. {
  160. g_light_para.rhythm_sensit = LIGHT_SENSIT_MAX;
  161. }
  162. }
  163. else
  164. {
  165. g_light_para.rhythm_sensit = dri_rhythm_sensit;
  166. }
  167. U_UART_PRINTF("sensit = [%d] [%d] \n", g_light_para.rhythm_sensit, g_light_para.rhythm_sensit);
  168. }
  169. /*
  170. void rhythm_speed_ctrl(const uint8_t rhythm_mode, const int8_t speed_step, uint8_t rhythm_speed)
  171. {
  172. uint8_t rhythm_speed_ind = 0;
  173. if (rhythm_speed > LIGHT_SPEED_MAX)
  174. {
  175. rhythm_speed = LIGHT_SPEED_MAX;
  176. }
  177. else if (rhythm_speed < LIGHT_SPEED_MIN)
  178. {
  179. rhythm_speed = LIGHT_SPEED_MIN;
  180. }
  181. if (rhythm_mode > RHYTHM_MODE_FULL_MAX)
  182. {
  183. rhythm_speed_ind = RHYTHM_SPEED_IND_DREAM;
  184. }
  185. else
  186. {
  187. rhythm_speed_ind = RHYTHM_SPEED_IND_FULL;
  188. }
  189. if (speed_step != 0)
  190. {
  191. int8_t speed = 0;
  192. speed = g_light_para.rhythm_speed[rhythm_speed_ind] + speed_step;
  193. if (speed >= LIGHT_SPEED_MIN && speed <= LIGHT_SPEED_MAX)
  194. {
  195. g_light_para.rhythm_speed[rhythm_speed_ind] = speed;
  196. }
  197. else if (speed <= LIGHT_SPEED_MIN)
  198. {
  199. g_light_para.rhythm_speed[rhythm_speed_ind] = LIGHT_SPEED_MIN;
  200. }
  201. else if (speed >= LIGHT_SPEED_MAX)
  202. {
  203. g_light_para.rhythm_speed[rhythm_speed_ind] = LIGHT_SPEED_MAX;
  204. }
  205. }
  206. else
  207. {
  208. g_light_para.rhythm_speed[rhythm_speed_ind] = rhythm_speed;
  209. }
  210. U_UART_PRINTF("speed = [%d] [%d] \n", g_light_para.rhythm_speed[0], g_light_para.rhythm_speed[1]);
  211. }
  212. */