123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- #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){ //配置失败,保留上一个模式
- 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){
- 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){
- 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){
- 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){
- 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_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);
- }
|