zhangbo
2025-05-20 5ee4fd97245fed0d45fb60d1aa38cca83e788ed5
keil/include/main/main.c
@@ -336,6 +336,7 @@
extern uint16_t sleep_time;
uint8_t input5v_time;
extern uint8_t uwbled,btled,loraled,powerled;
uint8_t jibu_flag;
static void sleep_timer_callback(void *dev, uint32_t time)
{
     input5v_time=1;
@@ -343,8 +344,8 @@
     HIDO_TimerTick();
//     lora_tx_flag++;
     uwb_time_count++;
//    upload_apppoll();
    jibu_flag=1;
    upload_apppoll();
      if (current_state == STATE_NORMAL)
     {
@@ -394,12 +395,14 @@
}
uint16_t sleep_time=0;
uint32_t state_start_time_jibu=0;
uint8_t exercise_state=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;
@@ -417,6 +420,7 @@
//            state_start_time = uwb_time_count; // 重置测距周期
//        }
         current_state = STATE_NORMAL;
         exercise_state=1;
         last_step_count = step_count;
         
    } 
@@ -424,11 +428,12 @@
      {
        // 步数没有变化,检查是否需要切换到休眠状态
        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;
            }
          }
@@ -748,6 +753,7 @@
}
extern uint32_t uwb_time_count;
uint8_t uwbled,btled,loraled,powerled;
uint8_t send_count=0;
void upload_apppoll()
{   
     uint32_t elapsed_time_jibu;
@@ -759,16 +765,17 @@
                switch(elapsed_time_jibu)
                  {
                     case UWB_OPEN_COUNT:
//                           PCA9555_Set_One_Value_Output(BT_IRQ ,0);
                           PCA9555_Set_One_Value_Output(IO_KONG,0);
                          CloseUWB();
                           LoraReportPoll();
                              CloseUWB();
                    LEDTask(0,0,0,2);
                   LEDTask(0,0,0,2);
                     break;
                     
                     case UWB_MEASUREMENT_INTERVAL:
                           LEDTask(uwbled,btled,loraled,powerled);
                             PCA9555_Set_One_Value_Output(IO_KONG,0);
                           delay_us(10000);
                           PCA9555_Set_One_Value_Output(IO_KONG,1);
                              CloseUWB();
                              Uwbinit();
                              OpenUWB();
@@ -782,16 +789,17 @@
                switch(elapsed_time_jibu)
                  {
                     case UWB_OPEN_COUNT:
//                            PCA9555_Set_One_Value_Output(BT_IRQ ,0);
                    PCA9555_Set_One_Value_Output(IO_KONG,0);
                            CloseUWB();
                            CloseUWB();
                           LoraReportPoll();
                           LEDTask(0,0,0,2);
                     break;
                     
                     case UWB_MEASUREMENT_INTERVAL_SLEEP:
                           LEDTask(uwbled,btled,loraled,powerled);
                             PCA9555_Set_One_Value_Output(IO_KONG,0);
                           delay_us(10000);
                           PCA9555_Set_One_Value_Output(IO_KONG,1);
                              CloseUWB();
                              Uwbinit();
                              OpenUWB();                                 
@@ -897,11 +905,16 @@
//      boot_deinit();
    while (1)
    { 
        step_count = mir3da_get_step(); // 获取步数
         if(jibu_flag)
         {
            jibu_flag=0;
           step_count = mir3da_get_step(); // 获取步数
         }
//       Lora_Tx_Poll();
         uwb_app_poll();
         check_step_and_update_state();
         upload_apppoll();
//         upload_apppoll();
      IdleTask();
         IMUTask();