123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- //#include "driver_gpio.h"
- //#include "Driver_uart.h"
- //#include "le_gap.h"
- #include "u_main.h"
- #include "u_time.h"
- #include "t_lev_decode.h"
- #include "u_pwm_drive.h"
- #include "u_effect_normal.h"
- #include "u_app_handler.h"
- #include "u_effect_rhythm.h"
- #include "u_light_ctrl.h"
- #include "u_power.h"
- #include "u_rc.h"
- #include "Drv_mic.h"
- LightPara_t g_light_para = {0x00};
- //extern void delay_ms(unsigned int tt);
- /****************** 判断是否带麦************************/
- void mic_estimate_gpio_int(void)
- {
- #if (firmware_is_mic==1)
- g_light_para.mic=1;
- #else
- g_light_para.mic=0;
- #endif
- // GPIO_config(2,2,0);
- // GPIO_config(3,1,2);
- // delay_ms(1);
- // if( gpio_input(2,2) ==0)
- // {
- // g_light_para.mic=0;
- // }else
- // {
- // g_light_para.mic=1;
- // }
- }
- /******************************************/
- void ag_timer_glo_task_cb(void)
- {
- //sys_event_sched();
- if (g_ir_recv_done_flag == 1)
- {
- //红外接收
- g_ir_recv_done_flag = 0;
-
- ir_decode(rc_decode());
- #ifdef DEBUG_DRV_APP
- 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]);
- #endif
- }
- }
- void ag_timer_test_cb(void)
- {
- static uint8_t s_run_cnt = 0;
- s_run_cnt = s_run_cnt % 3;
- ++s_run_cnt;
- switch (s_run_cnt)
- {
- case 0:
- light_set_color(0x00FF00);
- break;
- case 1:
- light_set_color(0x0000FF);
- break;
- case 2:
- light_set_color(0xFF0000);
- break;
- default:
- break;
- }
-
- }
- /********************* 连接 断开 回调 ***********************/
- #if 1
- //蓝牙连接成功回调
- void u_gapc_connection_cd(void)
- {
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("gapc_connect\n");
- #endif
- // if (g_light_para.app_seting & 0xF0)
- // {
- // light_power_set(GLO_EN);
- // }
- u_ag_timer_stop(AG_TIMER_ID_FLASH_SAVE);
- }
- //蓝牙连接断开回调
- void u_gapc_disconnect_cd(uint8_t reason)
- {
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("gapc_disconnect = %d\n", reason);
- #endif
- // if (g_light_para.app_seting & 0x0F)
- // {
- // light_power_set(GLO_DIS);
- // }
- light_info_save();
- u_ag_timer_start(AG_TIMER_ID_FLASH_SAVE, TIMER_TIME_FLASH_SAVE, light_flash_save_cb);
- }
- #endif
- void u_rhythm_timer_ctrl(uint8_t timer_en)
- {
- if (timer_en)
- {
- if(g_light_para.mic_AppOrDriver == 0)
- {
- u_ag_timer_start(AG_TIMER_ID_RHYTHM, TIMER_TIME_RHYTHM, rhythm_timer_cd);
-
- }else if(g_light_para.mic_AppOrDriver == 1)
- {
- DRV_Mic_Enable();
- u_ag_timer_start(AG_TIMER_ID_RHYTHM, TIMER_TIME_RHYTHM, driver_rhythm_timer_cd);
- }
- //u_ag_timer_start(AG_TIMER_ID_RHYTHM, TIMER_TIME_RHYTHM, rhythm_timer_cd);
-
- }
- else
- {
- DRV_Mic_Disable();
- u_ag_timer_stop(AG_TIMER_ID_RHYTHM);
- }
- }
- void light_time_timer_start(void)
- {
- u_ag_timer_start(AG_TIMER_ID_LIGHT_TIME, TIMER_TIME_LIGHT_TIME, alarm_time_task);
- }
- static void light_effect_timer_cb(void)
- {
- static unsigned char i=0;
- switch (g_light_para.effect)
- {
- case LIGHT_EFFECT_JUMP:
- {
- light_mode_jump_timer_cb(&g_light_info);
- }
- break;
- case LIGHT_EFFECT_GRADUAL:
- {
- light_mode_gradual_timer_cb(&g_light_info);
- }
- break;
- case LIGHT_EFFECT_BREATH:
- {
- light_mode_breath_timer_cb(&g_light_info);
- }
- break;
- case LIGHT_EFFECT_BLINK:
- {
- light_mode_blink_timer_cb(&g_light_info);
- }
- break;
-
- default:
- {
- light_effect_timer_stop();
- }
- break;
- }
- // if (g_light_para.app_mode == LIGHT_APP_MODE_RC_AUOT)
- // {
- // rc_mode_auot_ctrl(0);
- // }
- }
- static uint16_t m_light_timeing = 0;
- void light_effect_timer_start(uint16_t timing)
- {
- if (timing != NULL)
- {
- m_light_timeing = timing;
- }
- u_ag_timer_start(AG_TIMER_ID_LIGHT_EFFECT, m_light_timeing, light_effect_timer_cb);
- }
- void light_effect_timer_stop(void)
- {
- u_ag_timer_stop(AG_TIMER_ID_LIGHT_EFFECT);
- }
- void alarm_time_reach_cb(uint8_t execute_st)
- {
- uint8_t reply_len = 0, alarm_st[24] = {0x00};
- #ifdef DEBUG_DRV_APP
- U_UART_PRINTF("alarm_time_reach_cb\n");
- #endif
- light_power_set(execute_st);
- light_state_upload();
- time_alarm_state_query(alarm_st, &reply_len);
- reply_app_encode(0x35, alarm_st, reply_len);
- }
- void u_init(void)
- {
- sys_param_init();
- rc_init();
- power_check_init();
- light_info_init();
- light_time_init(); //闹钟
- app_mode_info_init();
-
- u_ag_timer_start(AG_TIMER_ID_GLO_TASK, TIMER_TIME_GLO_TASK, ag_timer_glo_task_cb); //红外
- u_ag_timer_start(AG_TIMER_ID_FLASH_SAVE, TIMER_TIME_FLASH_SAVE, light_flash_save_cb); //保存数据到flash
- mic_estimate_gpio_int();
- //u_ag_timer_start(AG_TIMER_ID_TEST, TIMER_TIME_LIGHT_TEST, ag_timer_test_cb);
-
- }
- //uint8_t g_speed = 0;
- //void uart_recv_handle(uint8_t *uart_data, uint8_t recv_len)
- //{
- // if (uart_data[0] == 0x55 && uart_data[1] == 0xAA)
- // {
- //
- // if (uart_data[2] == 0x01)
- // {
- // light_rhythm_enter(uart_data[3]);
- // }
- // else if (uart_data[2] == 0x02)
- // {
- // //rhythm_sensit_ctrl(NULL, uart_data[3]);
- // g_speed = uart_data[3];
- // }
- // else if (uart_data[2] == 0x03)
- // {
- // app_rhythm_val_up(uart_data[3]);
- // }
- // }
- //
- // //U_UART_PRINTF("uart_recv %x\n", uart_data[2]);
- //}
|