app_overturn.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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_imu.h"
  8. #include "hal_mode_manage.h"
  9. #include "app_overturn.h"
  10. #include "hal_wearshoes.h"
  11. #define acc0Value -1400
  12. #define acc1iValue -1600
  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];
  21. static uint32_t cnt = 0;
  22. if(hal_mode_get() == HAL_MODE_NORMAL) return;//停止状态
  23. //获取最新一组前脚加速度
  24. if(IMU_Get_Front_Data_Num() >= 1)IMU_Get_Front_Data(IMU_Get_Front_Data_Num()-1, NULL, acc, NULL, NULL);
  25. // SEGGER_RTT_printf(0,"0:acc[0]=%d,acc[1]=%d,acc[2]=%d\n",acc[0],acc[1],acc[2]);
  26. if(acc[2] > acc1iValue){
  27. cnt++;
  28. if(cnt==5){
  29. if(GetBatteryPersent()>20){
  30. LED_Start(LED_OVERTURN,COLOR_GREEN);
  31. }else{
  32. LED_Start(LED_OVERTURN,COLOR_RED);
  33. }
  34. Process_SetHoldOn(app_BatDispaly_Process_N,1);
  35. }
  36. if(cnt==100){
  37. LED_Stop(LED_OVERTURN);
  38. Process_SetHoldOn(app_BatDispaly_Process_N,0);
  39. }
  40. }else{
  41. if(cnt>0){ cnt = 0;
  42. LED_Stop(LED_OVERTURN);
  43. Process_SetHoldOn(app_BatDispaly_Process_N,0);
  44. }
  45. if(1== flag_move){
  46. flag_move =0;
  47. LED_Stop(LED_OVERTURN);
  48. Process_SetHoldOn(app_BatDispaly_Process_N,0);
  49. }
  50. }
  51. }
  52. void app_BatDispaly_Process(void)
  53. {
  54. int16_t acc[3];
  55. static uint32_t cnt = 0;
  56. static int16_t acc0 = acc0Value;
  57. static int16_t acc1i = acc1iValue;
  58. static int16_t acc1a = acc1aValue;
  59. static int16_t acc2i = acc2iValue;
  60. static int16_t acc2a = acc2aValue;
  61. if(hal_mode_get() == HAL_MODE_STANDBY) return;//走路状态
  62. //获取最新一组前脚加速度
  63. if(IMU_Get_Front_Data_Num() >= 1)IMU_Get_Front_Data(IMU_Get_Front_Data_Num()-1, NULL, acc, NULL, NULL);
  64. // SEGGER_RTT_printf(0,"1:acc[0]=%d,acc[1]=%d,acc[2]=%d\n",acc[0],acc[1],acc[2]);
  65. if(acc[0] < acc0 &&
  66. (acc[1] > acc1i && acc[1] < acc1a) &&
  67. (acc[2] < acc2a && acc[2] > acc2i)){
  68. cnt++;
  69. if(cnt==10){
  70. if(GetBatteryPersent()>20){
  71. LED_Start(LED_OVERTURN,COLOR_GREEN);
  72. }else{
  73. LED_Start(LED_OVERTURN,COLOR_RED);
  74. }
  75. Process_SetHoldOn(app_BatDispaly_Process,1);
  76. acc0 = acc0Value;
  77. acc1i = acc1iValue;
  78. acc1a = acc1aValue;
  79. acc2i = acc2iValue;
  80. acc2a = acc2aValue;
  81. }
  82. if(cnt==100){
  83. LED_Stop(LED_OVERTURN);
  84. Process_SetHoldOn(app_BatDispaly_Process,0);
  85. acc0 = acc0Value-200;
  86. acc1i = acc1iValue;
  87. acc1a = acc1aValue;
  88. acc2i = acc2iValue;
  89. acc2a = acc2aValue;
  90. }
  91. }else{
  92. if(cnt>0){ cnt = 0;
  93. LED_Stop(LED_OVERTURN);
  94. Process_SetHoldOn(app_BatDispaly_Process,0);
  95. acc0 = acc0Value;
  96. acc1i = acc1iValue;
  97. acc1a = acc1aValue;
  98. acc2i = acc2iValue;
  99. acc2a = acc2aValue;
  100. }
  101. if(flag_move == 0){
  102. flag_move =1;
  103. LED_Stop(LED_OVERTURN);
  104. Process_SetHoldOn(app_BatDispaly_Process,0);
  105. acc0 = acc0Value;
  106. acc1i = acc1iValue;
  107. acc1a = acc1aValue;
  108. acc2i = acc2iValue;
  109. acc2a = acc2aValue;
  110. }
  111. }
  112. }
  113. void app_overturn_Init(void)
  114. {
  115. Process_Start(StandByPower_Interval,"BatDispaly",app_BatDispaly_Process);
  116. Process_Start(StandByPower_Interval,"BatDispaly_N",app_BatDispaly_Process_N);
  117. }