#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" /********************** º¯ÊýÉùÃ÷Çø *************************/ static volatile uint8_t clientCnt; static uint8_t isGameMode = 0; static uint8_t GameModeHeartCnt = 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); SEGGER_RTT_printf(0,">>>cb_BLE_Client_R_GAMEMODE:%d\r\n",target->pDat[0]); if(1 == target->pDat[0])GameModeHeartCnt =0; } static void app_AutoOutgame_Process(void){ if(mFlash.isHost && IMU_GetGameMode()){ SEGGER_RTT_printf(0,"GameModeHeartCnt:%d\r\n",GameModeHeartCnt); if(GameModeHeartCnt++ >= 5){ isGameMode = 0; IMU_SetGameMode(isGameMode); BLE_Host_Tx_Send(0,BLE_Host_T_GAMEMODE,&isGameMode,1); } } } static void app_game_Process(void) { #if GAME_ENANBLE isGameMode = 1; IMU_SetGameMode(isGameMode); #else if(slave_isconnect()==0){ if(isGameMode>0){ isGameMode = 0; IMU_SetGameMode(isGameMode); } } #endif 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); Process_Start(60000,"app_AutoOutgame",app_AutoOutgame_Process); }