From 526f2fbdaa4532c5bc0b6dffd7b9b84f784d7fef Mon Sep 17 00:00:00 2001
From: yincheng.zhong <634916154@qq.com>
Date: 星期一, 29 一月 2024 15:49:44 +0800
Subject: [PATCH] 1.76

---
 源码/核心板/Src/application/beep_logic_app.c |  221 ++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 169 insertions(+), 52 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 d93e96f..5527f4a 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"
@@ -4,61 +4,178 @@
 #include "global_param.h"
 #include "dw_app.h"
 
-void main_logic(void)	//主逻辑在这里执行
+#define ONTIME1 1   // 100ms
+#define OFFTIME1 0  // 100ms
+
+#define ONTIME2 1   // 100ms
+#define OFFTIME2 0  // 100ms
+
+#define ONTIME3 5   // 500ms
+#define OFFTIME3 5  // 500ms
+
+int32_t min_dist1,min_dist2;
+extern u16 JDQ_time;
+typedef enum{	
+    NO_ALARM,
+    YUJING_ALARM,
+    BAOJING_ALARM,
+}alarm_state;
+alarm_state alarm1 = NO_ALARM,alarm2 = NO_ALARM;
+void Relay1Task(u16 min_dist)
 {
+    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)
+                {
+                    alarm1 = BAOJING_ALARM;
+                }
+         else if (min_dist <= g_com_map[ALARM_DISTANCE3]+distoffset2)
+                {
+                    alarm1 = YUJING_ALARM;
+                }
+                else{
+                    alarm1 = NO_ALARM;
+                }
+                
+//                if(beep_state!=0)
+//                {
+//                    if(timer_state==1)
+//                    {
+//                        if(beep_timer++ < beep_ontime)
+//                        {
+//                            RELAY1_ON;
+//                           		
+//                        }else{
+//                            timer_state=0;
+//                            beep_timer=0;
+//                        }
+//                    }else{
+//                        if(beep_timer++ < beep_offtime)
+//                            {
+//                                RELAY1_OFF;
+//                       
+//                            }else{
+//                                    timer_state=1;
+//                                    beep_timer=0;
+//                            }
+//                        
+//                    }
+//                }else {
+//                    RELAY1_OFF;
+//                 //    RELAY2_OFF;
+//                }
+}
+void Relay2Task(u16 min_dist)
+{
+    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[RELAY2_DISTANCE2]+distoffset12)
+                {
+                    alarm2 = BAOJING_ALARM;
+                }
+         else if (min_dist <= g_com_map[RELAY2_DISTANCE3]+distoffset22)
+                {
+                    alarm2 = YUJING_ALARM;
+                }
+                else{
+                    alarm2 = NO_ALARM;
+                }
+                
+//                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;
+//                            }
+//                        
+//                    }
+//                }else {
+//                   // RELAY1_OFF;
+//                     RELAY2_OFF;
+//                }
+}
+void AlarmJuge(void)
+{
+    if(alarm1 == BAOJING_ALARM||alarm2 == BAOJING_ALARM)
+    {
+        RELAY1_ON;
+        RELAY2_ON;
+        return;
+    }else{
+        RELAY1_OFF;
+    }
+    if(alarm1 == YUJING_ALARM||alarm2 == YUJING_ALARM)
+    {
+        RELAY2_ON;
+    }else{
+        RELAY2_OFF;
+    }
+}
+extern uint16_t tagid_list[TAG_NUM_IN_SYS];
+extern u16 taglist_num;
+void main_logic(void)	//主逻辑在这里执行
+{	
+	uint16_t i;
 	//除UWB之外的其他代码...
 	static uint16_t beep_judge_cnt = 0;
-	if(beep_judge_cnt++ >= 200)
-	{	
-		beep_judge_cnt = 0;
-		
-		if(dis_after_filter <= g_com_map[ALARM_DISTANCE])
-		{
-			switch(g_com_map[ALARM_DEV]) 
-			{
-				case 0:
-					BEEP2_ON;
-					BEEP_OFF;
-					OUT2_OFF;
-					break;
-				case 1:
-					BEEP_ON;
-					BEEP2_OFF;
-					OUT2_OFF;
-					break;
-				case 2:
-					OUT2_ON;
-					BEEP_OFF;
-					BEEP2_OFF;
-					break;
-				default:
-					BEEP2_ON;
-					BEEP_ON;
-					OUT2_ON;
-					break;
-			}
-		}
-		else
-		{
-			switch(g_com_map[ALARM_DEV]) 
-			{
-				case 0:
-					BEEP2_OFF;
-					break;
-				case 1:
-					BEEP_OFF;
-					break;
-				case 2:
-					OUT2_OFF;
-					break;
-				default:
-					BEEP2_OFF;
-					BEEP_OFF;
-					OUT2_OFF;
-					break;
-			}
-		}
-	}
+    if(g_com_map[ALARM_DISTANCE1]!=0||g_com_map[ALARM_DISTANCE2]!=0||g_com_map[ALARM_DISTANCE3]!=0||g_com_map[RELAY2_DISTANCE1]!=0||g_com_map[RELAY2_DISTANCE2]!=0||g_com_map[RELAY2_DISTANCE3]!=0)
+    {
+            if(beep_judge_cnt++ >= 100)
+            {	
+                beep_judge_cnt = 0;
+                min_dist1=0x1ffff;
+                min_dist2=0x1ffff;
+                for(i = 0; i < taglist_num;i++)
+                {
+                    if((tagid_list[i]>>12)!=9)
+                    {
+                        if(g_Tagdist[i] < min_dist1&&g_Tagdist[i]>g_com_map[ALARM_DISTANCE1])
+                        {
+                            min_dist1=g_Tagdist[i];
+                        }
+                    }
+                    else{
+                        if(g_Tagdist[i] < min_dist2&&g_Tagdist[i]>g_com_map[RELAY2_DISTANCE1])
+                        {
+                            min_dist2=g_Tagdist[i];
+                        }
+                    }                   
+                }
+                Relay1Task(min_dist1);
+                Relay2Task(min_dist2);    
+                AlarmJuge();                
+            }
+    }else{
+        if(g_com_map[RELAY1ON_INDEX]==1)
+            {
+             RELAY1_ON;
+            }else if(g_com_map[RELAY1ON_INDEX]==0)
+            {
+             RELAY1_OFF;
+            }
+        if(g_com_map[RELAY2ON_INDEX]==1)
+            {
+             RELAY2_ON;
+            }else if(g_com_map[RELAY2ON_INDEX]==0)
+            {
+             RELAY2_OFF;
+            }    
+    }
 }	
 
 

--
Gitblit v1.9.3