From 13cd19475cb91e0eebdc79743e32e77a2a212f0e Mon Sep 17 00:00:00 2001
From: yincheng.zhong <634916154@qq.com>
Date: 星期一, 22 一月 2024 22:20:38 +0800
Subject: [PATCH] 修改部分代码

---
 Src/application/dw_app.c |   33 +++++++++++++++++++--------------
 1 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/Src/application/dw_app.c b/Src/application/dw_app.c
index bea83cb..bdb24bd 100644
--- a/Src/application/dw_app.c
+++ b/Src/application/dw_app.c
@@ -253,6 +253,8 @@
   {
     current_count=HAL_LPTIM_ReadCounter(&hlptim1);
     target_count = GetUwbPollCount();
+    if(target_count<0)
+      target_count+=32768;
     while(current_count<target_count||current_count>target_count+16384)
     {
         current_count=HAL_LPTIM_ReadCounter(&hlptim1);
@@ -271,23 +273,26 @@
     bat_percent=Get_VDDVlotage();
     next_poll_state = Next_Poll_LORASYNC;
   }else{
-    current_count=HAL_LPTIM_ReadCounter(&hlptim1);
-    target_count = GetWGRecSyncCount()-2000/LPTIMER_LSB; //提前2ms进入接收状态
-    while(current_count<target_count||current_count>target_count+16384)
-    {
-        current_count=HAL_LPTIM_ReadCounter(&hlptim1);
-        if(current_count<target_count-300)
-        {
-            break;
-        }
-    }
-      LoraSyncRecPoll();
-      if(GetRangeState())
+     LoraSyncRecPoll();
+      if(GetRangeState())  //获取当前测距状态,是否开启。如果开启下次为测距,否为同步
       {
         next_poll_state = Next_Poll_RANGE;
       }else{
         next_poll_state = Next_Poll_LORASYNC;
-      }
-      
+      }      
+  }
+  if(next_poll_state == Next_Poll_LORASYNC)  
+  {
+   target_count = GetUwbPollCount()-4000/LPTIMER_LSB;  //同步则提前4ms唤醒,如果在同步间隔内,则会快速进入休眠。
+      if(target_count<0)
+      target_count+=32768;
+    __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count);
+  }else{
+
+        target_count = GetUwbPollCount()-2000/LPTIMER_LSB; //测距提前4ms唤醒
+     
+      if(target_count<0)
+      target_count+=32768;
+    __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count);
   }
 }

--
Gitblit v1.9.3