keil/include/main/main.c
@@ -46,6 +46,8 @@
#define UWB_MEASUREMENT_INTERVAL 5
#define UWB_MEASUREMENT_INTERVAL_SLEEP 30
#define INACTIVE_TIMEOUT 30
extern uint8_t mUsartReceivePack[100];
extern uint8_t mUsart2ReceivePack[150];
extern uint8_t state5V_prase_flag,gps_prase_flag;
@@ -422,6 +424,57 @@
     delaysleep_count--;
}
#ifdef JIBU_XIUMIAN
uint16_t sleep_time=0;
uint32_t state_start_time_jibu=0;
uint8_t exercise_state=0;
uint32_t step_count = 0;      // 步数计数
uint32_t last_step_count = 0; // 上一次步数
void check_step_and_update_state(void)
{
    if ((step_count != last_step_count))
      {
        // 步数有变化,重置状态为正常状态
      last_step_count = step_count;
         if(current_state == STATE_SLEEP)
         {
            state_start_time_jibu = uwb_time_count;
            state_start_time=uwb_time_count;
         }
//         if (current_state != STATE_NORMAL)
//            {
//            // 关闭可能正在运行的UWB
//            if (uwb_is_on) {
//                CloseUWB();
//                UWB_LED_OFF;
//                uwb_is_on = false;
//            }
//            current_state = STATE_NORMAL;
//            state_start_time = uwb_time_count; // 重置测距周期
//        }
         current_state = STATE_NORMAL;
         exercise_state=1;
         last_step_count = step_count;
    }
      else
      {
        // 步数没有变化,检查是否需要切换到休眠状态
        if (current_state == STATE_NORMAL)
               {
            uint32_t inactive_time = uwb_time_count - state_start_time_jibu;
            if (inactive_time >= INACTIVE_TIMEOUT)
                  { // 30秒后切换到休眠状态
                current_state = STATE_SLEEP;
                       exercise_state=2;
                       state_start_time_jibu=uwb_time_count;
            }
          }
     }
}
#endif
static void pca_handler(enum IO_PIN_T pin)
{
   PCA9555_readdata(PCA9555_DEVICE_ADDR,pca9555writedata_input);//读输入寄存器的值
@@ -780,7 +833,7 @@
    else if(current_state==STATE_SLEEP)
    {
            elapsed_time_jibu = uwb_time_count - state_start_time;
            switch(elapsed_time_jibu==1)
            switch(elapsed_time_jibu)
            {
            case UWB_OPEN_COUNT:
                CloseUWB();
@@ -969,5 +1022,6 @@
        }
          IMUTask();
        IdleTask();
            check_step_and_update_state();
    }
}