app_overturn.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 "app_overturn.h"
  9. #include "app_wearshoes.h"
  10. #define acc0Value 3000
  11. #define acc1iValue -1600
  12. #define acc1aValue 0
  13. #define acc2iValue -1500
  14. #define acc2aValue 400
  15. /************************ 追신鞫刻든좆 ***********************************/
  16. static uint8_t flag_move =0;
  17. void app_BatDispaly_Process_N(void)
  18. {
  19. int16_t acc[3];
  20. static uint32_t cnt = 0;
  21. if(app_wearshoes_is_wearshoes()== WEARSHOES_YES) return;//界岺榴檄
  22. IMU_Get_Index_Front_Low_Power_Data(acc, NULL, NULL, IMU_Get_Front_Update_Data_GroupNum());
  23. // SEGGER_RTT_printf(0,"0:acc[0]=%d,acc[1]=%d,acc[2]=%d\n",acc[0],acc[1],acc[2]);
  24. if(acc[2] > acc1iValue){
  25. cnt++;
  26. if(cnt==1){
  27. if(GetBatteryPersent()>20){
  28. LED_SetColor(LED_OVERTURN,COLOR_GREEN);
  29. }else{
  30. LED_SetColor(LED_OVERTURN,COLOR_RED);
  31. }
  32. LED_Start(LED_OVERTURN);
  33. Process_SetHoldOn(app_BatDispaly_Process_N,1);
  34. }
  35. if(cnt==100){
  36. LED_Stop(LED_OVERTURN);
  37. Process_SetHoldOn(app_BatDispaly_Process_N,0);
  38. }
  39. }else{
  40. if(cnt>0){ cnt = 0;
  41. LED_Stop(LED_OVERTURN);
  42. Process_SetHoldOn(app_BatDispaly_Process_N,0);
  43. }
  44. if(flag_move == 1){
  45. flag_move =0;
  46. LED_Stop(LED_OVERTURN);
  47. Process_SetHoldOn(app_BatDispaly_Process_N,0);
  48. }
  49. }
  50. }
  51. void app_BatDispaly_Process(void)
  52. {
  53. int16_t acc[3];
  54. static uint32_t cnt = 0;
  55. static int16_t acc0 = acc0Value;
  56. static int16_t acc1i = acc1iValue;
  57. static int16_t acc1a = acc1aValue;
  58. static int16_t acc2i = acc2iValue;
  59. static int16_t acc2a = acc2aValue;
  60. if(1 == IMU_GetSensorEnable()) {
  61. LED_Stop(LED_OVERTURN);
  62. return;//
  63. }
  64. if(app_wearshoes_is_wearshoes() == WEARSHOES_NO) return;//浬쨌榴檄
  65. IMU_Get_Index_Front_Low_Power_Data(acc, NULL, NULL, IMU_Get_Front_Update_Data_GroupNum());
  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 && acc[1] > acc1i && acc[1] < acc1a && acc[2] < acc2a && acc[2] > acc2i){
  68. cnt++;
  69. if(cnt==10){
  70. if(GetBatteryPersent()>20){
  71. LED_SetColor(LED_OVERTURN,COLOR_GREEN);
  72. }else{
  73. LED_SetColor(LED_OVERTURN,COLOR_RED);
  74. }
  75. LED_Start(LED_OVERTURN);
  76. Process_SetHoldOn(app_BatDispaly_Process,1);
  77. acc0 = acc0Value;
  78. acc1i = acc1iValue;
  79. acc1a = acc1aValue;
  80. acc2i = acc2iValue;
  81. acc2a = acc2aValue;
  82. }
  83. if(cnt==100){
  84. LED_Stop(LED_OVERTURN);
  85. Process_SetHoldOn(app_BatDispaly_Process,0);
  86. acc0 = acc0Value-200;
  87. acc1i = acc1iValue;
  88. acc1a = acc1aValue;
  89. acc2i = acc2iValue;
  90. acc2a = acc2aValue;
  91. }
  92. }else{
  93. if(cnt>0){ cnt = 0;
  94. LED_Stop(LED_OVERTURN);
  95. Process_SetHoldOn(app_BatDispaly_Process,0);
  96. acc0 = acc0Value;
  97. acc1i = acc1iValue;
  98. acc1a = acc1aValue;
  99. acc2i = acc2iValue;
  100. acc2a = acc2aValue;
  101. }
  102. if(flag_move == 0){
  103. flag_move =1;
  104. LED_Stop(LED_OVERTURN);
  105. Process_SetHoldOn(app_BatDispaly_Process,0);
  106. acc0 = acc0Value;
  107. acc1i = acc1iValue;
  108. acc1a = acc1aValue;
  109. acc2i = acc2iValue;
  110. acc2a = acc2aValue;
  111. }
  112. }
  113. }
  114. void app_overturn_Init(void)
  115. {
  116. Process_Start(100,"BatDispaly",app_BatDispaly_Process);
  117. Process_Start(100,"BatDispaly_N",app_BatDispaly_Process_N);
  118. }