#include "hal_mode_manage.h" #include "hal_imu.h" #include "usr_config.h" #include "bsp_time.h" #include "system.h" #include "hal_wearshoes.h" /********************************************************************* * LOCAL VARIABLES */ static hal_mode cur_mode; static hal_mode change_mode; static hal_mode process_mode; static uint8_t send_signal_flag = 0; static uint8_t critical_zone = 0; /********************************************************************* * LOCAL FUCTIONS */ static void Send_Signal(hal_mode mode) { switch(mode) { case HAL_MODE_GAME: if(IMU_GetCurrentMode() != STATE_FULL_POWER_MODE){ IMU_SetSignal(SIGNAL_FULL_POWER, IMU_SIGNAL_ON); send_signal_flag = 1; }else{ critical_zone = 0; //解锁 cur_mode = HAL_MODE_GAME; } break; case HAL_MODE_REALSTEP: if(IMU_GetCurrentMode() != STATE_FULL_POWER_MODE){ IMU_SetSignal(SIGNAL_FULL_POWER, IMU_SIGNAL_ON); send_signal_flag = 1; }else{ critical_zone = 0; //解锁 cur_mode = HAL_MODE_REALSTEP; } break; case HAL_MODE_STANDBY: if(IMU_GetCurrentMode() != STATE_STANDBY_POWER_MODE){ IMU_SetSignal(SIGNAL_STANDBY_POWER, IMU_SIGNAL_ON); send_signal_flag = 1; }else{ critical_zone = 0; //解锁 cur_mode = HAL_MODE_STANDBY; } break; case HAL_MODE_NORMAL: if(IMU_GetCurrentMode() != STATE_LOW_POWER_MODE){ IMU_SetSignal(SIGNAL_LOW_POWER, IMU_SIGNAL_ON); send_signal_flag = 1; }else{ critical_zone = 0; //解锁 cur_mode = HAL_MODE_NORMAL; } break; case HAL_MODE_SELF_CHECK: if(IMU_GetCurrentMode() != STATE_SELF_CHECK_MODE){ IMU_SetSignal(SIGNAL_SELF_CHECK, IMU_SIGNAL_ON); send_signal_flag = 1; }else{ critical_zone = 0; //解锁 cur_mode = HAL_MODE_SELF_CHECK; } break; default: break; } } static void Change_Mode(hal_mode mode) { switch(mode) { case HAL_MODE_GAME: if(IMU_GetCurrentMode() != STATE_FULL_POWER_MODE){ //配置失败,进入异常挂起模式 cur_mode = HAL_MODE_EXCEPT_SUSPEND; send_signal_flag = 0; critical_zone = 0; //解锁 }else{ if(IMU_Get_Front_Data_Num() >= 1 && IMU_Get_Front_Data_Num() < 10){ cur_mode = HAL_MODE_GAME; send_signal_flag = 0; critical_zone = 0; //解锁 } } break; case HAL_MODE_REALSTEP: if(IMU_GetCurrentMode() != STATE_FULL_POWER_MODE){ cur_mode = HAL_MODE_EXCEPT_SUSPEND; send_signal_flag = 0; critical_zone = 0; //解锁 }else{ if(IMU_Get_Front_Data_Num() >= 1 && IMU_Get_Front_Data_Num() < 10){ cur_mode = HAL_MODE_REALSTEP; send_signal_flag = 0; critical_zone = 0; //解锁 } } break; case HAL_MODE_STANDBY: if(IMU_GetCurrentMode() != STATE_STANDBY_POWER_MODE){ cur_mode = HAL_MODE_EXCEPT_SUSPEND; send_signal_flag = 0; critical_zone = 0; //解锁 }else{ if(IMU_Get_Front_Data_Num() >= 1 && IMU_Get_Front_Data_Num() < 10){ cur_mode = HAL_MODE_STANDBY; send_signal_flag = 0; critical_zone = 0; //解锁 } } break; case HAL_MODE_NORMAL: if(IMU_GetCurrentMode() != STATE_LOW_POWER_MODE){ cur_mode = HAL_MODE_EXCEPT_SUSPEND; send_signal_flag = 0; critical_zone = 0; //解锁 }else{ if(IMU_Get_Front_Data_Num() >= 10 && IMU_Get_Front_Data_Num() < 30){ cur_mode = HAL_MODE_NORMAL; send_signal_flag = 0; critical_zone = 0; //解锁 } } break; case HAL_MODE_SELF_CHECK: if(IMU_GetCurrentMode() != STATE_SELF_CHECK_MODE){ cur_mode = HAL_MODE_EXCEPT_SUSPEND; send_signal_flag = 0; critical_zone = 0; //解锁 }else{ if(IMU_Get_Front_Data_Num() >= 1 && IMU_Get_Front_Data_Num() < 10){ cur_mode = HAL_MODE_SELF_CHECK; send_signal_flag = 0; critical_zone = 0; //解锁 } } break; default: break; } } //转换规则 static void hal_mode_manage_Discipline(hal_mode *source_mode, hal_mode target_mode) { switch(*source_mode) { case HAL_MODE_EXCEPT_SUSPEND: *source_mode = target_mode; //异常挂起模式可转为任意模式 break; case HAL_MODE_STANDBY: *source_mode = target_mode; //待机模式可转为任意模式 break; case HAL_MODE_NORMAL: *source_mode = target_mode; //正常模式可转为任意模式 break; case HAL_MODE_SELF_CHECK: if(target_mode == HAL_MODE_NORMAL){ *source_mode = target_mode; //自检模式只能转为正常模式 } break; case HAL_MODE_GAME: if(target_mode == HAL_MODE_NORMAL){ *source_mode = target_mode; //游戏模式只能转为正常模式 } break; case HAL_MODE_REALSTEP: if(target_mode == HAL_MODE_NORMAL){ *source_mode = target_mode; //实时计步模式只能转为正常模式 } break; } } static void hal_mode_manage_Process(void) { //锁上期间,不更新 process_mode if(!critical_zone){ hal_mode_manage_Discipline(&process_mode, change_mode); critical_zone = 1; //锁上 } //没有信号的时候处理 if(IMU_IsNoSignal()){ if(!send_signal_flag){ //发送信号 Send_Signal(process_mode); }else{ //配置判断 Change_Mode(process_mode); } } } /********************** 外部接口声明区 *************************/ void hal_mode_set(hal_mode mode) { hal_mode_manage_Discipline(&change_mode, mode); } hal_mode hal_mode_get(void) { return cur_mode; } static void hal_mode_manage_test_Process(void) { SEGGER_RTT_printf(0,"IMU_IsNoSignal():%d change_mode=%d cur_mode=%d process_mode=%d critical_zone:%d IMU_GetCurrentMode():%d IMU_Get_Front_Data_Num():%d send_signal_flag:%d\r\n",IMU_IsNoSignal(),change_mode,cur_mode,process_mode,critical_zone,IMU_GetCurrentMode(),IMU_Get_Front_Data_Num(),send_signal_flag); } void hal_mode_manage_Init(void) { if(INIT_MODE == HAL_MODE_NORMAL){ cur_mode = HAL_MODE_NORMAL; change_mode = HAL_MODE_NORMAL; process_mode = HAL_MODE_NORMAL; } else if(INIT_MODE == HAL_MODE_STANDBY){ cur_mode = HAL_MODE_STANDBY; change_mode = HAL_MODE_STANDBY; process_mode = HAL_MODE_STANDBY; } Process_Start(0,"hal_mode_manage_Process",hal_mode_manage_Process); Process_Start(1000,"hal_mode_manage_test_Process",hal_mode_manage_test_Process); }