123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- /*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; //异常灯翻转时长
-
- 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];
-
- //读取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;
- 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;
- }
|