1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #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);
- }
|