#include "exception.h" #include "app_flash.h" #include "bsp_time.h" #include "system.h" #include "hal_imu.h" #include "hal_mode_manage.h" #include "hal_led.h" #define TRIGGER_EXCEPT_CONS_DISPLAY_ACC_Z 1500 //触发异常显示的加速度Z轴 #define TRIGGER_EXCEPT_PROS_DISPLAY_ACC_Z -1500 //复位触发异常显示的加速度Z轴 #define DISPLAY_EXCEPT_LED_TIME 200 //用灯显示异常结果的时间,单位ms #define DISPLAY_EXCEPT_CONTINUE_TIME 10000 //显示异常结果的总时间,单位ms ExcepSign Global_Ex; static uint8_t except_result_led_onoff = 0; static uint32_t display_times = 0; static void Except_Result_LED(void) { static uint8_t state = 0; static uint8_t toggle = 1; switch(state){ case 0: Process_SetHoldOn(Except_Result_LED,1); if(toggle){ LED_Start(LED_EXCEPT,COLOR_ORANGE); toggle = 0; }else{ LED_Start(LED_EXCEPT,COLOR_BLACK); toggle = 1; } state = 1; Process_UpdatePeroid(Except_Result_LED,DISPLAY_EXCEPT_LED_TIME); break; case 1: if((DISPLAY_EXCEPT_LED_TIME * ++display_times) <= DISPLAY_EXCEPT_CONTINUE_TIME){ Process_UpdatePeroid(Except_Result_LED,0);//跳过判断时间。 state = 0; break; } display_times = 0; Process_UpdatePeroid(Except_Result_LED,0); LED_Stop(LED_EXCEPT); state = 0; toggle = 1; Process_SetHoldOn(Except_Result_LED,0); Process_Stop(Except_Result_LED); break; default:state=0;Process_UpdatePeroid(Except_Result_LED,0);break; } } static void Exception_Process(void) { int16_t front_acc[3]; if(IMU_Get_Front_Data_Num() >= 1)IMU_Get_Front_Data(IMU_Get_Front_Data_Num()-1, NULL, front_acc, NULL, NULL); if(front_acc[2] >= TRIGGER_EXCEPT_CONS_DISPLAY_ACC_Z && except_result_led_onoff == 0){ if(mFlash.exception.except_number_of_exist > 0){ Process_Start(0,"Except_Result_LED",Except_Result_LED); //开灯 display_times = 1; except_result_led_onoff = 1; } }else if(front_acc[2] <= TRIGGER_EXCEPT_PROS_DISPLAY_ACC_Z && except_result_led_onoff == 1 && display_times == 0){ except_result_led_onoff = 0; } } void Except_SaveExceptype(ExcepType_t excep_type) { switch(excep_type) { case EXCEPT_DATA_BACK_MAG: if(mFlash.exception.except_data_back_mag != 1){ mFlash.exception.except_data_back_mag = 1; mFlash.exception.except_number_of_exist++; Flash_SaveInfomation(); } break; case EXCEPT_DATA_FRONT_ACC: if(mFlash.exception.except_data_front_acc != 1){ mFlash.exception.except_data_front_acc = 1; mFlash.exception.except_number_of_exist++; Flash_SaveInfomation(); } break; case EXCEPT_DATA_FRONT_GRY: if(mFlash.exception.except_data_front_gry != 1){ mFlash.exception.except_data_front_gry = 1; mFlash.exception.except_number_of_exist++; Flash_SaveInfomation(); } break; case EXCEPT_DATA_FRONT_MAG: if(mFlash.exception.except_data_front_mag != 1){ mFlash.exception.except_data_front_mag = 1; mFlash.exception.except_number_of_exist++; Flash_SaveInfomation(); } break; case EXCEPT_DATA_CHARGE: if(mFlash.exception.except_data_charge != 1){ mFlash.exception.except_data_charge = 1; mFlash.exception.except_number_of_exist++; Flash_SaveInfomation(); } break; case EXCEPT_DATA_BATTERY: if(mFlash.exception.except_data_battery != 1){ mFlash.exception.except_data_battery = 1; mFlash.exception.except_number_of_exist++; Flash_SaveInfomation(); } break; case EXCEPT_MODE_SUSPEND_OVERFLOW: if(mFlash.exception.except_mode_suspend_overflow != 1){ mFlash.exception.except_mode_suspend_overflow = 1; mFlash.exception.except_number_of_exist++; Flash_SaveInfomation(); } break; default: break; } } bool Except_IsError(ExcepType_t excep_type) { switch(excep_type) { case EXCEPT_DATA_BACK_MAG: if(mFlash.exception.except_data_back_mag == 1){ return true; } break; case EXCEPT_DATA_FRONT_ACC: if(mFlash.exception.except_data_front_acc == 1){ return true; } break; case EXCEPT_DATA_FRONT_GRY: if(mFlash.exception.except_data_front_gry == 1){ return true; } break; case EXCEPT_DATA_FRONT_MAG: if(mFlash.exception.except_data_front_mag == 1){ return true; } break; case EXCEPT_DATA_CHARGE: if(mFlash.exception.except_data_charge == 1){ return true; } break; case EXCEPT_DATA_BATTERY: if(mFlash.exception.except_data_battery == 1){ return true; } break; case EXCEPT_MODE_SUSPEND_OVERFLOW: if(mFlash.exception.except_mode_suspend_overflow == 1){ return true; } break; default: break; } return false; } void Exception_Init(void) { Process_Start(0,"Exception_Process",Exception_Process); }