#include "app_connect_manage.h" #include "bsp_time.h" #include "system.h" #include "hal_mode_manage.h" #include "ble_comm.h" #include "app_flash.h" #include "app_charge.h" #include "app_ota.h" #include "app_err.h" #include "hal_ble_client.h" #include "hal_ble_host.h" #include "hal_led.h" /********************** 变量区 *************************/ /********************** 函数声明区 *************************/ extern uint8_t app_client_step_GetIsScan(void); #if BLE_LED_TEST_ENANBLE static uint8_t connect_LED_FlashFlag =0; BLE_Client_Tx_t mBLE_Client_T_CONNET_R = { .n = 10, .t = 500, .cb = 0, }; static void app_connect_LED_Flash(void) { static uint8_t cnt = 0; static uint8_t state = 0; // SEGGER_RTT_printf(0,"=======>app_connect_LED_Flash:%d\n",TIME_GetTicks()); switch(state){ case 0: Process_SetHoldOn(app_connect_LED_Flash,1); LED_Start(LED_CONNECT,COLOR_BLUE); state = 1; break; case 1: state = 0; if(++cnt >= 3){ cnt = 0; LED_Stop(LED_CONNECT); Process_SetHoldOn(app_connect_LED_Flash,0); Process_Stop(app_connect_LED_Flash); connect_LED_FlashFlag =0; // SEGGER_RTT_printf(0,"=======>out app_connect_LED_Flash\n"); } else LED_Start(LED_CONNECT,COLOR_BLACK); break; default:state=0;break; } } void cb_BLE_Client_R_CONNET_LED(void* handle) { if(0 == connect_LED_FlashFlag){ Process_Start(200,"connect_LED",app_connect_LED_Flash); SEGGER_RTT_printf(0,"====================>cb_BLE_Client_R_CONNET_LED\n"); connect_LED_FlashFlag =1; } } static BLE_Host_Tx_t mBLE_Host_T_CONNET_R = { .n = 3, .t = 100, .cb = 0, }; void app_connect_LED_Process(void) { static uint8_t flashLED = 0; if(slave_isconnect()){ if(host_isconnect()&&flashLED==0){ flashLED = 1; BLE_Client_Tx_Send(&mBLE_Client_T_CONNET_R,BLE_CONNET_R,&flashLED,1); BLE_Host_Tx_Send(&mBLE_Host_T_CONNET_R,BLE_CONNET_LED,&flashLED,1); Process_Start(200,"connect_LED",app_connect_LED_Flash); SEGGER_RTT_printf(0,"====================>BLE_Host_T_CONNET_LED\n"); } }else{ if(flashLED>0) { flashLED = 0; } } } #endif void cb_Slave_Connect(void) { SEGGER_RTT_printf(0,"=======>cb_Slave_Connect\n"); if(mFlash.isHost) slave_update_conn_interval_request(30,30); } void cb_Host_Connect(void) { SEGGER_RTT_printf(0,"=======>cb_Host_Connect\n"); // else slave_update_conn_interval_request(100,100); // Process_Start(200," ",cb_Slave_Connect_LED); } void app_connect_Process(void) { static uint8_t state = 0; static uint32_t cnt = 0; static uint16_t update_temp = 0; static uint8_t ble_con_int = 0;//左右鞋蓝牙之间的连接间隔 switch(state){ case 0:{ if((app_client_step_GetIsScan()||slave_isconnect()||(app_charge_Getstate()!=BLE_Client_T_CHARGE_PULLOUT)) && 0 == app_ota_host_state()){ SEGGER_RTT_printf(0,"=======>scan_start\n"); Process_SetHoldOn(app_connect_Process,1); scan_start(); cnt = 0; state = 1; } break;} case 1:{ if(app_client_step_GetIsScan()==0&&slave_isconnect()==0&&(app_charge_Getstate()==BLE_Client_T_CHARGE_PULLOUT)){ SEGGER_RTT_printf(0,"=======>nrf_ble_scan_stop\n"); nrf_ble_scan_stop(); Process_SetHoldOn(app_connect_Process,0); state = 0; }else if(host_isconnect()){ SEGGER_RTT_printf(0,"=======>host_isconnect\n"); Process_SetHoldOn(app_connect_Process,0); if(mFlash.isHost){ update_temp =0; ble_con_int = 0; } state =2; } if(++cnt>=100){ app_err_Set(ERR_NUM_CONNET,1); SEGGER_RTT_printf(0,"=======>app_err_Set nrf_ble_scan_stop\n"); nrf_ble_scan_stop(); Process_SetHoldOn(app_connect_Process,0); state = 0; } break;} case 2:{ if(mFlash.isHost){ if(hal_mode_get() == HAL_MODE_GAME){//游戏模式下更新连接间隔 if(ble_con_int !=2 && update_temp <= 60){ if(APP_SUCCESS == Ble_update_conn_interval(7.5,7.5)){ ble_con_int =2; update_temp =0; } else ++update_temp; } }else{ if(ble_con_int !=1 && update_temp <= 60){ if(APP_SUCCESS == Ble_update_conn_interval(100,100)){ ble_con_int =1; update_temp =0; } else update_temp++; } } } if(app_client_step_GetIsScan()==0&&slave_isconnect()==0&&(app_charge_Getstate()==BLE_Client_T_CHARGE_PULLOUT)){ if(host_isconnect()){host_disconnect(); } } if(!host_isconnect()){ SEGGER_RTT_printf(0,"=======>host_disconnect\n"); Process_SetHoldOn(app_connect_Process,0); state = 0; } break;} default:state=0;break; } } void app_connect_manage_Init(void) { if(mFlash.isHost) Process_Start(100,"app_connect",app_connect_Process); Ble_Slave_Connectd_Evt_Regist(cb_Slave_Connect); Ble_Host_Connectd_Evt_Regist(cb_Host_Connect); #if BLE_LED_TEST_ENANBLE Process_Start(100,"app_connect_led",app_connect_LED_Process); BLE_Client_Rx_Regist(BLE_CONNET_LED,cb_BLE_Client_R_CONNET_LED); #endif }