app_overturn.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 "hal_step.h"
  10. #include "hal_attitude.h"
  11. #define acc0Value -9000
  12. #define acc1iValue -9000
  13. #define acc1aValue 9000
  14. #define acc2iValue -12000
  15. #define acc2aValue -4000
  16. /************************ 追신鞫刻든좆 ***********************************/
  17. static uint8_t flag_move =0;
  18. void app_BatDispaly_Process_N(void)
  19. {
  20. static uint32_t cnt = 0;
  21. if(get_isLoader()>0) return;//界岺榴檄
  22. int16_t * acc = hal_att_GetAcc();
  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. static uint32_t cnt = 0;
  54. static int16_t acc0 = acc0Value;
  55. static int16_t acc1i = acc1iValue;
  56. static int16_t acc1a = acc1aValue;
  57. static int16_t acc2i = acc2iValue;
  58. static int16_t acc2a = acc2aValue;
  59. if(1 == IMU_GetGameMode()) {
  60. LED_Stop(LED_OVERTURN);
  61. return;//
  62. }
  63. if(get_isLoader()==0) return;//浬쨌榴檄
  64. int16_t * acc = hal_att_GetAcc();
  65. // SEGGER_RTT_printf(0,"1:acc[0]=%d,acc[1]=%d,acc[2]=%d\n",acc[0],acc[1],acc[2]);
  66. if(acc[0] < acc0 && acc[1] > acc1i && acc[1] < acc1a && acc[2] < acc2a && acc[2] > acc2i){
  67. cnt++;
  68. if(cnt==10){
  69. if(GetBatteryPersent()>20){
  70. LED_SetColor(LED_OVERTURN,COLOR_GREEN);
  71. }else{
  72. LED_SetColor(LED_OVERTURN,COLOR_RED);
  73. }
  74. LED_Start(LED_OVERTURN);
  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(100,"BatDispaly",app_BatDispaly_Process);
  116. Process_Start(100,"BatDispaly_N",app_BatDispaly_Process_N);
  117. }