zhyinch
2022-07-29 038ffb0327e40886b4db2eb8b3fcd1653aa264a3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "beep_logic_app.h"
#include "led.h"
#include "beep.h"
#include "global_param.h"
#include "dw_app.h"
 
#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;
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)
                {
                    beep_ontime = 1;
                    beep_offtime = 0;
                    beep_state=2;
                    distoffset1=0;
                    distoffset2=0;
                    beep_timer = 0;
                    timer_state = 1;
                }
         else if (min_dist <= g_com_map[ALARM_DISTANCE3]+distoffset2)
                {
                    beep_ontime = JDQ_time;
                    beep_offtime = JDQ_time;
                    beep_state=1;
                    distoffset1=0;
                    distoffset2=0;
                }
                else{
                    beep_state=0;
                    distoffset1=0;
                    distoffset2=0;
                    beep_timer = 0;
                    timer_state = 1;
                }
                
                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)
                {
                    beep_ontime2 = 1;
                    beep_offtime2 = 0;
                    beep_state2=2;
                    distoffset12=0;
                    distoffset22=0;
                    timer_state2=1;
                    beep_timer2=0;
                }
         else if (min_dist <= g_com_map[RELAY2_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;
                    timer_state2=1;
                    beep_timer2=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;
                            }
                        
                    }
                }else {
                   // RELAY1_OFF;
                     RELAY2_OFF;
                }
}
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||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 < 255;i++)
                {
                    if(g_Tagdist[i] < min_dist1&&g_Tagdist[i]>g_com_map[ALARM_DISTANCE1])
                    {
                        min_dist1=g_Tagdist[i];
                    }
                    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);
         
            }
    }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;
            }    
    }
}