app_overturn.c 3.6 KB

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