hal_step.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /********************** Í·Îļþ *************************/
  2. #include "usr.h"
  3. #include "hal_imu.h"
  4. #include "hal_step.h"
  5. #include "system.h"
  6. #include "bsp_time.h"
  7. #include "hal_ble_client.h"
  8. #include "hal_flash.h"
  9. #include "hal_mag.h"
  10. #include "hal_RealStep.h"
  11. #include "hal_attitude.h"
  12. #include "detect_step_by_mag.h"
  13. static uint8_t isLoader =0;
  14. static uint16_t load_cal =0;
  15. uint8_t get_isLoader(void)
  16. {
  17. return isLoader;
  18. }
  19. #if DEBUG_STEP
  20. extern uint16_t realStepAdd_R,mag_sqrt;
  21. void hal_step_matlib_Test(void)
  22. {
  23. static uint8_t buf[24] ={0};
  24. uint8_t L =0;
  25. buf[L++] = (uint8_t)(mFlash.mStep.stepCur[0]>>8);
  26. buf[L++] = (uint8_t)(mFlash.mStep.stepCur[0]>>0);
  27. buf[L++] = (uint8_t)(mag_sqrt>>8);
  28. buf[L++] = (uint8_t)(mag_sqrt);
  29. buf[L++] = (uint8_t)(realStepAdd_R>>8);
  30. buf[L++] = (uint8_t)(realStepAdd_R>>0);
  31. BLE_Client_Tx_Send(0,BLE_Client_T_REALTIMESTEP,buf,L);
  32. }
  33. #endif
  34. static void hal_step_process(void){
  35. if(hal_Realstep_GetState())return;
  36. if(1 == detect_step_by_mag(hal_Mag_GetXYZ(Mag_Front))){
  37. mFlash.mStep.stepCur[0]++;
  38. if(0 == isLoader){
  39. isLoader =1;
  40. SEGGER_RTT_printf(0,"isLoader:%d\r\n",isLoader);
  41. }
  42. load_cal =0;
  43. // SEGGER_RTT_printf(0,">>>>>>>>current step:%d\r\n",mFlash.mStep.stepCur[0]);
  44. }else if(isLoader == 1){
  45. load_cal++;
  46. if(load_cal >= (60000/50)){
  47. isLoader =0;
  48. load_cal =0;
  49. SEGGER_RTT_printf(0,"isLoader:%d\r\n",isLoader);
  50. }
  51. }
  52. #if DEBUG_STEP
  53. hal_step_matlib_Test()£»
  54. #endif
  55. }
  56. //static void hal_stepSaveTest_process(void){
  57. // mFlash.mStep.stepCur[0]++;
  58. // SEGGER_RTT_printf(0,"hal step Save one minute:step %d\r\n",mFlash.mStep.stepCur[0]);
  59. //}
  60. void hal_step_init(void){
  61. Process_Start(50,"hal_step_process",hal_step_process);
  62. //if(mFlash.isHost)Process_Start(10000,"hal_stepSaveTest",hal_stepSaveTest_process);
  63. }