u_main.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. //#include "driver_gpio.h"
  2. //#include "Driver_uart.h"
  3. //#include "le_gap.h"
  4. #include "u_main.h"
  5. #include "u_time.h"
  6. #include "t_lev_decode.h"
  7. #include "u_pwm_drive.h"
  8. #include "u_effect_normal.h"
  9. #include "u_app_handler.h"
  10. #include "u_effect_rhythm.h"
  11. #include "u_light_ctrl.h"
  12. #include "u_power.h"
  13. #include "u_rc.h"
  14. #include "Drv_mic.h"
  15. LightPara_t g_light_para = {0x00};
  16. //extern void delay_ms(unsigned int tt);
  17. /****************** 判断是否带麦************************/
  18. void mic_estimate_gpio_int(void)
  19. {
  20. #if (firmware_is_mic==1)
  21. g_light_para.mic=1;
  22. #else
  23. g_light_para.mic=0;
  24. #endif
  25. // GPIO_config(2,2,0);
  26. // GPIO_config(3,1,2);
  27. // delay_ms(1);
  28. // if( gpio_input(2,2) ==0)
  29. // {
  30. // g_light_para.mic=0;
  31. // }else
  32. // {
  33. // g_light_para.mic=1;
  34. // }
  35. }
  36. /******************************************/
  37. void ag_timer_glo_task_cb(void)
  38. {
  39. //sys_event_sched();
  40. if (g_ir_recv_done_flag == 1)
  41. {
  42. //红外接收
  43. g_ir_recv_done_flag = 0;
  44. ir_decode(rc_decode());
  45. #ifdef DEBUG_DRV_APP
  46. U_UART_PRINTF("ir_code = %02X, %02X, %02X, %02X\n", g_ir_code[0], g_ir_code[1], g_ir_code[2], g_ir_code[3]);
  47. #endif
  48. }
  49. }
  50. void ag_timer_test_cb(void)
  51. {
  52. static uint8_t s_run_cnt = 0;
  53. s_run_cnt = s_run_cnt % 3;
  54. ++s_run_cnt;
  55. switch (s_run_cnt)
  56. {
  57. case 0:
  58. light_set_color(0x00FF00);
  59. break;
  60. case 1:
  61. light_set_color(0x0000FF);
  62. break;
  63. case 2:
  64. light_set_color(0xFF0000);
  65. break;
  66. default:
  67. break;
  68. }
  69. }
  70. /********************* 连接 断开 回调 ***********************/
  71. #if 1
  72. //蓝牙连接成功回调
  73. void u_gapc_connection_cd(void)
  74. {
  75. #ifdef DEBUG_DRV_APP
  76. U_UART_PRINTF("gapc_connect\n");
  77. #endif
  78. // if (g_light_para.app_seting & 0xF0)
  79. // {
  80. // light_power_set(GLO_EN);
  81. // }
  82. u_ag_timer_stop(AG_TIMER_ID_FLASH_SAVE);
  83. }
  84. //蓝牙连接断开回调
  85. void u_gapc_disconnect_cd(uint8_t reason)
  86. {
  87. #ifdef DEBUG_DRV_APP
  88. U_UART_PRINTF("gapc_disconnect = %d\n", reason);
  89. #endif
  90. // if (g_light_para.app_seting & 0x0F)
  91. // {
  92. // light_power_set(GLO_DIS);
  93. // }
  94. light_info_save();
  95. u_ag_timer_start(AG_TIMER_ID_FLASH_SAVE, TIMER_TIME_FLASH_SAVE, light_flash_save_cb);
  96. }
  97. #endif
  98. void u_rhythm_timer_ctrl(uint8_t timer_en)
  99. {
  100. if (timer_en)
  101. {
  102. if(g_light_para.mic_AppOrDriver == 0)
  103. {
  104. u_ag_timer_start(AG_TIMER_ID_RHYTHM, TIMER_TIME_RHYTHM, rhythm_timer_cd);
  105. }else if(g_light_para.mic_AppOrDriver == 1)
  106. {
  107. DRV_Mic_Enable();
  108. u_ag_timer_start(AG_TIMER_ID_RHYTHM, TIMER_TIME_RHYTHM, driver_rhythm_timer_cd);
  109. }
  110. //u_ag_timer_start(AG_TIMER_ID_RHYTHM, TIMER_TIME_RHYTHM, rhythm_timer_cd);
  111. }
  112. else
  113. {
  114. DRV_Mic_Disable();
  115. u_ag_timer_stop(AG_TIMER_ID_RHYTHM);
  116. }
  117. }
  118. void light_time_timer_start(void)
  119. {
  120. u_ag_timer_start(AG_TIMER_ID_LIGHT_TIME, TIMER_TIME_LIGHT_TIME, alarm_time_task);
  121. }
  122. static void light_effect_timer_cb(void)
  123. {
  124. static unsigned char i=0;
  125. switch (g_light_para.effect)
  126. {
  127. case LIGHT_EFFECT_JUMP:
  128. {
  129. light_mode_jump_timer_cb(&g_light_info);
  130. }
  131. break;
  132. case LIGHT_EFFECT_GRADUAL:
  133. {
  134. light_mode_gradual_timer_cb(&g_light_info);
  135. }
  136. break;
  137. case LIGHT_EFFECT_BREATH:
  138. {
  139. light_mode_breath_timer_cb(&g_light_info);
  140. }
  141. break;
  142. case LIGHT_EFFECT_BLINK:
  143. {
  144. light_mode_blink_timer_cb(&g_light_info);
  145. }
  146. break;
  147. default:
  148. {
  149. light_effect_timer_stop();
  150. }
  151. break;
  152. }
  153. // if (g_light_para.app_mode == LIGHT_APP_MODE_RC_AUOT)
  154. // {
  155. // rc_mode_auot_ctrl(0);
  156. // }
  157. }
  158. static uint16_t m_light_timeing = 0;
  159. void light_effect_timer_start(uint16_t timing)
  160. {
  161. if (timing != NULL)
  162. {
  163. m_light_timeing = timing;
  164. }
  165. u_ag_timer_start(AG_TIMER_ID_LIGHT_EFFECT, m_light_timeing, light_effect_timer_cb);
  166. }
  167. void light_effect_timer_stop(void)
  168. {
  169. u_ag_timer_stop(AG_TIMER_ID_LIGHT_EFFECT);
  170. }
  171. void alarm_time_reach_cb(uint8_t execute_st)
  172. {
  173. uint8_t reply_len = 0, alarm_st[24] = {0x00};
  174. #ifdef DEBUG_DRV_APP
  175. U_UART_PRINTF("alarm_time_reach_cb\n");
  176. #endif
  177. light_power_set(execute_st);
  178. light_state_upload();
  179. time_alarm_state_query(alarm_st, &reply_len);
  180. reply_app_encode(0x35, alarm_st, reply_len);
  181. }
  182. void u_init(void)
  183. {
  184. sys_param_init();
  185. rc_init();
  186. power_check_init();
  187. light_info_init();
  188. light_time_init(); //闹钟
  189. app_mode_info_init();
  190. u_ag_timer_start(AG_TIMER_ID_GLO_TASK, TIMER_TIME_GLO_TASK, ag_timer_glo_task_cb); //红外
  191. u_ag_timer_start(AG_TIMER_ID_FLASH_SAVE, TIMER_TIME_FLASH_SAVE, light_flash_save_cb); //保存数据到flash
  192. mic_estimate_gpio_int();
  193. //u_ag_timer_start(AG_TIMER_ID_TEST, TIMER_TIME_LIGHT_TEST, ag_timer_test_cb);
  194. }
  195. //uint8_t g_speed = 0;
  196. //void uart_recv_handle(uint8_t *uart_data, uint8_t recv_len)
  197. //{
  198. // if (uart_data[0] == 0x55 && uart_data[1] == 0xAA)
  199. // {
  200. //
  201. // if (uart_data[2] == 0x01)
  202. // {
  203. // light_rhythm_enter(uart_data[3]);
  204. // }
  205. // else if (uart_data[2] == 0x02)
  206. // {
  207. // //rhythm_sensit_ctrl(NULL, uart_data[3]);
  208. // g_speed = uart_data[3];
  209. // }
  210. // else if (uart_data[2] == 0x03)
  211. // {
  212. // app_rhythm_val_up(uart_data[3]);
  213. // }
  214. // }
  215. //
  216. // //U_UART_PRINTF("uart_recv %x\n", uart_data[2]);
  217. //}