exception.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #include "exception.h"
  2. #include "app_flash.h"
  3. #include "bsp_time.h"
  4. #include "system.h"
  5. #include "hal_imu.h"
  6. #include "hal_mode_manage.h"
  7. #include "hal_led.h"
  8. #define TRIGGER_EXCEPT_CONS_DISPLAY_ACC_Z 1500 //触发异常显示的加速度Z轴
  9. #define TRIGGER_EXCEPT_PROS_DISPLAY_ACC_Z -1500 //复位触发异常显示的加速度Z轴
  10. #define DISPLAY_EXCEPT_LED_TIME 200 //用灯显示异常结果的时间,单位ms
  11. #define DISPLAY_EXCEPT_CONTINUE_TIME 10000 //显示异常结果的总时间,单位ms
  12. ExcepSign Global_Ex;
  13. static uint8_t except_result_led_onoff = 0;
  14. static uint32_t display_times = 0;
  15. static void Except_Result_LED(void)
  16. {
  17. static uint8_t state = 0;
  18. static uint8_t toggle = 1;
  19. switch(state){
  20. case 0:
  21. Process_SetHoldOn(Except_Result_LED,1);
  22. if(toggle){
  23. LED_Start(LED_EXCEPT,COLOR_ORANGE);
  24. toggle = 0;
  25. }else{
  26. LED_Start(LED_EXCEPT,COLOR_BLACK);
  27. toggle = 1;
  28. }
  29. state = 1;
  30. Process_UpdatePeroid(Except_Result_LED,DISPLAY_EXCEPT_LED_TIME);
  31. break;
  32. case 1:
  33. if((DISPLAY_EXCEPT_LED_TIME * ++display_times) <= DISPLAY_EXCEPT_CONTINUE_TIME){
  34. Process_UpdatePeroid(Except_Result_LED,0);//跳过判断时间。
  35. state = 0;
  36. break;
  37. }
  38. display_times = 0;
  39. Process_UpdatePeroid(Except_Result_LED,0);
  40. LED_Stop(LED_EXCEPT);
  41. state = 0;
  42. toggle = 1;
  43. Process_SetHoldOn(Except_Result_LED,0);
  44. Process_Stop(Except_Result_LED);
  45. break;
  46. default:state=0;Process_UpdatePeroid(Except_Result_LED,0);break;
  47. }
  48. }
  49. static void Exception_Process(void)
  50. {
  51. int16_t front_acc[3];
  52. if(IMU_Get_Front_Data_Num() >= 1)IMU_Get_Front_Data(IMU_Get_Front_Data_Num()-1, NULL, front_acc, NULL, NULL);
  53. if(front_acc[2] >= TRIGGER_EXCEPT_CONS_DISPLAY_ACC_Z && except_result_led_onoff == 0){
  54. if(mFlash.exception.except_number_of_exist > 0){
  55. Process_Start(0,"Except_Result_LED",Except_Result_LED); //开灯
  56. display_times = 1;
  57. except_result_led_onoff = 1;
  58. }
  59. }else if(front_acc[2] <= TRIGGER_EXCEPT_PROS_DISPLAY_ACC_Z && except_result_led_onoff == 1 && display_times == 0){
  60. except_result_led_onoff = 0;
  61. nrf_gpio_pin_write(PIN_LED_RUN,LED_SMALL_ENABLE);
  62. }
  63. }
  64. void Except_SaveExceptype(ExcepType_t excep_type)
  65. {
  66. switch(excep_type)
  67. {
  68. case EXCEPT_DATA_BACK_MAG:
  69. if(mFlash.exception.except_data_back_mag != 1){
  70. mFlash.exception.except_data_back_mag = 1;
  71. mFlash.exception.except_number_of_exist++;
  72. }
  73. break;
  74. case EXCEPT_DATA_FRONT_ACC:
  75. if(mFlash.exception.except_data_front_acc != 1){
  76. mFlash.exception.except_data_front_acc = 1;
  77. mFlash.exception.except_number_of_exist++;
  78. }
  79. break;
  80. case EXCEPT_DATA_FRONT_GRY:
  81. if(mFlash.exception.except_data_front_gry != 1){
  82. mFlash.exception.except_data_front_gry = 1;
  83. mFlash.exception.except_number_of_exist++;
  84. }
  85. break;
  86. case EXCEPT_DATA_FRONT_MAG:
  87. if(mFlash.exception.except_data_front_mag != 1){
  88. mFlash.exception.except_data_front_mag = 1;
  89. mFlash.exception.except_number_of_exist++;
  90. }
  91. break;
  92. case EXCEPT_DATA_CHARGE:
  93. if(mFlash.exception.except_data_charge != 1){
  94. mFlash.exception.except_data_charge = 1;
  95. mFlash.exception.except_number_of_exist++;
  96. }
  97. break;
  98. case EXCEPT_MODE_SUSPEND_OVERFLOW:
  99. if(mFlash.exception.except_mode_suspend_overflow != 1){
  100. mFlash.exception.except_mode_suspend_overflow = 1;
  101. mFlash.exception.except_number_of_exist++;
  102. }
  103. break;
  104. default:
  105. break;
  106. }
  107. Flash_SaveInfomation();
  108. }
  109. uint32_t Except_IsExist(void)
  110. {
  111. return mFlash.exception.except_number_of_exist;
  112. }
  113. void Exception_Init(void)
  114. {
  115. Process_Start(0,"Exception_Process",Exception_Process);
  116. }