selfcheck.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. /*Includes ----------------------------------------------*/
  2. #include "tool.h"
  3. #include "hal_MahonyAHRS.h"
  4. #include "ble_comm.h"
  5. #include "nrf_delay.h"
  6. #include "bsp_pwm.h"
  7. #include "bsp_time.h"
  8. #include "fml_adc.h"
  9. #include "bsp_wdt.h"
  10. #include "exception.h"
  11. #include "selfcheck.h"
  12. #include "system.h"
  13. #include "drv_qma7981.h"
  14. #include "hal_led.h"
  15. #include "hal_battery.h"
  16. #include "bll_imu.h"
  17. #include "app_flash.h"
  18. #include "system.h"
  19. #include "hal_mahonyAHRS.h"
  20. #include "app_detectIsHost.h"
  21. /*Private macro ------------------------------------------------------------------------------------------------------------------------------------*/
  22. #define SELFCHECK_SCAN_DEVICE_RSSI_MIN_THRESHOLD -60 //需要扫描的设备的RSSI最小阈值,-76
  23. #define SELFCHECK_CHARGE_CHIP_PIN_ADC_MIN_THRESHOLD 80 //充电芯片引脚的最小ADC阈值
  24. #define SELFCHECK_BATTERY_PIN_ADC_MIN_THRESHOLD 3300 //电池分压电阻的最小ADC阈值
  25. #define SELFCHECK_BATTERY_PIN_ADC_MAX_THRESHOLD 4300 //电池分压电阻的最大ADC阈值,拆掉电阻后,原始值为3721,换算为5.49V
  26. #define SELFCHECK_MIDDLE_ACC_PROS_ROLL_MIN_THRESHOLD 0 //中间加速度正向ROLL值最小阈值
  27. #define SELFCHECK_MIDDLE_ACC_PROS_ROLL_MAX_THRESHOLD 35 //中间加速度正向ROLL值最大阈值
  28. #define SELFCHECK_MIDDLE_ACC_CONS_ROLL_MIN_THRESHOLD 160 //中间加速度反向ROLL值最小阈值
  29. #define SELFCHECK_MIDDLE_ACC_CONS_ROLL_MAX_THRESHOLD 180 //中间加速度反向ROLL值最大阈值
  30. #define SELFCHECK_WEAR_INSOLE_MAG_NORM_MIN_THRESHOLD 5000 //穿鞋垫的地磁norm值最小阈值
  31. #define SELFCHECK_SENSOR_MAG_NO_WELDING_CAPACITOR_MIN_THRESHOLD 200 //地磁传感器没焊接电容的最小阈值
  32. #define SELFCHECK_LED_DISPLAY_CYCLE_THRESHOLD 200 //自检灯显示周期时间,单位ms
  33. #define SELFCHECK_MIDDLE_ACC_CHECK_MT_MIN_THRESHOLD 1500 //中间加速度检测电机最小差值,不震动的差值是129,有个能震动的差值是1800+
  34. #define SELFCHECK_IMU_MONITOR_DATA_ERR_SUM_MAX 416 //数据监测错误累计最大值
  35. /*STRUCTION ------------------------------------------------------------------------------------------------------------------------------------*/
  36. typedef enum {
  37. SELFCHECK_RESULT_SUCCESS = 0, //自检成功
  38. SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_SIX_AXIS_ID, //自检失败——前脚传感器配置六轴ID
  39. SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_MAG_ID, //自检失败——前脚传感器配置地磁ID
  40. SELFCHECK_RESULT_ERR_BACK_SENSOR_CONFIG_ID, //自检失败——后脚传感器配置地磁ID
  41. SELFCHECK_RESULT_ERR_CHARGE_CHIP_PIN_ADC, //自检失败——充电芯片引脚ADC
  42. SELFCHECK_RESULT_ERR_BATTERY_PIN_ADC, //自检失败——电池分压电阻ADC
  43. SELFCHECK_RESULT_ERR_RSSI, //自检失败——RSSI
  44. SELFCHECK_RESULT_ERR_MT, //自检失败——震动电机
  45. SELFCHECK_RESULT_ERR_FRONT_IMU_REVERSE, //自检失败——前脚传感器装反
  46. SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_SIX_AXIS, //自检失败——前脚传感器配置六轴
  47. SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_MAG, //自检失败——前脚传感器配置地磁
  48. SELFCHECK_RESULT_ERR_FRONT_SIX_AXIS_NO_DATA, //自检失败——前脚传感器六轴没数据
  49. SELFCHECK_RESULT_ERR_FRONT_SIX_AXIS_EXCP_DATA, //自检失败——前脚传感器六轴数据异常(数据持续相等)
  50. SELFCHECK_RESULT_ERR_FRONT_MAG_NO_DATA, //自检失败——前脚传感器地磁没数据
  51. SELFCHECK_RESULT_ERR_FRONT_MAG_EXCP_DATA, //自检失败——前脚传感器地磁数据异常(数据持续相等)
  52. SELFCHECK_RESULT_ERR_FRONT_MAG_DATA_TO_SMALL, //自检失败——前脚传感器地磁数据过小
  53. SELFCHECK_RESULT_ERR_BACK_SENSOR_CONFIG, //自检失败——后脚传感器配置
  54. SELFCHECK_RESULT_ERR_BACK_NO_DATA, //自检失败——后脚传感器没数据
  55. SELFCHECK_RESULT_ERR_BACK_EXCP_DATA, //自检失败——后脚传感器数据异常(数据持续相等)
  56. SELFCHECK_RESULT_ERR_BACK_DATA_TO_SMALL, //自检失败——后脚传感器地磁数据过小
  57. SELFCHECK_RESULT_ERR_MIDDLE_SENSOR_CONFIG, //自检失败——中间传感器配置
  58. SELFCHECK_RESULT_ERR_MIDDLE_NO_DATA_OR_EXCP_DATA, //自检失败——中间传感器没数据或数据异常
  59. } SELFCHECK_RESULT_e;
  60. typedef struct _selfcheck
  61. {
  62. uint32_t selfcheck_result; //自检结果
  63. uint32_t selfcheck_result_led_color; //自检结果的led灯颜色
  64. uint32_t selfcheck_result_flash_num; //自检结果闪烁次数
  65. int16_t max_rssi; //最大的RSSI值
  66. fml_imu_data_t f_data; //前脚传感器数据
  67. fml_imu_data_t b_data; //后脚传感器数据
  68. qma_data_t m_data; //中间传感器数据
  69. bool f_is_read_data; //前脚传感器是否读到数据标志位
  70. bool b_is_read_data; //后脚传感器是否读到数据标志位
  71. char order; //指令
  72. } SelfCheck_t;
  73. /*Local Variable ------------------------------------------------------------------------------------------------------------------------------------*/
  74. static SelfCheck_t ob_selfcheck;
  75. static const bll_imu_one_way_param_t game_front_param={
  76. .acc_power_mode = FML_IMU_ACC_POWER_MODE_NORMAL, //前脚 - 加速度正常模式
  77. .gry_power_mode = FML_IMU_GRY_POWER_MODE_NORMAL, //前脚 - 陀螺仪正常模式
  78. .timestamp_resolution = FML_IMU_TIMESTAMP_25US, //前脚 - 时间戳25US精度
  79. .timestamp_switch = FML_IMU_TIMESTAMP_ON, //前脚 - 时间戳开启
  80. .acc_fs = FML_IMU_ACC_FS_16G, //前脚 - 加速度量程 - 16G
  81. .gry_fs = FML_IMU_GRY_FS_2000DPS, //前脚 - 陀螺仪量程 - 2000DPS
  82. .mag_fs = FML_IMU_MAG_FS_30GS, //前脚 - 地磁计量程 - 30GS
  83. .acc_odr = FML_IMU_ACC_ODR_416HZ, //前脚 - 加速度采样频率 - 104HZ
  84. .gry_odr = FML_IMU_GRY_ODR_416HZ, //前脚 - 陀螺仪采样频率 - 104HZ
  85. .mag_odr = FML_IMU_MAG_ODR_200HZ, //前脚 - 地磁计采样频率 - 200HZ
  86. .fifo_odr = FML_IMU_FIFO_ODR_416HZ,
  87. };
  88. static const bll_imu_one_way_param_t game_back_param={
  89. .acc_power_mode = FML_IMU_ACC_POWER_MODE_NORMAL, //后脚 - 加速度正常模式
  90. .gry_power_mode = FML_IMU_GRY_POWER_MODE_NORMAL, //后脚 - 陀螺仪正常模式
  91. .timestamp_resolution = FML_IMU_TIMESTAMP_25US, //后脚 - 时间戳25US精度
  92. .timestamp_switch = FML_IMU_TIMESTAMP_OFF, //后脚 - 时间戳关闭
  93. .acc_fs = FML_IMU_ACC_FS_16G, //后脚 - 加速度量程 - 16G
  94. .gry_fs = FML_IMU_GRY_FS_2000DPS, //后脚 - 陀螺仪量程 - 2000DPS
  95. .mag_fs = FML_IMU_MAG_FS_30GS, //后脚 - 地磁计量程 - 30GS
  96. .acc_odr = FML_IMU_ACC_ODR_OFF, //后脚 - 加速度采样频率 - 关闭
  97. .gry_odr = FML_IMU_GRY_ODR_OFF, //后脚 - 陀螺仪采样频率 - 关闭
  98. .mag_odr = FML_IMU_MAG_ODR_200HZ, //后脚 - 地磁计采样频率 - 200HZ
  99. .fifo_odr = FML_IMU_FIFO_ODR_OFF,
  100. };
  101. static const bll_imu_param_t game_bll_imu_param_t={
  102. .config_param[FML_IMU_DIR_FRONT] = &game_front_param,
  103. .config_param[FML_IMU_DIR_BACK] = &game_back_param,
  104. };
  105. static MahonyAHRS_t Self_Mind_Mahony={0};
  106. static MahonyAHRS_t Self_Front_Mahony={0};
  107. /*Local Functions ------------------------------------------------------------------------------------------------------------------------------------*/
  108. static void monitor_sensor_data(int16_t *f_acc, int16_t *f_gry, int16_t *f_mag, int16_t *b_mag)
  109. {
  110. static int16_t last_f_acc[3]; //上一次的前脚加速度值
  111. static int16_t last_f_gry[3]; //上一次的前脚陀螺仪值
  112. static int16_t last_f_mag[3]; //上一次的前脚地磁计值
  113. static int16_t last_b_mag[3]; //上一次的后脚地磁计值
  114. static int16_t last_f_acc_err_sum; //上一次的前脚加速度值错误累计
  115. static int16_t last_f_gry_err_sum; //上一次的前脚陀螺仪值错误累计
  116. static int16_t last_f_mag_err_sum; //上一次的前脚地磁计值错误累计
  117. static int16_t last_b_mag_err_sum; //上一次的后脚地磁计值错误累计
  118. /*前脚加速度*/
  119. if(f_acc != NULL)
  120. {
  121. if(
  122. last_f_acc[0] == f_acc[0] && \
  123. last_f_acc[1] == f_acc[1] && \
  124. last_f_acc[2] == f_acc[2]
  125. )
  126. {
  127. last_f_acc_err_sum++;
  128. if(last_f_acc_err_sum >= SELFCHECK_IMU_MONITOR_DATA_ERR_SUM_MAX){
  129. ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_SIX_AXIS_EXCP_DATA);
  130. }
  131. }else{
  132. last_f_acc_err_sum = 0;
  133. }
  134. last_f_acc[0] = f_acc[0];
  135. last_f_acc[1] = f_acc[1];
  136. last_f_acc[2] = f_acc[2];
  137. }
  138. /*前脚陀螺仪*/
  139. if(f_gry != NULL)
  140. {
  141. if(
  142. last_f_gry[0] == f_gry[0] && \
  143. last_f_gry[1] == f_gry[1] && \
  144. last_f_gry[2] == f_gry[2]
  145. )
  146. {
  147. last_f_gry_err_sum++;
  148. if(last_f_gry_err_sum >= SELFCHECK_IMU_MONITOR_DATA_ERR_SUM_MAX){
  149. ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_SIX_AXIS_EXCP_DATA);
  150. }
  151. }else{
  152. last_f_gry_err_sum = 0;
  153. }
  154. last_f_gry[0] = f_gry[0];
  155. last_f_gry[1] = f_gry[1];
  156. last_f_gry[2] = f_gry[2];
  157. }
  158. /*前脚地磁计*/
  159. if(f_mag != NULL)
  160. {
  161. if(
  162. last_f_mag[0] == f_mag[0] && \
  163. last_f_mag[1] == f_mag[1] && \
  164. last_f_mag[2] == f_mag[2]
  165. )
  166. {
  167. last_f_mag_err_sum++;
  168. if(last_f_mag_err_sum >= SELFCHECK_IMU_MONITOR_DATA_ERR_SUM_MAX){
  169. ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_MAG_EXCP_DATA);
  170. }
  171. }else{
  172. last_f_mag_err_sum = 0;
  173. }
  174. last_f_mag[0] = f_mag[0];
  175. last_f_mag[1] = f_mag[1];
  176. last_f_mag[2] = f_mag[2];
  177. }
  178. /*后脚地磁计*/
  179. if(b_mag != NULL)
  180. {
  181. if(
  182. last_b_mag[0] == b_mag[0] && \
  183. last_b_mag[1] == b_mag[1] && \
  184. last_b_mag[2] == b_mag[2]
  185. )
  186. {
  187. last_b_mag_err_sum++;
  188. if(last_b_mag_err_sum >= (SELFCHECK_IMU_MONITOR_DATA_ERR_SUM_MAX/2)){
  189. ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_BACK_EXCP_DATA);
  190. }
  191. }else{
  192. last_b_mag_err_sum = 0;
  193. }
  194. last_b_mag[0] = b_mag[0];
  195. last_b_mag[1] = b_mag[1];
  196. last_b_mag[2] = b_mag[2];
  197. }
  198. }
  199. static void fb_data_notify_cb(uint32_t dir_bit)
  200. {
  201. int data_len;
  202. if((dir_bit >> BLL_IMU_DIR_FRONT) & 0x01)
  203. {
  204. memset(&ob_selfcheck.f_data,0,sizeof(ob_selfcheck.f_data));
  205. data_len = bll_imu_get_data_num(BLL_IMU_DIR_FRONT);
  206. for(int i=0; i<data_len;i++)
  207. {
  208. bll_imu_get_data(BLL_IMU_DIR_FRONT, i, &ob_selfcheck.f_data);
  209. }
  210. monitor_sensor_data(ob_selfcheck.f_data.acc, ob_selfcheck.f_data.gry, ob_selfcheck.f_data.mag, NULL);
  211. Mahony_update(&Self_Front_Mahony,0,0,0,ob_selfcheck.f_data.acc[0],ob_selfcheck.f_data.acc[1],ob_selfcheck.f_data.acc[2],0,0,0);
  212. }
  213. if((dir_bit >> BLL_IMU_DIR_BACK) & 0x01)
  214. {
  215. memset(&ob_selfcheck.b_data,0,sizeof(ob_selfcheck.b_data));
  216. data_len = bll_imu_get_data_num(BLL_IMU_DIR_BACK);
  217. for(int i=0; i<data_len;i++)
  218. {
  219. bll_imu_get_data(BLL_IMU_DIR_BACK, i, &ob_selfcheck.b_data);
  220. }
  221. monitor_sensor_data(NULL, NULL, NULL, ob_selfcheck.b_data.mag);
  222. }
  223. if(((dir_bit >> BLL_IMU_DIR_FRONT) & 0x01))
  224. {
  225. ob_selfcheck.f_is_read_data = true;
  226. }
  227. if((dir_bit >> BLL_IMU_DIR_BACK))
  228. {
  229. ob_selfcheck.b_is_read_data = true;
  230. }
  231. }
  232. static void scan_report_cb(ble_gap_evt_adv_report_t const * p_adv_report)
  233. {
  234. ob_selfcheck.max_rssi = (ob_selfcheck.max_rssi > p_adv_report->rssi)?ob_selfcheck.max_rssi:p_adv_report->rssi;
  235. }
  236. static void selfcheck_result_display_process(void)
  237. {
  238. static uint32_t led_display_count = 0;
  239. //根据自检结果显示结果:
  240. //前脚传感器——红色(前脚六轴配置问题闪烁1下,前脚地磁配置问题闪烁2下,前脚六轴数据读取失败或数据异常闪烁3下,前脚地磁数据读取失败或数据异常闪烁4下)
  241. //后脚传感器——红色(后脚地磁配置问题闪烁5下,后脚地磁数据读取失败或数据异常闪烁6下)
  242. //中间传感器——红色(中间加速度配置问题闪烁7下,加速度roll值不在范围内闪烁8下)
  243. //充电芯片和电池分压电阻和蓝牙天线rssi——红色(充电芯片问题闪烁9下,电池分压电阻闪烁10下,蓝牙天线rssi问题闪烁11下)
  244. //中间加速度检测震动电机(待定)
  245. //上述检测通过,蓝色(1秒周期,500ms亮,500ms灭(断电源线)),若检测到鞋垫,则绿色(1秒周期,500ms亮,500ms灭(断电源线))。
  246. //LED电源引脚亮灯拉高,灭灯拉低。(4秒周期,40ms亮,160ms灭(断电源线)一组)
  247. //喂狗
  248. feed_watchdog();
  249. Process_UpdatePeroid(selfcheck_result_display_process,SELFCHECK_LED_DISPLAY_CYCLE_THRESHOLD);
  250. led_display_count++;
  251. if(led_display_count % 2 == 0)
  252. {
  253. WS2812_DisplayDot(COLOR_BLACK);WS2812_Pwm_Play();
  254. }
  255. else
  256. {
  257. WS2812_DisplayDot(ob_selfcheck.selfcheck_result_led_color);WS2812_Pwm_Play();
  258. }
  259. if(led_display_count >= ob_selfcheck.selfcheck_result_flash_num * 2)
  260. {
  261. led_display_count = 0;
  262. WS2812_DisplayDot(COLOR_BLACK);WS2812_Pwm_Play();
  263. Process_UpdatePeroid(selfcheck_result_display_process,SELFCHECK_LED_DISPLAY_CYCLE_THRESHOLD * 3);
  264. }
  265. }
  266. static void selfcheck_led_process(void)
  267. {
  268. //喂狗
  269. feed_watchdog();
  270. static uint8_t flow = 0;
  271. switch(flow)
  272. {
  273. case 0:
  274. WS2812_DisplayDot(COLOR_RED);WS2812_Pwm_Play();
  275. flow = 1;
  276. break;
  277. case 1:
  278. WS2812_DisplayDot(COLOR_GREEN);WS2812_Pwm_Play();
  279. flow = 2;
  280. break;
  281. case 2:
  282. WS2812_DisplayDot(COLOR_BLUE);WS2812_Pwm_Play();
  283. flow = 0;
  284. break;
  285. }
  286. nrf_gpio_pin_write(PIN_MT_EN,1);//这样有200ms的时间获取静止状态下的中间acc的z轴
  287. }
  288. static void selfcheck_mt_process(void)
  289. {
  290. static int16_t max_acc_z = 0;
  291. static int16_t min_acc_z = 32767;
  292. int16_t acc_z = 0;
  293. //喂狗
  294. feed_watchdog();
  295. //检测震动是否达标
  296. //读取中间传感器数据,计算加速度roll值
  297. if(ob_selfcheck.order == 0x52)
  298. {
  299. memset(&ob_selfcheck.m_data,0,sizeof(ob_selfcheck.m_data));
  300. if(drv_qma_get_acc_data(&ob_selfcheck.m_data) == 0)
  301. {
  302. if(ob_selfcheck.m_data.acc[0]==0 && ob_selfcheck.m_data.acc[1]==0 && ob_selfcheck.m_data.acc[2]==0)return;
  303. if(ob_selfcheck.m_data.acc[0]==-1 && ob_selfcheck.m_data.acc[1]==-1 && ob_selfcheck.m_data.acc[2]==-1)return;
  304. if(ob_selfcheck.m_data.acc[2] < 0)acc_z = ob_selfcheck.m_data.acc[2]*-1;
  305. else acc_z = ob_selfcheck.m_data.acc[2];
  306. max_acc_z = (max_acc_z > acc_z)?max_acc_z:acc_z;
  307. min_acc_z = (min_acc_z > acc_z)?acc_z:min_acc_z;
  308. if((max_acc_z - min_acc_z) < SELFCHECK_MIDDLE_ACC_CHECK_MT_MIN_THRESHOLD)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_MT);
  309. else ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_MT);
  310. // SEGGER_RTT_printf(0,"middle acc %d,%d,%d acc_z:%d,max:%d,min:%d,%d\r\n",ob_selfcheck.m_data.acc[0],ob_selfcheck.m_data.acc[1],ob_selfcheck.m_data.acc[2],acc_z,max_acc_z,min_acc_z,max_acc_z-min_acc_z);
  311. }
  312. }
  313. }
  314. #define N 10 //N > 3
  315. int data[N];
  316. int middleFilter(int in_data)
  317. {
  318. int sum = 0;
  319. int temp[N];
  320. int change;
  321. int i,j;
  322. //记录数据
  323. for(i=0; i<(N-1); i++)
  324. {
  325. data[i]=data[i+1];
  326. }
  327. data[N-1] = in_data;
  328. //复制数据
  329. for(i=0; i<N; i++)
  330. temp[i] = data[i];
  331. //冒泡法排序
  332. for(i=1; i<N; i++)
  333. for(j=0; j<N-i; j++)
  334. {
  335. if(temp[i] > temp[i+1])
  336. {
  337. change = temp[i];
  338. temp[i] = temp[i+1];
  339. temp[i+1] = change;
  340. }
  341. }
  342. //求和
  343. for(i=1; i<(N-1); i++)
  344. sum = sum + temp[i];
  345. //返回平均值
  346. return(sum/((N-2)));
  347. }
  348. static void selfcheck_process(void)
  349. {
  350. BLL_IMU_CONFIG_RESULT f_config_result,b_config_result;
  351. int16_t adc_value = 0;
  352. uint16_t front_mag_norm;
  353. uint16_t back_mag_norm;
  354. int16_t roll;
  355. uint8_t buf[256];
  356. uint8_t L=0;
  357. char mac_buf[16];
  358. static uint32_t charge_chip_adc_max = 0;
  359. static int16_t battery_adc_max = 0;
  360. static uint32_t t_count = 0;
  361. static uint32_t battery_adc_t_count = 0;
  362. static uint32_t roll_t_count = 0;
  363. static uint32_t sensor_t_count = 0;
  364. static uint32_t last_tim = 0;
  365. static uint32_t continue_trigger = 0;
  366. t_count++;
  367. //喂狗
  368. feed_watchdog();
  369. //读取中间传感器数据,计算加速度roll值
  370. memset(&ob_selfcheck.m_data,0,sizeof(ob_selfcheck.m_data));
  371. if(drv_qma_get_acc_data(&ob_selfcheck.m_data) != 0)
  372. {
  373. ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_MIDDLE_NO_DATA_OR_EXCP_DATA);
  374. //重新配置
  375. drv_qma_set_acc_odr(QMA_ACC_ODR_104HZ);
  376. }
  377. Mahony_update(&Self_Mind_Mahony,0,0,0,ob_selfcheck.m_data.acc[0],ob_selfcheck.m_data.acc[1],ob_selfcheck.m_data.acc[2],0,0,0);
  378. //筛选最大的电池分压后的电压
  379. fml_adc_get_value(PIN_ADC_BAT_CHANNEL,&adc_value);
  380. adc_value = ADC_RESULT_IN_MILLI_VOLTS(adc_value) * 5 / 3;
  381. battery_adc_max = middleFilter(adc_value);
  382. //每3秒读取ADC,以5V电压测试电池分压电阻是否焊接,不考虑阻值,设置自检结果。
  383. if(t_count - battery_adc_t_count > (3000/100))
  384. {
  385. if(!(SELFCHECK_BATTERY_PIN_ADC_MIN_THRESHOLD < battery_adc_max && battery_adc_max < SELFCHECK_BATTERY_PIN_ADC_MAX_THRESHOLD))ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_BATTERY_PIN_ADC);
  386. else ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_BATTERY_PIN_ADC);
  387. //更新计时
  388. battery_adc_t_count = t_count;
  389. }
  390. //充电芯片检测
  391. fml_adc_get_value(PIN_ADC_CHARGMEASURE_CHANNEL,&adc_value);
  392. if(SELFCHECK_CHARGE_CHIP_PIN_ADC_MIN_THRESHOLD < adc_value)
  393. {
  394. charge_chip_adc_max++;
  395. }
  396. if(charge_chip_adc_max > 10)
  397. {
  398. ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_CHARGE_CHIP_PIN_ADC);
  399. }
  400. else
  401. {
  402. ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_CHARGE_CHIP_PIN_ADC);
  403. }
  404. //每3秒检测加速度roll值,设置自检结果。
  405. if(t_count - roll_t_count > (3000/100))
  406. {
  407. roll = (int16_t)(Self_Mind_Mahony.roll*100);
  408. if(roll < 0)roll *= -1;
  409. roll = (roll > 0 && roll < 100)?1:roll/100;
  410. if(!( \
  411. (SELFCHECK_MIDDLE_ACC_PROS_ROLL_MIN_THRESHOLD < roll && roll < SELFCHECK_MIDDLE_ACC_PROS_ROLL_MAX_THRESHOLD) || \
  412. (SELFCHECK_MIDDLE_ACC_CONS_ROLL_MIN_THRESHOLD < roll && roll < SELFCHECK_MIDDLE_ACC_CONS_ROLL_MAX_THRESHOLD) \
  413. ))ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_MIDDLE_NO_DATA_OR_EXCP_DATA);
  414. else
  415. ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_MIDDLE_NO_DATA_OR_EXCP_DATA);
  416. //更新计时
  417. roll_t_count = t_count;
  418. }
  419. //每1秒查看前后传感器是否配置且读取成功(至少要1秒才有结果)且值本身是否正常(如地磁没有焊接电容),设置自检结果。
  420. if(t_count - sensor_t_count > (1000/100))
  421. {
  422. //前脚传感器判断
  423. f_config_result = bll_imu_query_config_param_is_ready(BLL_IMU_DIR_FRONT,&game_bll_imu_param_t);
  424. if(f_config_result != BLL_IMU_CONFIG_FINISH)
  425. {
  426. if(f_config_result == BLL_IMU_CONFIG_FAIL_FRONT_SIX_AXIS_GET_ID)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_SIX_AXIS_ID);
  427. if(f_config_result == BLL_IMU_CONFIG_FAIL_FRONT_MAG_GET_ID)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_MAG_ID);
  428. if(f_config_result == BLL_IMU_CONFIG_FAIL_FRONT_MAG)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_MAG);
  429. if(f_config_result == BLL_IMU_CONFIG_FAIL_FRONT_SIX_AXIS)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_SIX_AXIS);
  430. }
  431. else
  432. {
  433. //配置没问题
  434. ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_MAG);
  435. ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_FRONT_SENSOR_CONFIG_SIX_AXIS);
  436. if(ob_selfcheck.f_is_read_data != true)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_SIX_AXIS_NO_DATA);
  437. else
  438. {
  439. //数据没问题
  440. ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_FRONT_SIX_AXIS_NO_DATA);
  441. ob_selfcheck.f_is_read_data = false;
  442. front_mag_norm = sqrt((double)(ob_selfcheck.f_data.mag[0]*ob_selfcheck.f_data.mag[0]) + (double)(ob_selfcheck.f_data.mag[1]*ob_selfcheck.f_data.mag[1]) + (double)(ob_selfcheck.f_data.mag[2]*ob_selfcheck.f_data.mag[2]));
  443. //前脚传感器地磁没焊接电容
  444. if(front_mag_norm < SELFCHECK_SENSOR_MAG_NO_WELDING_CAPACITOR_MIN_THRESHOLD)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_MAG_DATA_TO_SMALL);
  445. else ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_FRONT_MAG_DATA_TO_SMALL);
  446. }
  447. }
  448. //后脚传感器判断
  449. b_config_result = bll_imu_query_config_param_is_ready(BLL_IMU_DIR_BACK,&game_bll_imu_param_t);
  450. if(b_config_result != BLL_IMU_CONFIG_FINISH)
  451. {
  452. if(b_config_result == BLL_IMU_CONFIG_FAIL_BACK_MAG_GET_ID)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_BACK_SENSOR_CONFIG_ID);
  453. else ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_BACK_SENSOR_CONFIG);
  454. }
  455. else
  456. {
  457. //配置没问题
  458. ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_BACK_SENSOR_CONFIG);
  459. if(ob_selfcheck.b_is_read_data != true)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_BACK_NO_DATA);
  460. else
  461. {
  462. //数据没问题
  463. ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_BACK_NO_DATA);
  464. ob_selfcheck.b_is_read_data = false;
  465. back_mag_norm = sqrt((double)(ob_selfcheck.b_data.mag[0]*ob_selfcheck.b_data.mag[0]) + (double)(ob_selfcheck.b_data.mag[1]*ob_selfcheck.b_data.mag[1]) + (double)(ob_selfcheck.b_data.mag[2]*ob_selfcheck.b_data.mag[2]));
  466. //后脚传感器地磁没焊接电容
  467. if(back_mag_norm < SELFCHECK_SENSOR_MAG_NO_WELDING_CAPACITOR_MIN_THRESHOLD)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_BACK_DATA_TO_SMALL);
  468. else ob_selfcheck.selfcheck_result &= ~(1 << SELFCHECK_RESULT_ERR_BACK_DATA_TO_SMALL);
  469. }
  470. }
  471. //任意传感器配置失败,重新配置
  472. if(f_config_result != BLL_IMU_CONFIG_FINISH || b_config_result != BLL_IMU_CONFIG_FINISH || ob_selfcheck.b_is_read_data != true || ob_selfcheck.f_is_read_data != true)
  473. {
  474. bll_imu_Resume_config_param(&game_bll_imu_param_t);
  475. }
  476. //更新计时-
  477. sensor_t_count = t_count;
  478. }
  479. //第3秒获取前脚是否装反
  480. if(t_count == (3000/100) && ob_selfcheck.order == 0x52)
  481. {
  482. roll = (int16_t)(Self_Front_Mahony.roll*100);
  483. if(roll < 0)roll *= -1;
  484. roll = (roll > 0 && roll < 100)?1:roll/100;
  485. if(!(roll >=SELFCHECK_MIDDLE_ACC_CONS_ROLL_MIN_THRESHOLD && roll <= SELFCHECK_MIDDLE_ACC_CONS_ROLL_MAX_THRESHOLD))
  486. {
  487. ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_FRONT_IMU_REVERSE);
  488. }
  489. // SEGGER_RTT_printf(0,"front roll:%d\r\n",roll);
  490. }
  491. //第3秒查看能否读取到任意广播名字,且最小的RSSI是否满足条件,设置自检结果。
  492. if(t_count == (3000/100))
  493. {
  494. if(SELFCHECK_SCAN_DEVICE_RSSI_MIN_THRESHOLD >= ob_selfcheck.max_rssi)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_RSSI);
  495. }
  496. //第3秒关闭100毫秒震动电机自检线程
  497. if(t_count == (3000/100))
  498. {
  499. Process_Stop(selfcheck_mt_process);
  500. Process_Stop(selfcheck_led_process);
  501. WS2812_DisplayDot(COLOR_BLACK);WS2812_Pwm_Play();
  502. nrf_gpio_pin_write(PIN_MT_EN,0);
  503. }
  504. //第3+SELFCHECK_LED_DISPLAY_CYCLE_THRESHOLD秒初始化自检显示结果线程,设置holdon,全功率运行。
  505. if(t_count == ((3000 + SELFCHECK_LED_DISPLAY_CYCLE_THRESHOLD)/100))
  506. {
  507. //根据自检结果设置灯
  508. if(ob_selfcheck.selfcheck_result == 0)
  509. {
  510. front_mag_norm = sqrt((double)(ob_selfcheck.f_data.mag[0]*ob_selfcheck.f_data.mag[0]) + (double)(ob_selfcheck.f_data.mag[1]*ob_selfcheck.f_data.mag[1]) + (double)(ob_selfcheck.f_data.mag[2]*ob_selfcheck.f_data.mag[2]));
  511. if(SELFCHECK_WEAR_INSOLE_MAG_NORM_MIN_THRESHOLD <= front_mag_norm)
  512. {
  513. ob_selfcheck.selfcheck_result_led_color = COLOR_GREEN;
  514. ob_selfcheck.selfcheck_result_flash_num = 1;
  515. }
  516. else
  517. {
  518. ob_selfcheck.selfcheck_result_led_color = COLOR_BLUE;
  519. ob_selfcheck.selfcheck_result_flash_num = 1;
  520. }
  521. }
  522. else
  523. {
  524. ob_selfcheck.selfcheck_result_led_color = COLOR_RED;
  525. for(int i=0;i<sizeof(ob_selfcheck.selfcheck_result)*8;i++)
  526. {
  527. if((ob_selfcheck.selfcheck_result & (1 << i)) != 0)
  528. {
  529. ob_selfcheck.selfcheck_result_flash_num = i;
  530. break;
  531. }
  532. }
  533. }
  534. Process_Start(SELFCHECK_LED_DISPLAY_CYCLE_THRESHOLD,"selfcheck_result_display_process",selfcheck_result_display_process);
  535. Process_SetHoldOn(selfcheck_result_display_process,1);
  536. }
  537. //上报中间传感器的加速度值和roll值
  538. L=0;
  539. int16_t rol = (int16_t)(Mahony_M_GetRoll()*100);
  540. int16_t pitch = (int16_t)(Mahony_M_GetPitch()*100);
  541. int16_t yaw = (int16_t)(Mahony_M_GetYaw()*100);
  542. buf[L++] = (uint8_t)(rol>>8);
  543. buf[L++] = (uint8_t)(rol>>0);
  544. buf[L++] = (uint8_t)(pitch>>8);
  545. buf[L++] = (uint8_t)(pitch>>0);
  546. buf[L++] = (uint8_t)(yaw>>8);
  547. buf[L++] = (uint8_t)(yaw>>0);
  548. buf[L++] = 0;
  549. buf[L++] = 0;
  550. buf[L++] = 0;
  551. buf[L++] = 0;
  552. buf[L++] = 0;
  553. buf[L++] = 0;
  554. buf[L++] = 0;
  555. Mahony_send_ANO(0x01,buf,L);
  556. L=0;
  557. int32_t middle_acc_x = ob_selfcheck.m_data.acc[2];
  558. int32_t middle_acc_y = ob_selfcheck.m_data.acc[1];
  559. int16_t middle_acc_z = ob_selfcheck.m_data.acc[0];
  560. middle_acc_x *= 100;
  561. middle_acc_y *= 100;
  562. middle_acc_z *= 10;
  563. buf[L++] = (uint8_t)(middle_acc_x>>24);
  564. buf[L++] = (uint8_t)(middle_acc_x>>16);
  565. buf[L++] = (uint8_t)(middle_acc_x>>8);
  566. buf[L++] = (uint8_t)(middle_acc_x>>0);
  567. buf[L++] = (uint8_t)(middle_acc_y>>24);
  568. buf[L++] = (uint8_t)(middle_acc_y>>16);
  569. buf[L++] = (uint8_t)(middle_acc_y>>8);
  570. buf[L++] = (uint8_t)(middle_acc_y>>0);
  571. buf[L++] = (uint8_t)(middle_acc_z>>8);
  572. buf[L++] = (uint8_t)(middle_acc_z>>0);
  573. Mahony_send_ANO(0x07,buf,L);
  574. //上报前脚传感器的加速度数据、陀螺仪数据、地磁计开平方和数据
  575. //上报后脚传感器的地磁计开平方和数据
  576. //上报扫描到的任意广播的rssi值
  577. if(TIME_GetTicks()-last_tim >= 1000)
  578. {
  579. last_tim = TIME_GetTicks();
  580. ob_selfcheck.max_rssi = -120;
  581. }
  582. L=0;
  583. buf[L++] = (uint8_t)(ob_selfcheck.f_data.acc[0]>>8);
  584. buf[L++] = (uint8_t)(ob_selfcheck.f_data.acc[0]>>0);
  585. buf[L++] = (uint8_t)(ob_selfcheck.f_data.acc[1]>>8);
  586. buf[L++] = (uint8_t)(ob_selfcheck.f_data.acc[1]>>0);
  587. buf[L++] = (uint8_t)(ob_selfcheck.f_data.acc[2]>>8);
  588. buf[L++] = (uint8_t)(ob_selfcheck.f_data.acc[2]>>0);
  589. buf[L++] = (uint8_t)(ob_selfcheck.f_data.gry[0]>>8);
  590. buf[L++] = (uint8_t)(ob_selfcheck.f_data.gry[0]>>0);
  591. buf[L++] = (uint8_t)(ob_selfcheck.f_data.gry[1]>>8);
  592. buf[L++] = (uint8_t)(ob_selfcheck.f_data.gry[1]>>0);
  593. buf[L++] = (uint8_t)(ob_selfcheck.f_data.gry[2]>>8);
  594. buf[L++] = (uint8_t)(ob_selfcheck.f_data.gry[2]>>0);
  595. front_mag_norm = sqrt((double)(ob_selfcheck.f_data.mag[0]*ob_selfcheck.f_data.mag[0]) + (double)(ob_selfcheck.f_data.mag[1]*ob_selfcheck.f_data.mag[1]) + (double)(ob_selfcheck.f_data.mag[2]*ob_selfcheck.f_data.mag[2]));
  596. back_mag_norm = sqrt((double)(ob_selfcheck.b_data.mag[0]*ob_selfcheck.b_data.mag[0]) + (double)(ob_selfcheck.b_data.mag[1]*ob_selfcheck.b_data.mag[1]) + (double)(ob_selfcheck.b_data.mag[2]*ob_selfcheck.b_data.mag[2]));
  597. buf[L++] = (uint8_t)(front_mag_norm>>8);
  598. buf[L++] = (uint8_t)(front_mag_norm>>0);
  599. buf[L++] = (uint8_t)(back_mag_norm>>8);
  600. buf[L++] = (uint8_t)(back_mag_norm>>0);
  601. buf[L++] = (uint8_t)(ob_selfcheck.max_rssi>> 8);
  602. buf[L++] = (uint8_t)(ob_selfcheck.max_rssi>>0);
  603. Mahony_send_ANO(0x02,buf,L);
  604. fml_adc_get_value(PIN_CHARGING_CHANNEL,&adc_value);
  605. if(adc_value >= 2000)
  606. {
  607. if(continue_trigger <= 50)continue_trigger++;
  608. }
  609. else
  610. {
  611. if(continue_trigger != 0)continue_trigger--;
  612. }
  613. // SEGGER_RTT_printf(0,"continue_trigger:%d,%d\r\n",continue_trigger,adc_value);
  614. // SEGGER_RTT_printf(0,"front mag:%d,%d,%d,%d\r\n",ob_selfcheck.f_data.mag[0],ob_selfcheck.f_data.mag[1],ob_selfcheck.f_data.mag[2],front_mag_norm);
  615. // SEGGER_RTT_printf(0,"back mag:%d,%d,%d,%d\r\n",ob_selfcheck.b_data.mag[0],ob_selfcheck.b_data.mag[1],ob_selfcheck.b_data.mag[2],back_mag_norm);
  616. //第30秒重启
  617. if(t_count >= (30000/100) && !slave_isconnect() && continue_trigger==0)
  618. {
  619. memset(mac_buf, 0, sizeof(mac_buf));
  620. sprintf(mac_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]);
  621. ST_scan_stop();
  622. host_set_scan_name(mac_buf, strlen(mac_buf));
  623. //恢复出厂信息
  624. memset(&mFlash,0xFF,sizeof(mFlash));
  625. memset(&mBackup,0xFF,sizeof(mBackup));
  626. //保存数据到flash
  627. if(Flash_SaveStep() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Power,"save step fail");
  628. extern battercb_t battery_record;
  629. // extern void printbatter_cb(battercb_t *c,unsigned char *buff);
  630. memcpy(&mFlash.mbattercb_t,&battery_record,sizeof(battercb_t));
  631. mBackup.RestartCnt =0;
  632. if(Flash_SaveBackup() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Power,"pwr save backup fail");
  633. if(Flash_SaveInfomation() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Power,"pwr save information fail");
  634. NVIC_SystemReset();
  635. }
  636. }
  637. static void adc_callback(uint32_t sample_point, Fml_Adc_All_Channel_Adc_Value_t all_adc_value)
  638. {
  639. //纯粹做覆盖
  640. }
  641. /*API ------------------------------------------------------------------------------------------------------------------------------------*/
  642. /**
  643. @brief 自检触发回调
  644. @param order - [in] 回调触发的指令
  645. @return 无
  646. */
  647. void selfcheck_trigger_callback(char order)
  648. {
  649. int error;
  650. uint32_t last_tim = TIME_GetTicks();
  651. //喂狗
  652. feed_watchdog();
  653. //初始化结构体,自检结果为成功
  654. memset(&ob_selfcheck,0,sizeof(ob_selfcheck));
  655. ob_selfcheck.max_rssi = -120;
  656. ob_selfcheck.selfcheck_result = SELFCHECK_RESULT_SUCCESS;
  657. ob_selfcheck.selfcheck_result_led_color = COLOR_BLACK;
  658. ob_selfcheck.f_is_read_data = false;
  659. ob_selfcheck.b_is_read_data = false;
  660. ob_selfcheck.order = order;
  661. //关闭所有线程,初始化0毫秒自检线程,设置holdon,全功率运行。
  662. Process_All_Stop();
  663. Process_Start(100,"selfcheck_process",selfcheck_process);
  664. Process_SetHoldOn(selfcheck_process,1);
  665. //关闭扫描,设置任意设备扫描回调,开启扫描
  666. while(TIME_GetTicks() - last_tim <= 1000)
  667. {
  668. host_disconnect();
  669. if(host_isconnect() == 0)break;
  670. }
  671. nrf_ble_scan_stop();
  672. host_set_scan_name((char *)"***********",sizeof("***********"));
  673. advdata_report_Evt_Regist(scan_report_cb);
  674. error = ST_scan_start();
  675. if(error != APP_SUCCESS)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_RSSI);
  676. //配置LED电源引脚为输出SOD1
  677. nrf_gpio_cfg(
  678. PIN_LED_ENABLE,
  679. NRF_GPIO_PIN_DIR_OUTPUT,
  680. NRF_GPIO_PIN_INPUT_DISCONNECT,
  681. NRF_GPIO_PIN_NOPULL,
  682. NRF_GPIO_PIN_S0D1,
  683. NRF_GPIO_PIN_NOSENSE);
  684. //配置震动电机引脚为输出SOS1
  685. nrf_gpio_cfg_output(PIN_MT_EN);
  686. nrf_gpio_pin_write(PIN_MT_EN,0);
  687. //配置led灯电源引脚为输出
  688. nrf_gpio_pin_write(PIN_LED_ENABLE,LED_ENABLE);
  689. //重新初始化ADC,配置所有通道。
  690. ADC_SetPinChannel(PIN_ADC_CHARGMEASURE, PIN_ADC_CHARGMEASURE_CHANNEL,NRF_GPIO_PIN_NOPULL);
  691. ADC_SetPinChannel(PIN_ADC_BAT_IN, PIN_ADC_BAT_CHANNEL,NRF_GPIO_PIN_NOPULL);
  692. ADC_SetPinChannel(PIN_CHARGING, PIN_CHARGING_CHANNEL,NRF_GPIO_PIN_NOPULL);
  693. fml_adc_sample_update_notify_register(adc_callback);
  694. //配置前脚传感器、中间传感器、后脚传感器
  695. bll_imu_Init();
  696. bll_imu_register_data_notify_callback(BLL_IMU_DATA_NOTIFY_CB_PRIORITY_1, fb_data_notify_cb);
  697. bll_imu_Resume_config_param(&game_bll_imu_param_t);
  698. error = drv_qma_Init();
  699. if(error == -1)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_MIDDLE_SENSOR_CONFIG);
  700. nrf_delay_ms(20);
  701. error = drv_qma_set_acc_odr(QMA_ACC_ODR_104HZ);
  702. if(error == -1)ob_selfcheck.selfcheck_result |= (1 << SELFCHECK_RESULT_ERR_MIDDLE_SENSOR_CONFIG);
  703. //初始化震动电机自检线程
  704. Process_Start(0,"selfcheck_mt_process",selfcheck_mt_process);
  705. Process_SetHoldOn(selfcheck_mt_process,1);
  706. //初始化LED自检线程
  707. Process_Start(SELFCHECK_LED_DISPLAY_CYCLE_THRESHOLD,"selfcheck_led_process",selfcheck_led_process);
  708. Process_SetHoldOn(selfcheck_led_process,1);
  709. //初始化计算roll值算法
  710. Mahony_Init(&Self_Mind_Mahony,104);
  711. Mahony_Init(&Self_Front_Mahony,416);
  712. //喂狗
  713. feed_watchdog();
  714. }