app_overturn.c 3.0 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. #define acc0Value -1000
  10. #define acc1iValue -1200
  11. #define acc1aValue 1300
  12. #define acc2iValue -1800
  13. #define acc2aValue -400
  14. /************************ 追신鞫刻든좆 ***********************************/
  15. static uint8_t flag_move =0;
  16. void app_BatDispaly_Process_N(void)
  17. {
  18. int16_t acc[3];
  19. static uint32_t cnt = 0;
  20. if(IMU_isLoader()>0) return;//界岺榴檄
  21. IMU_GetAcc(acc);
  22. //SEGGER_RTT_printf(0,"0:acc[0]=%d,acc[1]=%d,acc[2]=%d\n",acc[0],acc[1],acc[2]);
  23. if(acc[2] > acc1iValue){
  24. cnt++;
  25. if(cnt==1){
  26. if(GetBatteryPersent()>20){
  27. LED_SetColor(LED_OVERTURN,COLOR_GREEN);
  28. }else{
  29. LED_SetColor(LED_OVERTURN,COLOR_RED);
  30. }
  31. LED_Start(LED_OVERTURN);
  32. Process_SetHoldOn(app_BatDispaly_Process_N,1);
  33. }
  34. if(cnt==100){
  35. LED_Stop(LED_OVERTURN);
  36. Process_SetHoldOn(app_BatDispaly_Process_N,0);
  37. }
  38. }else{
  39. if(cnt>0){ cnt = 0;
  40. LED_Stop(LED_OVERTURN);
  41. Process_SetHoldOn(app_BatDispaly_Process_N,0);
  42. }
  43. if(flag_move == 1){
  44. flag_move =0;
  45. LED_Stop(LED_OVERTURN);
  46. Process_SetHoldOn(app_BatDispaly_Process_N,0);
  47. }
  48. }
  49. }
  50. void app_BatDispaly_Process(void)
  51. {
  52. int16_t acc[3];
  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(IMU_isLoader()==0) return;//浬쨌榴檄
  64. IMU_GetAcc(acc);
  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. }