#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; //解锁 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; //解锁 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; //解锁 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; //解锁 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; //解锁 break; default: break; } } static void Change_Mode(hal_mode mode) { switch(mode) { case HAL_MODE_GAME: if(IMU_GetCurrentMode() != STATE_FULL_POWER_MODE){ //配置失败 change_mode = cur_mode; //回退到上一个模式 send_signal_flag = 0; critical_zone = 0; //解锁 }else{ if(IMU_Get_Front_Data_Num() >= 1 && IMU_Get_Front_Data_Num() < 3){ cur_mode = HAL_MODE_GAME; send_signal_flag = 0; critical_zone = 0; //解锁 } } break; case HAL_MODE_REALSTEP: if(IMU_GetCurrentMode() != STATE_FULL_POWER_MODE){ change_mode = cur_mode; send_signal_flag = 0; critical_zone = 0; //解锁 }else{ if(IMU_Get_Front_Data_Num() >= 1 && IMU_Get_Front_Data_Num() < 3){ cur_mode = HAL_MODE_REALSTEP; send_signal_flag = 0; critical_zone = 0; //解锁 } } break; case HAL_MODE_STANDBY: if(IMU_GetCurrentMode() != STATE_STANDBY_POWER_MODE){ change_mode = cur_mode; send_signal_flag = 0; critical_zone = 0; //解锁 }else{ if(IMU_Get_Front_Data_Num() >= 1 && IMU_Get_Front_Data_Num() < 3){ cur_mode = HAL_MODE_STANDBY; send_signal_flag = 0; critical_zone = 0; //解锁 } } break; case HAL_MODE_NORMAL: if(IMU_GetCurrentMode() != STATE_LOW_POWER_MODE){ change_mode = cur_mode; send_signal_flag = 0; critical_zone = 0; //解锁 }else{ if(IMU_Get_Front_Data_Num() >= 10 && IMU_Get_Front_Data_Num() < 13){ 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){ change_mode = cur_mode; send_signal_flag = 0; critical_zone = 0; //解锁 }else{ if(IMU_Get_Front_Data_Num() >= 1 && IMU_Get_Front_Data_Num() < 3){ cur_mode = HAL_MODE_SELF_CHECK; send_signal_flag = 0; critical_zone = 0; //解锁 } } break; default: break; } } static void hal_mode_manage_Process(void) { //没有信号的时候处理 if(IMU_IsNoSignal()){ if(!send_signal_flag){ //发送信号 Send_Signal(process_mode); }else{ //配置判断 Change_Mode(process_mode); } } } /********************** 外部接口声明区 *************************/ void hal_mode_set(hal_mode mode) { static hal_mode screen = HAL_MODE_INIT; //筛选出优先级最大的 screen = mode > screen ? mode : screen; change_mode = screen; SEGGER_RTT_printf(0,"=====>hal_mode_set change_mode:%d critical_zone:%d \r\n",change_mode,critical_zone); if(!critical_zone){ process_mode = change_mode; critical_zone = 1; //锁上 screen = HAL_MODE_INIT; } } hal_mode hal_mode_get(void) { return cur_mode; } static void hal_mode_manage_test_Process(void) { // SEGGER_RTT_printf(0,"change_mode=%d cur_mode=%d IMU_Get_Front_Data_Num():%d isWearShoes:%d\r\n",change_mode,cur_mode,IMU_Get_Front_Data_Num(),hal_wearshoes_is_wearshoes()); } void hal_mode_manage_Init(void) { if(INIT_MODE == HAL_MODE_NORMAL){ cur_mode = HAL_MODE_NORMAL; change_mode = HAL_MODE_NORMAL; } else if(INIT_MODE == HAL_MODE_STANDBY){ cur_mode = HAL_MODE_STANDBY; change_mode = HAL_MODE_STANDBY; } Process_Start(0,"hal_mode_manage_Process",hal_mode_manage_Process); Process_Start(100,"hal_mode_manage_test_Process",hal_mode_manage_test_Process); }