#include "app_game.h" #include "nrf_gpio.h" #include "usr_config.h" #include "bsp_time.h" #include "system.h" #include "hal_mt.h" #include "hal_battery.h" #include "app_charge.h" #include "hal_ble_client.h" #include "hal_ble_host.h" #include "nrf_delay.h" #include "hal_flash.h" #include "hal_imu.h" #include "ble_comm.h" #include "app_err.h" /********************** º¯ÊýÉùÃ÷Çø *************************/ volatile uint8_t clientCnt; static uint8_t isGameMode = 0; void app_game_SetClientGameMode(void) { if(clientCnt!=3) clientCnt = 3; } void cb_BLE_Client_R_GAMEMODE(void* handle) { BLE_Client_Rx_t* target = handle; isGameMode = target->pDat[0]; IMU_SetGameMode(isGameMode); BLE_Host_Tx_Send(0,BLE_Host_T_GAMEMODE,&isGameMode,1); } void app_game_Process(void) { if(slave_isconnect()==0){ if(isGameMode>0){ isGameMode = 0; IMU_SetGameMode(isGameMode); } } if(mFlash.isHost){ if(isGameMode>0){static uint8_t errCnt = 0; if(clientCnt==0){ uint8_t clientMode = 1; BLE_Host_Tx_Send(0,BLE_Host_T_GAMEMODE,&clientMode,1); if(++errCnt>=10) { SEGGER_RTT_printf(0,"ERR_NUM_GAME app_game_Process\r\n"); app_err_Set(ERR_NUM_GAME,1); } }else{ if(errCnt>0) errCnt = 0; } }else{ if(clientCnt>0){ uint8_t clientMode = 0; BLE_Host_Tx_Send(0,BLE_Host_T_GAMEMODE,&clientMode,1); } } if(clientCnt>0) clientCnt--; } } void app_game_Init(void) { Process_Start(1000,"app_game",app_game_Process); BLE_Client_Rx_Regist(BLE_Client_R_GAMEMODE,cb_BLE_Client_R_GAMEMODE); }