From 31ee4794fbefac2963dee237aca3519c19218d46 Mon Sep 17 00:00:00 2001
From: zhyinch <zhyinch@gmail.com>
Date: 星期六, 14 八月 2021 19:56:55 +0800
Subject: [PATCH] 增加继电器分别控制,增加继电器持续时间控制

---
 源码/核心板/Src/application/beep_logic_app.c |  119 +++++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 86 insertions(+), 33 deletions(-)

diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/beep_logic_app.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/beep_logic_app.c"
index cd89445..546618f 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/beep_logic_app.c"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/beep_logic_app.c"
@@ -12,41 +12,25 @@
 
 #define ONTIME3 5   // 500ms
 #define OFFTIME3 5  // 500ms
-u8 distoffset1=0,distoffset2=0;
+
 uint16_t min_dist;
-void main_logic(void)	//主逻辑在这里执行
+extern u16 JDQ_time;
+void Relay1Task(void)
 {
-	static uint8_t beep_state,timer_state,beep_timer,beep_ontime,beep_offtime;
-	uint16_t i;
-	//除UWB之外的其他代码...
-	static uint16_t beep_judge_cnt = 0;
-    if(g_com_map[ALARM_DISTANCE1]!=0||g_com_map[ALARM_DISTANCE2]!=0||g_com_map[ALARM_DISTANCE3]!=0)
-    {
-            if(beep_judge_cnt++ >= 100)
-            {	
-                beep_judge_cnt = 0;
-                min_dist=0xffff;
-                for(i = 0; i < 255;i++)
-                {
-                    if(g_Tagdist[i] < min_dist&&g_Tagdist[i]>g_com_map[ALARM_DISTANCE1])
-                    {
-                        min_dist=g_Tagdist[i];
-                    }
-                        
-                }
-                
+    static u8 distoffset1=0,distoffset2=0;
+    static uint8_t beep_state,timer_state,beep_timer,beep_ontime,beep_offtime;
          if (min_dist <= g_com_map[ALARM_DISTANCE2]+distoffset1)
                 {
-                    beep_ontime = ONTIME2;
-                    beep_offtime = OFFTIME2;
+                    beep_ontime = JDQ_time;
+                    beep_offtime = JDQ_time;
                     beep_state=2;
                     distoffset1=0;
                     distoffset2=0;
                 }
          else if (min_dist <= g_com_map[ALARM_DISTANCE3]+distoffset2)
                 {
-                    beep_ontime = ONTIME3;
-                    beep_offtime = OFFTIME3;
+                    beep_ontime = JDQ_time;
+                    beep_offtime = JDQ_time;
                     beep_state=1;
                     distoffset1=0;
                     distoffset2=0;
@@ -64,7 +48,7 @@
                         if(beep_timer++ < beep_ontime)
                         {
                             RELAY1_ON;
-                            RELAY2_ON;		
+                           		
                         }else{
                             timer_state=0;
                             beep_timer=0;
@@ -73,18 +57,88 @@
                         if(beep_timer++ < beep_offtime)
                             {
                                 RELAY1_OFF;
-                                RELAY2_OFF;
+                       
                             }else{
                                     timer_state=1;
                                     beep_timer=0;
                             }
                         
                     }
-                
-                }	else {
-                    RELAY1_OFF;
-                     RELAY2_OFF;
                 }
+}
+void Relay2Task(void)
+{
+    static u8 distoffset12=0,distoffset22=0;
+    static uint8_t beep_state2,timer_state2,beep_timer2,beep_ontime2,beep_offtime2;
+         if (min_dist <= g_com_map[ALARM_DISTANCE2]+distoffset12)
+                {
+                    beep_ontime2 = JDQ_time;
+                    beep_offtime2 = JDQ_time;
+                    beep_state2=2;
+                    distoffset12=0;
+                    distoffset22=0;
+                }
+         else if (min_dist <= g_com_map[ALARM_DISTANCE3]+distoffset22)
+                {
+                    beep_ontime2 = JDQ_time;
+                    beep_offtime2 = JDQ_time;
+                    beep_state2=1;
+                    distoffset12=0;
+                    distoffset22=0;
+                }
+                else{
+                    beep_state2=0;
+                    distoffset12=0;
+                    distoffset22=0;
+                }
+                
+                if(beep_state2!=0)
+                {
+                    if(timer_state2==1)
+                    {
+                        if(beep_timer2++ < beep_ontime2)
+                        {
+                            RELAY2_ON;
+                           		
+                        }else{
+                            timer_state2=0;
+                            beep_timer2=0;
+                        }
+                    }else{
+                        if(beep_timer2++ < beep_offtime2)
+                            {
+                                RELAY2_OFF;
+                       
+                            }else{
+                                    timer_state2=1;
+                                    beep_timer2=0;
+                            }
+                        
+                    }
+                }
+}
+void main_logic(void)	//主逻辑在这里执行
+{	
+	uint16_t i;
+	//除UWB之外的其他代码...
+	static uint16_t beep_judge_cnt = 0;
+    if(g_com_map[ALARM_DISTANCE1]!=0||g_com_map[ALARM_DISTANCE2]!=0||g_com_map[ALARM_DISTANCE3]!=0)
+    {
+            if(beep_judge_cnt++ >= 100)
+            {	
+                beep_judge_cnt = 0;
+                min_dist=0xffff;
+                for(i = 0; i < 255;i++)
+                {
+                    if(g_Tagdist[i] < min_dist&&g_Tagdist[i]>g_com_map[ALARM_DISTANCE1])
+                    {
+                        min_dist=g_Tagdist[i];
+                    }
+                   
+                }
+                Relay1Task();
+                Relay2Task();
+         
             }
     }else{
         if(g_com_map[RELAY1ON_INDEX]==1)
@@ -100,8 +154,7 @@
             }else if(g_com_map[RELAY2ON_INDEX]==0)
             {
              RELAY2_OFF;
-            }
-    
+            }    
     }
 }	
 

--
Gitblit v1.9.3