/*Includes ----------------------------------------------*/ #include "exception.h" #include "system.h" #include "app_flash.h" #include "hal_imu.h" #include "hal_led.h" #include "hal_mode_manage.h" #include "bsp_time.h" /*Private macro ------------------------------------------------*/ #define EXCEPT_LED_ON_ACC_Z 1500 //加速度Z轴触发异常灯开启 #define EXCEPT_LED_OFF_ACC_Z -1500 //加速度Z轴触发异常灯关闭 #define LED_PROCESS_CYCLE 200 //异常灯线程周期,ms为单位 #define EXCEPT_LED_TOGGLE_TIME 200 //异常灯翻转周期,ms为单位 #define EXCEPT_LED_DISPLAY_TIME 10000 //异常灯显示时长,ms为单位 /*STRUCTION ----------------------------------------------------*/ typedef enum{ EXCEPT_LED_ON, //异常灯 - 开 EXCEPT_LED_OFF, //异常灯 - 关 } EXCEPT_LED_SWITCH_e; typedef struct exception{ /*private member*/ EXCEPT_LED_SWITCH_e led_switch; //异常灯开关 uint16_t led_display_time; //异常灯显示时长 uint16_t led_toggle_time; //异常灯翻转时长 } Exception_t; /*Local Variable ----------------------------------------------*/ static Exception_t ob_exception; /*Local Functions ----------------------------------------------*/ static void Exception_Led_Process(void); static void Except_Led_Close(void) { //全功率关闭 Process_SetHoldOn(Exception_Led_Process,0); ob_exception.led_switch = EXCEPT_LED_OFF; ob_exception.led_display_time = EXCEPT_LED_DISPLAY_TIME/LED_PROCESS_CYCLE; ob_exception.led_toggle_time = EXCEPT_LED_TOGGLE_TIME/LED_PROCESS_CYCLE; } static void Except_Led_OpenOnce(void) { //异常灯显示/关闭 if(ob_exception.led_display_time != 0) { //全功率开启 Process_SetHoldOn(Exception_Led_Process,1); if(ob_exception.led_toggle_time == 0) { if(ob_exception.led_switch == EXCEPT_LED_ON)ob_exception.led_switch = EXCEPT_LED_OFF; else ob_exception.led_switch = EXCEPT_LED_ON; ob_exception.led_toggle_time = EXCEPT_LED_TOGGLE_TIME/LED_PROCESS_CYCLE; } else { if(ob_exception.led_switch == EXCEPT_LED_ON)LED_Start(LED_EXCEPT,COLOR_ORANGE); if(ob_exception.led_switch == EXCEPT_LED_OFF)LED_Start(LED_EXCEPT,COLOR_BLACK); ob_exception.led_toggle_time--; } ob_exception.led_display_time--; } } static void Exception_Led_Process(void) { int16_t f_acc[3]; //读取ACC值 if(IMU_Get_Front_Data_Num() >= 1)IMU_Get_Front_Data(IMU_Get_Front_Data_Num()-1, NULL, f_acc, NULL, NULL); //把鞋子倒转平放,且存在异常 if(f_acc[2] >= EXCEPT_LED_ON_ACC_Z && mFlash.exception.except_number_of_exist > 0) { Except_Led_OpenOnce(); }//把鞋子正放 else if(f_acc[2] <= EXCEPT_LED_OFF_ACC_Z) { Except_Led_Close(); } } /*API ----------------------------------------------*/ void Exception_Init(void) { ob_exception.led_switch = EXCEPT_LED_OFF; ob_exception.led_display_time = EXCEPT_LED_DISPLAY_TIME/LED_PROCESS_CYCLE; ob_exception.led_toggle_time = EXCEPT_LED_TOGGLE_TIME/LED_PROCESS_CYCLE; Process_Start(LED_PROCESS_CYCLE,"Exception_Led_Process",Exception_Led_Process); } 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; } } uint32_t Except_IsError(ExcepType_t excep_type) { switch(excep_type) { case EXCEPT_DATA_BACK_MAG: if(mFlash.exception.except_data_back_mag == 1){ return 1; } break; case EXCEPT_DATA_FRONT_ACC: if(mFlash.exception.except_data_front_acc == 1){ return 1; } break; case EXCEPT_DATA_FRONT_GRY: if(mFlash.exception.except_data_front_gry == 1){ return 1; } break; case EXCEPT_DATA_FRONT_MAG: if(mFlash.exception.except_data_front_mag == 1){ return 1; } break; case EXCEPT_DATA_CHARGE: if(mFlash.exception.except_data_charge == 1){ return 1; } break; case EXCEPT_DATA_BATTERY: if(mFlash.exception.except_data_battery == 1){ return 1; } break; case EXCEPT_MODE_SUSPEND_OVERFLOW: if(mFlash.exception.except_mode_suspend_overflow == 1){ return 1; } break; default: break; } return 0; } bool Except_IsErrorExist(void) { if(mFlash.exception.except_number_of_exist > 0)return true; return false; }