123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #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 "app_flash.h"
- #include "ble_comm.h"
- #include "app_err.h"
- #include "hal_mode_manage.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];
- if(isGameMode){
- hal_mode_set(HAL_MODE_GAME);
- }else{
- hal_mode_set(HAL_MODE_NORMAL);
- }
- BLE_Host_Tx_Send(0,BLE_GAMEMODE,&isGameMode,1);
- if(1 == isGameMode)GameModeHeartCnt =0;
- }
- static void app_AutoOutgame_Process(void){
- if(mFlash.isHost && hal_mode_get() == HAL_MODE_GAME){
- SEGGER_RTT_printf(0,"GameModeHeartCnt:%d\r\n",GameModeHeartCnt);
- if(GameModeHeartCnt++ >= 5){
- isGameMode = 0;
- hal_mode_set(HAL_MODE_NORMAL);
- BLE_Host_Tx_Send(0,BLE_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;
- hal_mode_set(HAL_MODE_NORMAL);
- }
- }
- #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_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_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_GAMEMODE,cb_BLE_Client_R_GAMEMODE);
- Process_Start(60000,"app_AutoOutgame",app_AutoOutgame_Process);
- }
|