app_game.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "app_game.h"
  2. #include "nrf_gpio.h"
  3. #include "usr_config.h"
  4. #include "bsp_time.h"
  5. #include "system.h"
  6. #include "hal_mt.h"
  7. #include "hal_battery.h"
  8. #include "app_charge.h"
  9. #include "hal_ble_client.h"
  10. #include "hal_ble_host.h"
  11. #include "nrf_delay.h"
  12. #include "hal_flash.h"
  13. #include "hal_imu.h"
  14. #include "ble_comm.h"
  15. #include "app_err.h"
  16. /********************** º¯ÊýÉùÃ÷Çø *************************/
  17. volatile uint8_t clientCnt;
  18. static uint8_t isGameMode = 0;
  19. void app_game_SetClientGameMode(void)
  20. {
  21. if(clientCnt!=3) clientCnt = 3;
  22. }
  23. void cb_BLE_Client_R_GAMEMODE(void* handle)
  24. {
  25. BLE_Client_Rx_t* target = handle;
  26. isGameMode = target->pDat[0];
  27. IMU_SetGameMode(isGameMode);
  28. BLE_Host_Tx_Send(0,BLE_Host_T_GAMEMODE,&isGameMode,1);
  29. }
  30. void app_game_Process(void)
  31. {
  32. if(slave_isconnect()==0){
  33. if(isGameMode>0){ isGameMode = 0;
  34. IMU_SetGameMode(isGameMode);
  35. }
  36. }
  37. if(mFlash.isHost){
  38. if(isGameMode>0){static uint8_t errCnt = 0;
  39. if(clientCnt==0){
  40. uint8_t clientMode = 1;
  41. BLE_Host_Tx_Send(0,BLE_Host_T_GAMEMODE,&clientMode,1);
  42. if(++errCnt>=10) {
  43. SEGGER_RTT_printf(0,"ERR_NUM_GAME app_game_Process\r\n");
  44. app_err_Set(ERR_NUM_GAME,1);
  45. }
  46. }else{
  47. if(errCnt>0) errCnt = 0;
  48. }
  49. }else{
  50. if(clientCnt>0){
  51. uint8_t clientMode = 0;
  52. BLE_Host_Tx_Send(0,BLE_Host_T_GAMEMODE,&clientMode,1);
  53. }
  54. }
  55. if(clientCnt>0) clientCnt--;
  56. }
  57. }
  58. void app_game_Init(void)
  59. {
  60. Process_Start(1000,"app_game",app_game_Process);
  61. BLE_Client_Rx_Regist(BLE_Client_R_GAMEMODE,cb_BLE_Client_R_GAMEMODE);
  62. }