hal_RealStep.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /********************** Í·Îļþ *************************/
  2. #include "usr.h"
  3. #include "hal_Realstep.h"
  4. #include "system.h"
  5. #include "bsp_time.h"
  6. #include "hal_ble_client.h"
  7. #include "hal_flash.h"
  8. #include "hal_mag.h"
  9. #include "hal_attitude.h"
  10. static uint8_t Realstep_Enable = 0;
  11. static uint8_t ReqRealstep_Enable = 0;
  12. static uint8_t Realstep_temp =0;
  13. enum{
  14. Realstep_init,
  15. Realstep_Check_r,
  16. Realstep_run,
  17. Realstep_quiet
  18. };
  19. void hal_Realstep_Enable(uint8_t cmd)
  20. {
  21. ReqRealstep_Enable = cmd;
  22. }
  23. uint8_t hal_Realstep_GetState(void)
  24. {
  25. return Realstep_Enable;
  26. }
  27. static void hal_Realstep_process(void)
  28. {
  29. static uint8_t state =Realstep_init;
  30. switch(state){
  31. case Realstep_init:
  32. if(ReqRealstep_Enable ==1){
  33. Process_SetHoldOn(hal_Realstep_process,1);
  34. hal_attitude_setMode(Att_GameMode);
  35. hal_mag_SetState(Mag_All_l,Mag_Mode_10Hz);
  36. state = Realstep_Check_r;
  37. Realstep_temp =0;
  38. }
  39. break;
  40. case Realstep_Check_r:
  41. if(1 == hal_attitude_GetMode(Att_GameMode) && Mag_Mode_10Hz == hal_mag_GetState(Mag_Front) && Mag_Mode_10Hz == hal_mag_GetState(Mag_Back)){
  42. state = Realstep_run;
  43. SEGGER_RTT_printf(0,"Realstep_Check_r\n");
  44. Realstep_Enable =1;
  45. }
  46. else if(Realstep_temp++ >20){
  47. SEGGER_RTT_printf(0,"Realstep_Check into fail\n");
  48. state = Realstep_init;
  49. ReqRealstep_Enable =0;
  50. if(0 == hal_attitude_GetMode(Att_GameMode))app_err_Set(ERR_NUM_IMU_BMI160,1);
  51. else app_err_Set(ERR_NUM_IMU_QMC6310,1);
  52. }
  53. break;
  54. case Realstep_run:
  55. if(ReqRealstep_Enable == 0){
  56. Process_SetHoldOn(hal_Realstep_process,0);
  57. hal_attitude_setMode(Att_Lowpower);
  58. hal_mag_SetState(Mag_Front,Mag_Mode_10Hz);
  59. hal_mag_SetState(Mag_Back,Mag_Mode_Suspend);
  60. state = Realstep_quiet;
  61. }
  62. break;
  63. case Realstep_quiet:
  64. if(hal_attitude_GetMode(Att_Lowpower) && Mag_Mode_Suspend == hal_mag_GetState(Mag_Back) && Mag_Mode_10Hz == hal_mag_GetState(Mag_Front)){
  65. Realstep_Enable = 0;
  66. state = Realstep_init;
  67. SEGGER_RTT_printf(0,"Realstep out ok\n");
  68. }
  69. else if(Realstep_temp++ >40){
  70. Realstep_Enable = 0;
  71. SEGGER_RTT_printf(0,"Realstep out fail\n");
  72. state = Realstep_init;
  73. if(0 == hal_attitude_GetMode(Att_GameMode))app_err_Set(ERR_NUM_IMU_BMI160,1);
  74. else app_err_Set(ERR_NUM_IMU_QMC6310,1);
  75. }
  76. break;
  77. default:
  78. break;
  79. }
  80. }
  81. void hal_Realstep_Init(void)
  82. {
  83. Process_Start(100,"hal_Realstep_process",hal_Realstep_process);
  84. }