usr.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #include "usr.h"
  2. #include "system.h"
  3. #include "bsp_time.h"
  4. #include "nrf_delay.h"
  5. //用户初始化头文件
  6. //Add your code here...
  7. #include "twi_master.h"
  8. #include "hal_imu.h"
  9. #include "hal_ble_client.h"
  10. #include "hal_ble_host.h"
  11. #include "hal_mt.h"
  12. #include "hal_battery.h"
  13. #include "hal_mempress.h"
  14. #include "hal_led.h"
  15. #include "app_overturn.h"
  16. #include "app_charge.h"
  17. #include "app_power.h"
  18. #include "app_client.h"
  19. #include "app_host.h"
  20. #include "hal_flash.h"
  21. #include "app_step.h"
  22. #include "app_game.h"
  23. #include "hal_ble_uart0.h"
  24. #include "app_config.h"
  25. #include "app_ota.h"
  26. #include "app_connect_manage.h"
  27. #include "ble_comm.h"
  28. #include "ble_gap.h"
  29. #include "app_err.h"
  30. #include "bsp_pwm.h"
  31. #include "bsp_wdt.h"
  32. #include "bsp_adc.h"
  33. #include "tool.h"
  34. #include "hal_soft_time.h"
  35. #include "lsm6ds3tr_c.h"
  36. ////host
  37. //char sn1[] = "SH_P0";
  38. //char hn1[] = "SH_L0";
  39. ////client
  40. //char sn2[] = "SH_L0";
  41. //char hn2[] = "SH_N0";
  42. //char* HOST_NAME;
  43. //char* DEVICE_NAME;
  44. void USR_SetName(void)
  45. {
  46. char buf[16];
  47. memset(buf,0,16);
  48. if(mFlash.isHost){ //主机
  49. //slave_set_adv_name((char *) LEFT_NAME,sizeof(LEFT_NAME));
  50. if(mFlash.mClient.isConfig=='C'){ //已配置
  51. sprintf(buf,"%02X%02X%02X%02X%02X%02X",mFlash.macHost[0],mFlash.macHost[1],mFlash.macHost[2],mFlash.mClient.macAddr[3],mFlash.mClient.macAddr[4],mFlash.mClient.macAddr[5]);
  52. SEGGER_RTT_printf(0,"scanName(%d):%s\n",strlen(buf),buf);
  53. host_set_scan_name(buf,strlen(buf));
  54. }else{SEGGER_RTT_printf(0,"scanName(%d):%s\n",sizeof(RIGHT_NAME),RIGHT_NAME);
  55. host_set_scan_name((char *)RIGHT_NAME,sizeof(RIGHT_NAME));
  56. }
  57. }else{ //从机
  58. if(mFlash.mClient.isConfig=='C'){ //已配置
  59. sprintf(buf,"%02X%02X%02X%02X%02X%02X",mFlash.macHost[0],mFlash.macHost[1],mFlash.macHost[2],mFlash.mClient.macAddr[3],mFlash.mClient.macAddr[4],mFlash.mClient.macAddr[5]);
  60. SEGGER_RTT_printf(0,"advName(%d):%s\n",strlen(buf),buf);
  61. slave_set_adv_name(buf,strlen(buf));
  62. }else{ //无配置
  63. #if DEBUG
  64. slave_set_adv_name((char *)RIGHT_NAME,sizeof(RIGHT_NAME));
  65. SEGGER_RTT_printf(0,"AdvName(%d):%s\n",sizeof(RIGHT_NAME),RIGHT_NAME);
  66. #endif
  67. }
  68. host_set_scan_name((char *) LAST_NAME,sizeof(LAST_NAME));
  69. }
  70. }
  71. __weak void usr1_Init(void)
  72. {
  73. USR_SetName();
  74. slave_init(BLE_Client_Push);
  75. host_init(BLE_Host_Push);
  76. }
  77. void PRE_Init(void)
  78. {
  79. nrf_gpio_cfg_input(21,NRF_GPIO_PIN_PULLUP);//充电引脚上拉
  80. PWR_Init();
  81. LED_Init();
  82. MT_Init();
  83. Flash_Initialize();
  84. JS_RTT_Init();
  85. usr1_Init();
  86. }
  87. void USR_Init(void)
  88. {
  89. //用户初始化
  90. //Add your code here...
  91. TIME_Init();
  92. #if WATCHDOG_ENANBLE
  93. watchdog_init();
  94. #endif
  95. Battery_Initialize();
  96. IMU_Initialize();
  97. ADC_Initialize();
  98. Battery_Enable(true);
  99. BLE_Client_Initialize();
  100. BLE_Host_Initialize();
  101. //APP
  102. app_client_Initialize();
  103. app_host_Initialize();
  104. app_overturn_Init();
  105. app_charge_Init();
  106. app_step_Init();
  107. app_game_Init();
  108. app_config_Init();
  109. app_ota_Init();
  110. app_connect_manage_Init();
  111. app_err_Init();
  112. }