/*Includes ----------------------------------------------*/ #include "exception.h" #include "system.h" #include "app_flash.h" #include "hal_led.h" #include "hal_ser_imu_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; //异常灯翻转时长 bool is_change; //更改标志位 } 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; LED_Stop(LED_EXCEPT); } 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]; ser_imu_data_t data; //读取ACC值 if(hal_ser_imu_mode_manage_get_data_num(SER_IMU_DIR_FRONT) >= 1)hal_ser_imu_mode_manage_get_data(SER_IMU_DIR_FRONT, 0, &data); f_acc[0] = data.acc[0];f_acc[1] = data.acc[1];f_acc[2] = data.acc[2]; //把鞋子倒转平放,且存在异常 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; ob_exception.is_change = false; Process_Start(LED_PROCESS_CYCLE,"Exception_Led_Process",Exception_Led_Process); } void Except_SetExceptype(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++; ob_exception.is_change = true; } 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++; ob_exception.is_change = true; } 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++; ob_exception.is_change = true; } 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++; ob_exception.is_change = true; } break; case EXCEPT_DATA_CHARGE: if(mFlash.exception.except_data_charge != 1){ mFlash.exception.except_data_charge = 1; mFlash.exception.except_number_of_exist++; ob_exception.is_change = true; } break; case EXCEPT_DATA_BATTERY: if(mFlash.exception.except_data_battery != 1){ mFlash.exception.except_data_battery = 1; mFlash.exception.except_number_of_exist++; ob_exception.is_change = true; } 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++; ob_exception.is_change = true; } break; case EXCEPT_ANT_DAMAGE: if(mFlash.exception.except_ant_damage != 1){ mFlash.exception.except_ant_damage = 1; mFlash.exception.except_number_of_exist++; ob_exception.is_change = true; } break; } } void Except_ClearExceptype(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 = 0; if(mFlash.exception.except_number_of_exist != 0)mFlash.exception.except_number_of_exist--; ob_exception.is_change = true; } break; case EXCEPT_DATA_FRONT_ACC: if(mFlash.exception.except_data_front_acc == 1){ mFlash.exception.except_data_front_acc = 0; if(mFlash.exception.except_number_of_exist != 0)mFlash.exception.except_number_of_exist--; ob_exception.is_change = true; } break; case EXCEPT_DATA_FRONT_GRY: if(mFlash.exception.except_data_front_gry == 1){ mFlash.exception.except_data_front_gry = 0; if(mFlash.exception.except_number_of_exist != 0)mFlash.exception.except_number_of_exist--; ob_exception.is_change = true; } break; case EXCEPT_DATA_FRONT_MAG: if(mFlash.exception.except_data_front_mag == 1){ mFlash.exception.except_data_front_mag = 0; if(mFlash.exception.except_number_of_exist != 0)mFlash.exception.except_number_of_exist--; ob_exception.is_change = true; } break; case EXCEPT_DATA_CHARGE: if(mFlash.exception.except_data_charge == 1){ mFlash.exception.except_data_charge = 0; if(mFlash.exception.except_number_of_exist != 0)mFlash.exception.except_number_of_exist--; ob_exception.is_change = true; } break; case EXCEPT_DATA_BATTERY: if(mFlash.exception.except_data_battery == 1){ mFlash.exception.except_data_battery = 0; if(mFlash.exception.except_number_of_exist != 0)mFlash.exception.except_number_of_exist--; ob_exception.is_change = true; } break; case EXCEPT_MODE_SUSPEND_OVERFLOW: if(mFlash.exception.except_mode_suspend_overflow == 1){ mFlash.exception.except_mode_suspend_overflow = 0; if(mFlash.exception.except_number_of_exist != 0)mFlash.exception.except_number_of_exist--; ob_exception.is_change = true; } break; case EXCEPT_ANT_DAMAGE: if(mFlash.exception.except_ant_damage == 1){ mFlash.exception.except_ant_damage = 0; if(mFlash.exception.except_number_of_exist != 0)mFlash.exception.except_number_of_exist--; ob_exception.is_change = true; } break; } } bool Except_SaveExceptype(void) { if(ob_exception.is_change) { if(Flash_SaveInfomation() != ZONE_OP_SUCCESS) { return false; } ob_exception.is_change = false; } return true; } 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; case EXCEPT_ANT_DAMAGE: if(mFlash.exception.except_ant_damage == 1){ return true; } break; } return false; } bool Except_IsErrorExist(void) { if(mFlash.exception.except_number_of_exist > 0)return true; return false; }