app_overturn.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #include "usr_config.h"
  2. #include "hal_battery.h"
  3. #include "nrf_drv_saadc.h"
  4. #include "bsp_time.h"
  5. #include "system.h"
  6. #include "hal_led.h"
  7. #include "hal_ser_imu_mode_manage.h"
  8. #include "app_overturn.h"
  9. #include "hal_wearshoes.h"
  10. #define acc1iValue_noshoes 1200
  11. #define acc0Value -1400
  12. #define acc1iValue -1400
  13. #define acc1aValue 1800
  14. #define acc2iValue -1500
  15. #define acc2aValue 400
  16. /************************ 踮脚显示电量 ***********************************/
  17. static uint8_t flag_move =0;
  18. void app_BatDispaly_Process_N(void)
  19. {
  20. int16_t acc[3] = {0,0,0};
  21. ser_imu_data_t data;
  22. static uint32_t cnt = 0;
  23. if(-1 == hal_ser_imu_mode_manage_get_ready(HAL_SER_IMU_MODE_MANAGE_STANDBY)) return;//停止状态
  24. //获取最新一组前脚加速度
  25. if(hal_ser_imu_mode_manage_get_data_num(SER_IMU_DIR_FRONT) >= 1){
  26. hal_ser_imu_mode_manage_get_data(SER_IMU_DIR_FRONT, 0, &data);
  27. acc[0] = data.acc[0];acc[1] = data.acc[1];acc[2] = data.acc[2];
  28. }
  29. // SEGGER_RTT_printf(0,"0:acc[0]=%d,acc[1]=%d,acc[2]=%d\n",acc[0],acc[1],acc[2]);
  30. if(acc[2] > acc1iValue_noshoes){
  31. cnt++;
  32. if(cnt ==(1500/StandByPower_Interval) ){
  33. // SEGGER_RTT_printf(0,">>>>>>>0:acc[0]=%d,acc[1]=%d,acc[2]=%d\n",acc[0],acc[1],acc[2]);
  34. if(GetBatteryPersent()>20){
  35. LED_Start(LED_OVERTURN,COLOR_GREEN);
  36. }else{
  37. LED_Start(LED_OVERTURN,COLOR_ORANGE);
  38. }
  39. Process_SetHoldOn(app_BatDispaly_Process_N,1);
  40. }
  41. if(cnt >= (10000/StandByPower_Interval)){
  42. LED_Stop(LED_OVERTURN);
  43. Process_SetHoldOn(app_BatDispaly_Process_N,0);
  44. }
  45. }else{
  46. if(cnt>0){ cnt = 0;
  47. LED_Stop(LED_OVERTURN);
  48. Process_SetHoldOn(app_BatDispaly_Process_N,0);
  49. }
  50. if(1== flag_move){
  51. flag_move =0;
  52. LED_Stop(LED_OVERTURN);
  53. Process_SetHoldOn(app_BatDispaly_Process_N,0);
  54. }
  55. }
  56. }
  57. void app_BatDispaly_Process(void)
  58. {
  59. int16_t acc[3] = {0,0,0};
  60. ser_imu_data_t data;
  61. static uint32_t cnt = 0;
  62. static int16_t acc0 = acc0Value;
  63. static int16_t acc1i = acc1iValue;
  64. static int16_t acc1a = acc1aValue;
  65. static int16_t acc2i = acc2iValue;
  66. static int16_t acc2a = acc2aValue;
  67. if(-1 == hal_ser_imu_mode_manage_get_ready(HAL_SER_IMU_MODE_MANAGE_NORMAL)) return;//走路状态
  68. //获取最新一组前脚加速度
  69. if(hal_ser_imu_mode_manage_get_data_num(SER_IMU_DIR_FRONT) >= 1){
  70. hal_ser_imu_mode_manage_get_data(SER_IMU_DIR_FRONT, 0, &data);
  71. acc[0] = data.acc[0];acc[1] = data.acc[1];acc[2] = data.acc[2];
  72. }
  73. // SEGGER_RTT_printf(0,"1:acc[0]=%d,acc[1]=%d,acc[2]=%d\n",acc[0],acc[1],acc[2]);
  74. if(acc[0] < acc0 &&
  75. (acc[1] > acc1i && acc[1] < acc1a) &&
  76. (acc[2] < acc2a && acc[2] > acc2i)){
  77. cnt++;
  78. if(cnt==(1500/StandByPower_Interval)){
  79. if(GetBatteryPersent()>20){
  80. LED_Start(LED_OVERTURN,COLOR_GREEN);
  81. }else{
  82. LED_Start(LED_OVERTURN,COLOR_ORANGE);
  83. }
  84. Process_SetHoldOn(app_BatDispaly_Process,1);
  85. acc0 = acc0Value;
  86. acc1i = acc1iValue;
  87. acc1a = acc1aValue;
  88. acc2i = acc2iValue;
  89. acc2a = acc2aValue;
  90. }
  91. if(cnt == (10000/StandByPower_Interval)){
  92. LED_Stop(LED_OVERTURN);
  93. Process_SetHoldOn(app_BatDispaly_Process,0);
  94. acc0 = acc0Value-200;
  95. acc1i = acc1iValue;
  96. acc1a = acc1aValue;
  97. acc2i = acc2iValue;
  98. acc2a = acc2aValue;
  99. }
  100. }else{
  101. if(cnt>0){ cnt = 0;
  102. LED_Stop(LED_OVERTURN);
  103. Process_SetHoldOn(app_BatDispaly_Process,0);
  104. acc0 = acc0Value;
  105. acc1i = acc1iValue;
  106. acc1a = acc1aValue;
  107. acc2i = acc2iValue;
  108. acc2a = acc2aValue;
  109. }
  110. if(flag_move == 0){
  111. flag_move =1;
  112. LED_Stop(LED_OVERTURN);
  113. Process_SetHoldOn(app_BatDispaly_Process,0);
  114. acc0 = acc0Value;
  115. acc1i = acc1iValue;
  116. acc1a = acc1aValue;
  117. acc2i = acc2iValue;
  118. acc2a = acc2aValue;
  119. }
  120. }
  121. }
  122. void app_overturn_Init(void)
  123. {
  124. Process_Start(StandByPower_Interval,"BatDispaly",app_BatDispaly_Process);
  125. Process_Start(StandByPower_Interval,"BatDispaly_N",app_BatDispaly_Process_N);
  126. }