exception.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. }
  62. }
  63. void Except_SaveExceptype(ExcepType_t excep_type)
  64. {
  65. switch(excep_type)
  66. {
  67. case EXCEPT_DATA_BACK_MAG:
  68. if(mFlash.exception.except_data_back_mag != 1){
  69. mFlash.exception.except_data_back_mag = 1;
  70. mFlash.exception.except_number_of_exist++;
  71. }
  72. break;
  73. case EXCEPT_DATA_FRONT_ACC:
  74. if(mFlash.exception.except_data_front_acc != 1){
  75. mFlash.exception.except_data_front_acc = 1;
  76. mFlash.exception.except_number_of_exist++;
  77. }
  78. break;
  79. case EXCEPT_DATA_FRONT_GRY:
  80. if(mFlash.exception.except_data_front_gry != 1){
  81. mFlash.exception.except_data_front_gry = 1;
  82. mFlash.exception.except_number_of_exist++;
  83. }
  84. break;
  85. case EXCEPT_DATA_FRONT_MAG:
  86. if(mFlash.exception.except_data_front_mag != 1){
  87. mFlash.exception.except_data_front_mag = 1;
  88. mFlash.exception.except_number_of_exist++;
  89. }
  90. break;
  91. case EXCEPT_DATA_CHARGE:
  92. if(mFlash.exception.except_data_charge != 1){
  93. mFlash.exception.except_data_charge = 1;
  94. mFlash.exception.except_number_of_exist++;
  95. }
  96. break;
  97. default:
  98. break;
  99. }
  100. Flash_SaveInfomation();
  101. }
  102. void Exception_Init(void)
  103. {
  104. Process_Start(0,"Exception_Process",Exception_Process);
  105. }