1 /*
2 * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <stdio.h>
17 #include <unistd.h>
18 #include "ohos_init.h"
19 #include "cmsis_os2.h"
20 #include "iot_pwm.h"
21 #include "iot_i2c.h"
22 #include "iot_gpio.h"
23 #include "hi_timer.h"
24 #include "hi_gpio.h"
25 #include "app_demo_multi_sample.h"
26 #include "ssd1306_oled.h"
27 #include "app_demo_i2c_oled.h"
28 #include "app_demo_config.h"
29
30 #define IOT_GPIO_INDEX_9 9
31 #define IOT_GPIO_INDEX_10 10
32 #define IOT_GPIO_INDEX_11 11
33 #define IOT_GPIO_INDEX_12 12
34
35 #define IO_FUNC_GPIO_9_PWM0_OUT 5
36 #define IO_FUNC_GPIO_OUT 0
37
38 unsigned char g_ledCountFlag = 0;
39
40 #define HUMAN_MODU_RED_COUNT_SECOND (30)
41 #define COUNT_FIVE_SECOND (5)
42 #define COUNT_THREE_SECOND_FLASH (3)
43
44 #define COUNT_MAX_SECOND (4294967296)
45
46 #define DELAY_CYCLE_COUNT (20000)
47 #define CN_QUEUE_WAITTIMEOUT 1000
48 #define LED_FLASHING_TIME (7)
49 #define LAMP_FLASHING_TIME_RESET (1)
50 #define LAMP_FLASHING_TIME_RESET_0 (0)
51 #define DATA_OUT_OF_BOUND (-1)
52 #define AUTO_MODULE_LIGHT_ON_TIME (6)
53 #define DATA_OUT_OF_BOUND (-1)
54 #define AUTO_MODULE_LIGHT_ON_TIME_10_SECOND (10)
55 #define AUTO_MODULE_LIGHT_ON_TIME_30_SECOND (31)
56
57 static unsigned int g_redLedAutoModuTimeCount = 0;
58 static unsigned int g_yellowLedAutoModuTimeCount = 0;
59 static unsigned int g_greenLedAutoModuTimeCount = 0;
60
61 static unsigned int redLedHumanModuTimeCount = 0;
62 static unsigned int yellowLedHumanModuTimeCount = 0;
63 static unsigned int greenLedHumanModuTimeCount = 0;
64
65 unsigned int g_redLedHumanModuTimeCounts = 0;
66 unsigned int g_yellowLedHumanModuTimeCounts = 0;
67 unsigned int g_greenLedHumanModuTimeCounts = 0;
68
69 static unsigned int timer1Count = LED_FLASHING_TIME;
70 static unsigned int timer7Count = LED_FLASHING_TIME;
71 static unsigned int humanTimerCount = LED_FLASHING_TIME;
72 static int timer2Count = AUTO_MODULE_LIGHT_ON_TIME;
73 static int timer6Count = AUTO_MODULE_LIGHT_ON_TIME_30_SECOND;
74 static int humanRedTimerCount = AUTO_MODULE_LIGHT_ON_TIME;
75 static unsigned int timer3Count = LED_FLASHING_TIME;
76 static unsigned int timer8Count = LED_FLASHING_TIME;
77 static unsigned int yellowHumanCount = LED_FLASHING_TIME;
78 static unsigned int timer4Count = AUTO_MODULE_LIGHT_ON_TIME;
79 static unsigned int timer9Count = AUTO_MODULE_LIGHT_ON_TIME;
80 static unsigned int humanGreenTimerCount = AUTO_MODULE_LIGHT_ON_TIME;
81 static unsigned int timer5Count = LED_FLASHING_TIME;
82 static unsigned int timer10Count = LED_FLASHING_TIME;
83 static unsigned int humanGreenFlashCount = LED_FLASHING_TIME;
84
85 TrafficLedStatusType trafficStaType = {0};
86
87 LightTimerCfg TrafficLightTimer = {
88 .Timer1Status = 0,
89 .Timer1Count = 0xff,
90 .Timer2Status = 0,
91 .Timer2Count = 0xff,
92 .Timer3Status = 0,
93 .Timer3Count = 0xff,
94 .Timer3Status = 0,
95 .Timer4Count = 0xff,
96 .Timer5Status = 0,
97 .Timer5Count = 0xff,
98 .Timer6Status = 0,
99 .Timer6Count = 0xff,
100 .Timer7Status = 0,
101 .Timer7Count = 0xff,
102 .Timer8Status = 0,
103 .Timer8Count = 0xff,
104 .Timer9Status = 0,
105 .Timer9Count = 0xff,
106 .Timer10Status = 0,
107 .Timer10Count = 0xff,
108 .TimerYellowLightStatus = 0,
109 .TimerRedLightStatus = 0,
110 .TimerGreenLightStatus = 0,
111 };
112
113
114 /* Set timer count status */
SetTimeCount(unsigned char setTimeCount)115 unsigned char SetTimeCount(unsigned char setTimeCount)
116 {
117 return setTimeCount;
118 }
119 /*
120 * @bref delay time and fresh screen
121 * @param unsigned int delay_time :delay unit us
122 * unsigned char beep_status: 0/1, 0:beep off, 1:beep on
123 */
124 #define MODULUS_OR_REMAINDER (10)
125
RedOledLedLigthTimeShowNum9(void)126 static void RedOledLedLigthTimeShowNum9(void)
127 {
128 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
129 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
130 "R:9 Y:0 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
131 } else {
132 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
133 "R:9 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
134 }
135 }
136
RedOledLedLigthTimeShowNum8(void)137 static void RedOledLedLigthTimeShowNum8(void)
138 {
139 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
140 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
141 "R:8 Y:0 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
142 } else {
143 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
144 "R:8 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
145 }
146 }
147
RedOledLedLigthTimeShowNum7(void)148 static void RedOledLedLigthTimeShowNum7(void)
149 {
150 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
151 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
152 "R:7 Y:0 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
153 } else {
154 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
155 "R:7 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
156 }
157 }
158
RedOledLedLigthTimeShowNum6(void)159 static void RedOledLedLigthTimeShowNum6(void)
160 {
161 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
162 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
163 "R:6 Y:0 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
164 } else {
165 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
166 "R:6 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
167 }
168 }
169
RedOledLedLigthTimeShowNum5(void)170 static void RedOledLedLigthTimeShowNum5(void)
171 {
172 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
173 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
174 "R:5 Y:0 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
175 } else {
176 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
177 "R:5 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
178 }
179 }
180
RedOledLedLigthTimeShowNum4(void)181 static void RedOledLedLigthTimeShowNum4(void)
182 {
183 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
184 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
185 "R:4 Y:0 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
186 } else {
187 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
188 "R:4 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
189 }
190 }
191
RedOledLedLigthTimeShowNum3(void)192 static void RedOledLedLigthTimeShowNum3(void)
193 {
194 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
195 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
196 "R:3 Y:0 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
197 } else {
198 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
199 "R:3 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
200 }
201 }
202
RedOledLedLigthTimeShowNum2(void)203 static void RedOledLedLigthTimeShowNum2(void)
204 {
205 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
206 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
207 "R:2 Y:0 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
208 } else {
209 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
210 "R:2 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
211 }
212 }
213
RedOledLedLigthTimeShowNum1(void)214 static void RedOledLedLigthTimeShowNum1(void)
215 {
216 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
217 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
218 "R:1 Y:0 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
219 } else {
220 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
221 "R:1 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
222 }
223 }
224
RedOledLedLigthTimeShowNum0(void)225 static void RedOledLedLigthTimeShowNum0(void)
226 {
227 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
228 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
229 "R:0 Y:0 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
230 } else {
231 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
232 "R:0 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
233 }
234 }
235 // 绿色
GreenOledLedLigthTimeShowNum9(void)236 static void GreenOledLedLigthTimeShowNum9(void)
237 {
238 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
239 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
240 "R:0 Y:0 G:9 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
241 } else {
242 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
243 "R:0 Y:0 G:9 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
244 }
245 }
246
GreenOledLedLigthTimeShowNum8(void)247 static void GreenOledLedLigthTimeShowNum8(void)
248 {
249 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
250 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
251 "R:0 Y:0 G:8 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
252 } else {
253 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
254 "R:0 Y:0 G:8 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
255 }
256 }
257
GreenOledLedLigthTimeShowNum7(void)258 static void GreenOledLedLigthTimeShowNum7(void)
259 {
260 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
261 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
262 "R:0 Y:0 G:7 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
263 } else {
264 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
265 "R:0 Y:0 G:7 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
266 }
267 }
268
GreenOledLedLigthTimeShowNum6(void)269 static void GreenOledLedLigthTimeShowNum6(void)
270 {
271 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
272 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
273 "R:0 Y:0 G:6 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
274 } else {
275 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
276 "R:0 Y:0 G:6 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
277 }
278 }
279
GreenOledLedLigthTimeShowNum5(void)280 static void GreenOledLedLigthTimeShowNum5(void)
281 {
282 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
283 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
284 "R:0 Y:0 G:5 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
285 } else {
286 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
287 "R:0 Y:0 G:5 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
288 }
289 }
290
GreenOledLedLigthTimeShowNum4(void)291 static void GreenOledLedLigthTimeShowNum4(void)
292 {
293 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
294 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
295 "R:0 Y:0 G:4 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
296 } else {
297 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
298 "R:0 Y:0 G:4 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
299 }
300 }
301
GreenOledLedLigthTimeShowNum3(void)302 static void GreenOledLedLigthTimeShowNum3(void)
303 {
304 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
305 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
306 "R:0 Y:0 G:3 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
307 } else {
308 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
309 "R:0 Y:0 G:3 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
310 }
311 }
312
GreenOledLedLigthTimeShowNum2(void)313 static void GreenOledLedLigthTimeShowNum2(void)
314 {
315 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
316 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
317 "R:0 Y:0 G:2 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
318 } else {
319 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
320 "R:0 Y:0 G:2 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
321 }
322 }
323
GreenOledLedLigthTimeShowNum1(void)324 static void GreenOledLedLigthTimeShowNum1(void)
325 {
326 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
327 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
328 "R:0 Y:0 G:1 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
329 } else {
330 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
331 "R:0 Y:0 G:1 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
332 }
333 }
334
GreenOledLedLigthTimeShowNum0(void)335 static void GreenOledLedLigthTimeShowNum0(void)
336 {
337 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
338 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
339 "R:0 Y:0 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
340 } else {
341 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
342 "R:0 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
343 }
344 }
OledLedLightHumanReckonShow(int timeCount)345 int OledLedLightHumanReckonShow(int timeCount)
346 {
347 int ret = 0;
348 unsigned char showTimeCount[4] = {0};
349 unsigned char beepStatus[2] = {0};
350 char *space = " ";
351 static int status = 0;
352 static int sta = 0;
353 static unsigned char currentMode = 0;
354 static unsigned char currentType = 0;
355
356 if (!status) {
357 status = HI_TRUE;
358 currentMode = GetKeyStatus(CURRENT_MODE);
359 currentType = GetKeyStatus(CURRENT_TYPE);
360 }
361 if ((currentMode != GetKeyStatus(CURRENT_MODE)) || (currentType != GetKeyStatus(CURRENT_TYPE))) {
362 GpioControl(IOT_GPIO_INDEX_10, IOT_GPIO_INDEX_10, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE0, IO_FUNC_GPIO_OUT);
363 return KEY_DOWN_INTERRUPT;
364 }
365 ret = snprintf_s(showTimeCount, sizeof(showTimeCount), sizeof(showTimeCount), "%d", timeCount);
366 if (ret < 0) {
367 printf("change data format failed\r\n");
368 }
369 if (timeCount == AUTO_MODULE_LIGHT_ON_TIME_30_SECOND - 1) { /* 1: 0ffset */
370 sta = HI_FALSE;
371 }
372 if (timeCount < AUTO_MODULE_LIGHT_ON_TIME_10_SECOND && sta == HI_FALSE) {
373 sta = HI_TRUE;
374 OledShowStr(OLED_X_POSITION_16, OLED_Y_POSITION_7,
375 space, OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
376 }
377 OledShowStr(OLED_X_POSITION_16, OLED_Y_POSITION_7,
378 showTimeCount, OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
379 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
380 ret = snprintf_s(beepStatus, sizeof(beepStatus), sizeof(beepStatus), "%d", BEEP_ON);
381 if (ret < 0) {
382 printf("change data format failed\r\n");
383 }
384 OledShowStr(OLED_X_POSITION_120, OLED_Y_POSITION_7,
385 beepStatus, OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
386 } else {
387 ret = snprintf_s(beepStatus, sizeof(beepStatus), sizeof(beepStatus), "%d", BEEP_OFF);
388 if (ret < 0) {
389 printf("change data format failed\r\n");
390 }
391 OledShowStr(OLED_X_POSITION_120, OLED_Y_POSITION_7,
392 beepStatus, OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
393 }
394 return 0;
395 }
396
397 // 红灯
OledLedLigthReckonByTimeShow(int timeCount)398 void OledLedLigthReckonByTimeShow(int timeCount)
399 {
400 switch (timeCount) {
401 case FIVE:
402 RedOledLedLigthTimeShowNum5();
403 break;
404 case FOUR:
405 RedOledLedLigthTimeShowNum4();
406 break;
407 case THREE:
408 RedOledLedLigthTimeShowNum3();
409 break;
410 case TWO:
411 RedOledLedLigthTimeShowNum2();
412 break;
413 case ONE:
414 RedOledLedLigthTimeShowNum1();
415 break;
416 case ZERO:
417 RedOledLedLigthTimeShowNum0();
418 break;
419 default:
420 break;
421 }
422 }
423
424 // 绿灯
GreenOledLedLigthReckonByTimeShow(unsigned int timeCount)425 void GreenOledLedLigthReckonByTimeShow(unsigned int timeCount)
426 {
427 switch (timeCount) {
428 case FIVE:
429 GreenOledLedLigthTimeShowNum5();
430 break;
431 case FOUR:
432 GreenOledLedLigthTimeShowNum4();
433 break;
434 case THREE:
435 GreenOledLedLigthTimeShowNum3();
436 break;
437 case TWO:
438 GreenOledLedLigthTimeShowNum2();
439 break;
440 case ONE:
441 GreenOledLedLigthTimeShowNum1();
442 break;
443 case ZERO:
444 GreenOledLedLigthTimeShowNum0();
445 break;
446 default:
447 break;
448 }
449 }
450
SetBeepOperation(unsigned char beep)451 void SetBeepOperation(unsigned char beep)
452 {
453 unsigned char bp = beep;
454
455 if (bp == BEEP_ON) {
456 IoTPwmStart(HI_PWM0, PWM_DUTY, PWM_SMALL_DUTY); /* 0, xx, xx */
457 bp = BEEP_OFF;
458 } else {
459 IoTPwmStart(HI_PWM0, PWM_LOW_DUTY, PWM_FULL_DUTY); /* 0, xx, xx */
460 bp = BEEP_ON;
461 }
462 }
463
SetBeepStatus(int cnt,unsigned char beepStatus,unsigned char beep)464 void SetBeepStatus(int cnt, unsigned char beepStatus, unsigned char beep)
465 {
466 switch (beepStatus) {
467 case BEEP_BY_ONE_SECOND:
468 if ((cnt % BEEP_ONE_SECOND_INTERVAL) == DEFAULT_TYPE) {
469 SetBeepOperation(beep);
470 }
471 break;
472 case BEEP_BY_HALF_SECOND:
473 if ((cnt % BEEP_HALF_SECOND_INTERVAL) == DEFAULT_TYPE) {
474 SetBeepOperation(beep);
475 }
476 break;
477 case BEEP_BY_QUARTER_SECOND:
478 if ((cnt % BEEP_QUARTER_SECOND_INTERVAL) == DEFAULT_TYPE) {
479 SetBeepOperation(beep);
480 }
481 break;
482 default:
483 break;
484 }
485 }
486
487 unsigned char g_trafficAutoModeCurrent = TRAFFIC_AUTO_MODE;
RedTimeCount6(void)488 void RedTimeCount6(void)
489 {
490 GpioControl(IOT_GPIO_INDEX_10, IOT_GPIO_INDEX_10, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE1, IO_FUNC_GPIO_OUT);
491 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
492 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
493 "R:3 Y:0 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
494 } else {
495 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
496 "R:3 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
497 }
498 }
RedTimeCount4(void)499 void RedTimeCount4(void)
500 {
501 GpioControl(IOT_GPIO_INDEX_10, IOT_GPIO_INDEX_10, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE1, IO_FUNC_GPIO_OUT);
502 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
503 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
504 "R:2 Y:0 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
505 } else {
506 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
507 "R:2 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
508 }
509 }
RedTimeCount2(void)510 void RedTimeCount2(void)
511 {
512 GpioControl(IOT_GPIO_INDEX_10, IOT_GPIO_INDEX_10, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE1, IO_FUNC_GPIO_OUT);
513 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
514 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
515 "R:1 Y:0 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
516 } else {
517 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
518 "R:1 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
519 }
520 }
RedTimeCount0(void)521 void RedTimeCount0(void)
522 {
523 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
524 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
525 "R:0 Y:0 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
526 } else {
527 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
528 "R:0 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
529 }
530 }
531
RedLedLigthReckonByTimeShow(unsigned int timeCount)532 static void RedLedLigthReckonByTimeShow(unsigned int timeCount)
533 {
534 switch (timeCount) {
535 case TIME_COUNT_6:
536 RedTimeCount6();
537 break;
538 case TIME_COUNT_5:
539 GpioControl(IOT_GPIO_INDEX_10, IOT_GPIO_INDEX_10, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE0, IO_FUNC_GPIO_OUT);
540 break;
541 case TIME_COUNT_4:
542 RedTimeCount4();
543 break;
544 case TIME_COUNT_3:
545 GpioControl(IOT_GPIO_INDEX_10, IOT_GPIO_INDEX_10, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE0, IO_FUNC_GPIO_OUT);
546 break;
547 case TIME_COUNT_2:
548 RedTimeCount2();
549 break;
550 case TIME_COUNT_1:
551 GpioControl(IOT_GPIO_INDEX_10, IOT_GPIO_INDEX_10, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE0, IO_FUNC_GPIO_OUT);
552 break;
553 case TIME_COUNT_0:
554 RedTimeCount0();
555 break;
556 default:
557 break;
558 }
559 }
560
OledAutoRedLedLigthReckonByTimeShow(unsigned int timeCount)561 static int OledAutoRedLedLigthReckonByTimeShow(unsigned int timeCount)
562 {
563 static unsigned char currentMode = 0;
564 static unsigned char currentType = 0;
565 static unsigned char sta = 0;
566 int ret = 0;
567
568 OledAutoHumanGreenBeepControl();
569 /* auto mode */
570 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_AUTO_MODE) {
571 currentMode = GetKeyStatus(CURRENT_MODE);
572 currentType = GetKeyStatus(CURRENT_TYPE);
573 RedLedLigthReckonByTimeShow(timeCount);
574 }
575
576 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE) {
577 if (currentMode != GetKeyStatus(CURRENT_MODE)) {
578 return KEY_DOWN_INTERRUPT;
579 }
580 }
581 return 0;
582 }
583
OledHumanNormalRedLedLigthReckonByTimeShow(unsigned int timeCount)584 static int OledHumanNormalRedLedLigthReckonByTimeShow(unsigned int timeCount)
585 {
586 static unsigned char currentMode = 0;
587 static unsigned char currentType = 0;
588 static unsigned char sta = 0;
589 int ret = 0;
590
591 OledAutoHumanGreenBeepControl();
592 /* human control mode */
593 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE &&
594 GetKeyStatus(CURRENT_TYPE) == TRAFFIC_NORMAL_TYPE) {
595 currentMode = GetKeyStatus(CURRENT_MODE);
596 currentType = GetKeyStatus(CURRENT_TYPE);
597 RedLedLigthReckonByTimeShow(timeCount);
598 }
599
600 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_RETURN_MODE) {
601 if (currentMode != GetKeyStatus(CURRENT_MODE)) {
602 return KEY_DOWN_INTERRUPT;
603 }
604 }
605
606 if (currentType != GetKeyStatus(CURRENT_TYPE)) {
607 currentType = GetKeyStatus(CURRENT_TYPE);
608 return KEY_DOWN_INTERRUPT;
609 }
610 return 0;
611 }
612
OledHumanRedLedLigthReckonByTimeShow(unsigned int timeCount)613 static int OledHumanRedLedLigthReckonByTimeShow(unsigned int timeCount)
614 {
615 static unsigned char currentMode = 0;
616 static unsigned char currentType = 0;
617 static unsigned char sta = 0;
618 int ret = 0;
619
620 OledAutoHumanGreenBeepControl();
621 /* human control mode */
622 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE &&
623 GetKeyStatus(CURRENT_TYPE) == TRAFFIC_HUMAN_TYPE) {
624 currentMode = GetKeyStatus(CURRENT_MODE);
625 currentType = GetKeyStatus(CURRENT_TYPE);
626 RedLedLigthReckonByTimeShow(timeCount);
627 }
628
629 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_RETURN_MODE) {
630 if (currentMode != GetKeyStatus(CURRENT_MODE)) {
631 return KEY_DOWN_INTERRUPT;
632 }
633 }
634
635 if (currentType != GetKeyStatus(CURRENT_TYPE)) {
636 currentType = GetKeyStatus(CURRENT_TYPE);
637 return KEY_DOWN_INTERRUPT;
638 }
639 return 0;
640 }
641
OledRedLedLigthOnFlashRecordShow(unsigned int timeCount)642 static int OledRedLedLigthOnFlashRecordShow(unsigned int timeCount)
643 {
644 int ret = 0;
645
646 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_AUTO_MODE) {
647 ret = OledAutoRedLedLigthReckonByTimeShow(timeCount);
648 if (ret == KEY_DOWN_INTERRUPT) {
649 return KEY_DOWN_INTERRUPT;
650 }
651 }
652
653 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE) {
654 ret = OledHumanRedLedLigthReckonByTimeShow(timeCount);
655 if (ret == KEY_DOWN_INTERRUPT) {
656 return KEY_DOWN_INTERRUPT;
657 }
658 }
659
660 return 0;
661 }
662
OledAutoRedLedLigthFiveSecondCountShow(unsigned int timeCount)663 static int OledAutoRedLedLigthFiveSecondCountShow(unsigned int timeCount)
664 {
665 static unsigned char currentMode = 0;
666 static unsigned char currentType = 0;
667 static unsigned char sta = 0;
668 int ret = 0;
669
670 OledAutoHumanGreenBeepControl();
671 /* auto mode */
672 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_AUTO_MODE) {
673 currentMode = GetKeyStatus(CURRENT_MODE);
674 currentType = GetKeyStatus(CURRENT_TYPE);
675 RedLedLightOnFiveSecond(timeCount);
676 }
677
678 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE) {
679 if (currentMode != GetKeyStatus(CURRENT_MODE)) {
680 return KEY_DOWN_INTERRUPT;
681 }
682 }
683 return 0;
684 }
685
OledHumanRedLedLigthFiveSecondCountShow(unsigned int timeCount)686 static int OledHumanRedLedLigthFiveSecondCountShow(unsigned int timeCount)
687 {
688 static unsigned char currentMode = 0;
689 static unsigned char currentType = 0;
690 static unsigned char sta = 0;
691 int ret = 0;
692
693 OledAutoHumanGreenBeepControl();
694 /* human control mode */
695 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE &&
696 GetKeyStatus(CURRENT_TYPE) == TRAFFIC_HUMAN_TYPE) {
697 currentMode = GetKeyStatus(CURRENT_MODE);
698 currentType = GetKeyStatus(CURRENT_TYPE);
699 RedLedLightOnFiveSecond(timeCount);
700 }
701
702 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_RETURN_MODE) {
703 if (currentMode != GetKeyStatus(CURRENT_MODE)) {
704 return KEY_DOWN_INTERRUPT;
705 }
706 }
707 if (currentType != GetKeyStatus(CURRENT_TYPE)) {
708 currentType = GetKeyStatus(CURRENT_TYPE);
709 return KEY_DOWN_INTERRUPT;
710 }
711 return 0;
712 }
713
OledRedLedLigthOnFiveSecondCountShow(unsigned int timeCount)714 static int OledRedLedLigthOnFiveSecondCountShow(unsigned int timeCount)
715 {
716 int ret = 0;
717
718 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_AUTO_MODE) {
719 ret = OledAutoRedLedLigthFiveSecondCountShow(timeCount);
720 if (ret == KEY_DOWN_INTERRUPT) {
721 return KEY_DOWN_INTERRUPT;
722 }
723 }
724
725 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE) {
726 ret = OledHumanRedLedLigthFiveSecondCountShow(timeCount);
727 if (ret == KEY_DOWN_INTERRUPT) {
728 return KEY_DOWN_INTERRUPT;
729 }
730 }
731
732 return 0;
733 }
734
YellowTimeCount6(void)735 void YellowTimeCount6(void)
736 {
737 GpioControl(IOT_GPIO_INDEX_12, IOT_GPIO_INDEX_12, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE1, IO_FUNC_GPIO_OUT);
738 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
739 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
740 "R:0 Y:3 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
741 } else {
742 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
743 "R:0 Y:3 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
744 }
745 }
YellowTimeCount4(void)746 void YellowTimeCount4(void)
747 {
748 GpioControl(IOT_GPIO_INDEX_12, IOT_GPIO_INDEX_12, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE1, IO_FUNC_GPIO_OUT);
749 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
750 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
751 "R:0 Y:2 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
752 } else {
753 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
754 "R:0 Y:2 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
755 }
756 }
YellowTimeCount2(void)757 void YellowTimeCount2(void)
758 {
759 GpioControl(IOT_GPIO_INDEX_12, IOT_GPIO_INDEX_12, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE1, IO_FUNC_GPIO_OUT);
760 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
761 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
762 "R:0 Y:1 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
763 } else {
764 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
765 "R:0 Y:1 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
766 }
767 }
YellowTimeCount0(void)768 void YellowTimeCount0(void)
769 {
770 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
771 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
772 "R:0 Y:0 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
773 } else {
774 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
775 "R:0 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
776 }
777 }
OledYellowLedLigthReckonByTimeShow(unsigned char timeCount)778 static int OledYellowLedLigthReckonByTimeShow(unsigned char timeCount)
779 {
780 switch (timeCount) {
781 case TIME_COUNT_6:
782 YellowTimeCount6();
783 break;
784 case TIME_COUNT_5:
785 GpioControl(IOT_GPIO_INDEX_12, IOT_GPIO_INDEX_12, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE0, IO_FUNC_GPIO_OUT);
786 break;
787 case TIME_COUNT_4:
788 YellowTimeCount4();
789 break;
790 case TIME_COUNT_3:
791 GpioControl(IOT_GPIO_INDEX_12, IOT_GPIO_INDEX_12, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE0, IO_FUNC_GPIO_OUT);
792 break;
793 case TIME_COUNT_2:
794 YellowTimeCount2();
795 break;
796 case TIME_COUNT_1:
797 GpioControl(IOT_GPIO_INDEX_12, IOT_GPIO_INDEX_12, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE0, IO_FUNC_GPIO_OUT);
798 break;
799 case TIME_COUNT_0:
800 YellowTimeCount0();
801 break;
802 default:
803 break;
804 }
805 }
GreenTimeCount6(void)806 void GreenTimeCount6(void)
807 {
808 GpioControl(IOT_GPIO_INDEX_11, IOT_GPIO_INDEX_11, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE1, IO_FUNC_GPIO_OUT);
809 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
810 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
811 "R:0 Y:0 G:3 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
812 } else {
813 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
814 "R:0 Y:0 G:3 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
815 }
816 }
GreenTimeCount4(void)817 void GreenTimeCount4(void)
818 {
819 GpioControl(IOT_GPIO_INDEX_11, IOT_GPIO_INDEX_11, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE1, IO_FUNC_GPIO_OUT);
820 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
821 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
822 "R:0 Y:0 G:2 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
823 } else {
824 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
825 "R:0 Y:0 G:2 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
826 }
827 }
GreenTimeCount2(void)828 void GreenTimeCount2(void)
829 {
830 GpioControl(IOT_GPIO_INDEX_11, IOT_GPIO_INDEX_11, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE1, IO_FUNC_GPIO_OUT);
831 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
832 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
833 "R:0 Y:0 G:1 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
834 } else {
835 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
836 "R:0 Y:0 G:1 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
837 }
838 }
GreenTimeCount0(void)839 void GreenTimeCount0(void)
840 {
841 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
842 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
843 "R:1 Y:0 G:0 B:1 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
844 } else {
845 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7,
846 "R:1 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
847 }
848 }
OledGreenLedLigthReckonByTimeShow(unsigned int timeCount)849 int OledGreenLedLigthReckonByTimeShow(unsigned int timeCount)
850 {
851 switch (timeCount) {
852 case TIME_COUNT_6:
853 GreenTimeCount6();
854 break;
855 case TIME_COUNT_5:
856 GpioControl(IOT_GPIO_INDEX_11, IOT_GPIO_INDEX_11, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE0, IO_FUNC_GPIO_OUT);
857 break;
858 case TIME_COUNT_4:
859 GreenTimeCount4();
860 break;
861 case TIME_COUNT_3:
862 GpioControl(IOT_GPIO_INDEX_11, IOT_GPIO_INDEX_11, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE0, IO_FUNC_GPIO_OUT);
863 break;
864 case TIME_COUNT_2:
865 GreenTimeCount2();
866 break;
867 case TIME_COUNT_1:
868 GpioControl(IOT_GPIO_INDEX_11, IOT_GPIO_INDEX_11, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE0, IO_FUNC_GPIO_OUT);
869 break;
870 case TIME_COUNT_0:
871 GreenTimeCount0();
872 break;
873 default:
874 break;
875 }
876 }
877
878 #define COUNT_RESET ((hi_u8)0x0)
879
RedLedLightOnFiveSecond(unsigned int timeCount)880 void RedLedLightOnFiveSecond(unsigned int timeCount)
881 {
882 // 红灯亮5秒
883 GpioControl(IOT_GPIO_INDEX_10, IOT_GPIO_INDEX_10, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE1, IO_FUNC_GPIO_OUT);
884 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
885 SetBeepStatus(DELAY_1_S, BEEP_BY_HALF_SECOND, BEEP_ON);
886 } else {
887 SetBeepStatus(DELAY_1_S, BEEP_BY_HALF_SECOND, BEEP_OFF);
888 }
889
890 if (timeCount < AUTO_MODULE_LIGHT_ON_TIME) {
891 OledLedLigthReckonByTimeShow(timeCount);
892 } else {
893 RedOledLedLigthTimeShowNum0();
894 }
895
896 if (timeCount == COUNT_RESET) {
897 GpioControl(IOT_GPIO_INDEX_10, IOT_GPIO_INDEX_10, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE0, IO_FUNC_GPIO_OUT);
898 TrafficLightTimer.Timer2Status = HI_TRUE;
899 }
900 }
901
OledAutoGreenLedLigthFiveSecondCountShow(unsigned int timeCount)902 static int OledAutoGreenLedLigthFiveSecondCountShow(unsigned int timeCount)
903 {
904 static unsigned char currentMode = 0;
905 static unsigned char currentType = 0;
906 static unsigned char sta = 0;
907 int ret = 0;
908
909 OledAutoHumanGreenBeepControl();
910 /* auto mode */
911 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_AUTO_MODE) {
912 currentMode = GetKeyStatus(CURRENT_MODE);
913 currentType = GetKeyStatus(CURRENT_TYPE);
914 GreenLedLightOnFiveSecond(timeCount);
915 }
916
917 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE) {
918 if (currentMode != GetKeyStatus(CURRENT_MODE)) {
919 return KEY_DOWN_INTERRUPT;
920 }
921 }
922 return 0;
923 }
924
OledHumanGreenLedLigthFiveSecondCountShow(unsigned int timeCount)925 static int OledHumanGreenLedLigthFiveSecondCountShow(unsigned int timeCount)
926 {
927 static unsigned char currentMode = 0;
928 static unsigned char currentType = 0;
929 static unsigned char sta = 0;
930 int ret = 0;
931
932 OledAutoHumanGreenBeepControl();
933 /* human control mode */
934 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE) {
935 currentMode = GetKeyStatus(CURRENT_MODE);
936 currentType = GetKeyStatus(CURRENT_TYPE);
937 GreenLedLightOnFiveSecond(timeCount);
938 }
939
940 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_RETURN_MODE) {
941 if (currentMode != GetKeyStatus(CURRENT_MODE)) {
942 return KEY_DOWN_INTERRUPT;
943 }
944 }
945 if (currentType != GetKeyStatus(CURRENT_TYPE)) {
946 currentType = GetKeyStatus(CURRENT_TYPE);
947 return KEY_DOWN_INTERRUPT;
948 }
949 return 0;
950 }
951
OledGreenLedLigthOnFiveSecondCountShow(unsigned int timeCount)952 static int OledGreenLedLigthOnFiveSecondCountShow(unsigned int timeCount)
953 {
954 int ret = 0;
955
956 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_AUTO_MODE) {
957 ret = OledAutoGreenLedLigthFiveSecondCountShow(timeCount);
958 if (ret == KEY_DOWN_INTERRUPT) {
959 return KEY_DOWN_INTERRUPT;
960 }
961 }
962
963 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE) {
964 ret = OledHumanGreenLedLigthFiveSecondCountShow(timeCount);
965 if (ret == KEY_DOWN_INTERRUPT) {
966 return KEY_DOWN_INTERRUPT;
967 }
968 }
969
970 return 0;
971 }
972
GreenLedLightOnFiveSecond(unsigned int timeCount)973 void GreenLedLightOnFiveSecond(unsigned int timeCount)
974 {
975 GpioControl(IOT_GPIO_INDEX_11, IOT_GPIO_INDEX_11, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE1, IO_FUNC_GPIO_OUT);
976 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
977 SetBeepStatus(DELAY_1_S, BEEP_BY_HALF_SECOND, BEEP_ON);
978 } else {
979 SetBeepStatus(DELAY_1_S, BEEP_BY_HALF_SECOND, BEEP_OFF);
980 }
981 if (timeCount < AUTO_MODULE_LIGHT_ON_TIME) {
982 GreenOledLedLigthReckonByTimeShow(timeCount);
983 }
984 if (timeCount == COUNT_RESET) {
985 GpioControl(IOT_GPIO_INDEX_11, IOT_GPIO_INDEX_11, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE0, IO_FUNC_GPIO_OUT);
986 if (TrafficLightTimer.HumanTimerGreenLightStatus) {
987 TrafficLightTimer.Timer9Status = HI_TRUE;
988 } else {
989 TrafficLightTimer.Timer3Status = HI_TRUE;
990 }
991 }
992 }
993
OledRedLedLigthOnRecordShow(int timer2,unsigned int timer1)994 int OledRedLedLigthOnRecordShow(int timer2, unsigned int timer1)
995 {
996 int ret;
997
998 if ((TrafficLightTimer.TimerYellowLightStatus == HI_FALSE) &&
999 (TrafficLightTimer.TimerGreenLightStatus == HI_FALSE) &&
1000 (TrafficLightTimer.Timer1Status == HI_FALSE) &&
1001 (TrafficLightTimer.Timer2Status == HI_FALSE)) {
1002 ret = OledRedLedLigthOnFiveSecondCountShow(timer2);
1003 if (ret == KEY_DOWN_INTERRUPT) {
1004 return KEY_DOWN_INTERRUPT;
1005 }
1006 }
1007 /* 闪烁3s */
1008 if (TrafficLightTimer.Timer2Status == HI_TRUE) {
1009 TrafficLightTimer.Timer1Status = HI_TRUE;
1010 ret = OledRedLedLigthOnFlashRecordShow(timer1);
1011 if (ret == KEY_DOWN_INTERRUPT) {
1012 TrafficLightTimer.Timer2Status = HI_FALSE;
1013 TrafficLightTimer.Timer1Status = HI_FALSE;
1014 return KEY_DOWN_INTERRUPT;
1015 }
1016 if (timer1Count == LAMP_FLASHING_TIME_RESET_0) {
1017 TrafficLightTimer.TimerYellowLightStatus = HI_TRUE;
1018 TrafficLightTimer.Timer2Status = HI_FALSE;
1019 TrafficLightTimer.Timer1Status = HI_FALSE;
1020 }
1021 }
1022 return 0;
1023 }
1024
AutoHumanYellowStatusSet(unsigned int timeCount)1025 void AutoHumanYellowStatusSet(unsigned int timeCount)
1026 {
1027 if ((TrafficLightTimer.TimerYellowLightStatus == HI_TRUE) &&
1028 (TrafficLightTimer.Timer1Status == HI_FALSE)) {
1029 if (timeCount == LAMP_FLASHING_TIME_RESET_0) {
1030 TrafficLightTimer.TimerYellowLightStatus = HI_FALSE;
1031 TrafficLightTimer.TimerGreenLightStatus = HI_TRUE;
1032 }
1033 }
1034 if (TrafficLightTimer.HumanTimerYellowLightStatus == HI_TRUE &&
1035 TrafficLightTimer.Timer6Status == HI_FALSE &&
1036 TrafficLightTimer.Timer7Status == HI_FALSE) {
1037 if (timeCount == LAMP_FLASHING_TIME_RESET_0) {
1038 TrafficLightTimer.HumanTimerYellowLightStatus = HI_FALSE;
1039 TrafficLightTimer.HumanTimerGreenLightStatus = HI_TRUE;
1040 }
1041 }
1042 }
1043
OledAutoHumanGreenBeepControl(void)1044 void OledAutoHumanGreenBeepControl(void)
1045 {
1046 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
1047 SetBeepStatus(DELAY_1_S, BEEP_BY_HALF_SECOND, BEEP_ON);
1048 } else {
1049 SetBeepStatus(DELAY_1_S, BEEP_BY_HALF_SECOND, BEEP_OFF);
1050 }
1051 }
1052
OledAutoYellowLedLigthOnRecordShow(unsigned int timeCount)1053 static int OledAutoYellowLedLigthOnRecordShow(unsigned int timeCount)
1054 {
1055 static unsigned char currentMode = 0;
1056 static unsigned char currentType = 0;
1057 static unsigned char sta = 0;
1058 int ret = 0;
1059
1060 OledAutoHumanGreenBeepControl();
1061 /* auto mode */
1062 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_AUTO_MODE) {
1063 currentMode = GetKeyStatus(CURRENT_MODE);
1064 currentType = GetKeyStatus(CURRENT_TYPE);
1065 OledYellowLedLigthReckonByTimeShow(timeCount);
1066 }
1067 /* status config */
1068 AutoHumanYellowStatusSet(timeCount);
1069 /* Exit current mode */
1070 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE) {
1071 if (currentMode != GetKeyStatus(CURRENT_MODE)) {
1072 return KEY_DOWN_INTERRUPT;
1073 }
1074 }
1075 return 0;
1076 }
1077
OledHumanRedLedLigth30SecondCountShow(unsigned int timeCount)1078 static int OledHumanRedLedLigth30SecondCountShow(unsigned int timeCount)
1079 {
1080 static unsigned char currentMode = 0;
1081 static unsigned char currentType = 0;
1082 static unsigned char sta = 0;
1083 int ret = 0;
1084
1085 OledAutoHumanGreenBeepControl();
1086 /* human control mode */
1087 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE &&
1088 GetKeyStatus(CURRENT_TYPE) == TRAFFIC_NORMAL_TYPE) {
1089 currentMode = GetKeyStatus(CURRENT_MODE);
1090 currentType = GetKeyStatus(CURRENT_TYPE);
1091 NormalTypeRedLedLightOnRecord30Second(timeCount);
1092 }
1093
1094 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_RETURN_MODE) {
1095 if (currentMode != GetKeyStatus(CURRENT_MODE)) {
1096 return KEY_DOWN_INTERRUPT;
1097 }
1098 }
1099 if (currentType != GetKeyStatus(CURRENT_TYPE)) {
1100 currentType = GetKeyStatus(CURRENT_TYPE);
1101 return KEY_DOWN_INTERRUPT;
1102 }
1103 return 0;
1104 }
1105
OledHumanNormalYellowLedLigthOnRecordShow(unsigned int timeCount)1106 static int OledHumanNormalYellowLedLigthOnRecordShow(unsigned int timeCount)
1107 {
1108 static unsigned char currentMode = 0;
1109 static unsigned char currentType = 0;
1110 static unsigned char sta = 0;
1111 int ret = 0;
1112
1113 OledAutoHumanGreenBeepControl();
1114 /* human mode */
1115 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE &&
1116 GetKeyStatus(CURRENT_TYPE) == TRAFFIC_NORMAL_TYPE) {
1117 currentMode = GetKeyStatus(CURRENT_MODE);
1118 currentType = GetKeyStatus(CURRENT_TYPE);
1119 OledYellowLedLigthReckonByTimeShow(timeCount);
1120 }
1121 /* status config */
1122 AutoHumanYellowStatusSet(timeCount);
1123 /* Exit current mode */
1124 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_RETURN_MODE) {
1125 if (currentMode != GetKeyStatus(CURRENT_MODE)) {
1126 return KEY_DOWN_INTERRUPT;
1127 }
1128 }
1129 if ((currentType != GetKeyStatus(CURRENT_TYPE))) {
1130 currentType = GetKeyStatus(CURRENT_TYPE);
1131 return KEY_DOWN_INTERRUPT;
1132 }
1133 return 0;
1134 }
1135
OledHumanYellowLedLigthOnRecordShow(unsigned int timeCount)1136 static int OledHumanYellowLedLigthOnRecordShow(unsigned int timeCount)
1137 {
1138 static unsigned char currentMode = 0;
1139 static unsigned char currentType = 0;
1140 static unsigned char sta = 0;
1141 int ret = 0;
1142
1143 OledAutoHumanGreenBeepControl();
1144 /* human mode */
1145 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE &&
1146 GetKeyStatus(CURRENT_TYPE) == TRAFFIC_HUMAN_TYPE) {
1147 currentMode = GetKeyStatus(CURRENT_MODE);
1148 currentType = GetKeyStatus(CURRENT_TYPE);
1149 OledYellowLedLigthReckonByTimeShow(timeCount);
1150 }
1151 /* status config */
1152 AutoHumanYellowStatusSet(timeCount);
1153 /* Exit current mode */
1154 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_RETURN_MODE) {
1155 if (currentMode != GetKeyStatus(CURRENT_MODE)) {
1156 return KEY_DOWN_INTERRUPT;
1157 }
1158 }
1159 if ((currentType != GetKeyStatus(CURRENT_TYPE))) {
1160 currentType = GetKeyStatus(CURRENT_TYPE);
1161 return KEY_DOWN_INTERRUPT;
1162 }
1163 return 0;
1164 }
1165
OledYellowLedLigthOnRecordShow(unsigned int timeCount)1166 static int OledYellowLedLigthOnRecordShow(unsigned int timeCount)
1167 {
1168 int ret = 0;
1169
1170 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_AUTO_MODE) {
1171 ret = OledAutoYellowLedLigthOnRecordShow(timeCount);
1172 if (ret == KEY_DOWN_INTERRUPT) {
1173 return KEY_DOWN_INTERRUPT;
1174 }
1175 }
1176
1177 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE) {
1178 ret = OledHumanYellowLedLigthOnRecordShow(timeCount);
1179 if (ret == KEY_DOWN_INTERRUPT) {
1180 return KEY_DOWN_INTERRUPT;
1181 }
1182 }
1183
1184 return 0;
1185 }
1186
OledAutoGreenLedLigthReckonByTimeShow(unsigned char timeCount)1187 static int OledAutoGreenLedLigthReckonByTimeShow(unsigned char timeCount)
1188 {
1189 static unsigned char currentMode = 0;
1190 static unsigned char currentType = 0;
1191 static unsigned char sta = 0;
1192 int ret = 0;
1193
1194 OledAutoHumanGreenBeepControl();
1195 /* auto mode */
1196 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_AUTO_MODE) {
1197 currentMode = GetKeyStatus(CURRENT_MODE);
1198 currentType = GetKeyStatus(CURRENT_TYPE);
1199 OledGreenLedLigthReckonByTimeShow(timeCount);
1200 }
1201
1202 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE) {
1203 if (currentMode != GetKeyStatus(CURRENT_MODE)) {
1204 return KEY_DOWN_INTERRUPT;
1205 }
1206 }
1207 return 0;
1208 }
1209
OledHumanNormalGreenLedLigthReckonByTimeShow(unsigned char timeCount)1210 static int OledHumanNormalGreenLedLigthReckonByTimeShow(unsigned char timeCount)
1211 {
1212 static unsigned char currentMode = 0;
1213 static unsigned char currentType = 0;
1214 static unsigned char sta = 0;
1215 int ret = 0;
1216
1217 OledAutoHumanGreenBeepControl();
1218 /* auto mode */
1219 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE &&
1220 GetKeyStatus(CURRENT_TYPE) == TRAFFIC_NORMAL_TYPE) {
1221 currentMode = GetKeyStatus(CURRENT_MODE);
1222 currentType = GetKeyStatus(CURRENT_TYPE);
1223 OledGreenLedLigthReckonByTimeShow(timeCount);
1224 }
1225
1226 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_RETURN_MODE) {
1227 if (currentMode != GetKeyStatus(CURRENT_MODE)) {
1228 return KEY_DOWN_INTERRUPT;
1229 }
1230 }
1231
1232 if (currentType != GetKeyStatus(CURRENT_TYPE)) {
1233 currentType = GetKeyStatus(CURRENT_TYPE);
1234 return KEY_DOWN_INTERRUPT;
1235 }
1236 return 0;
1237 }
1238
OledHumanGreenLedLigthReckonByTimeShow(unsigned char timeCount)1239 static int OledHumanGreenLedLigthReckonByTimeShow(unsigned char timeCount)
1240 {
1241 static unsigned char currentMode = 0;
1242 static unsigned char currentType = 0;
1243 static unsigned char sta = 0;
1244 int ret = 0;
1245
1246 OledAutoHumanGreenBeepControl();
1247 /* auto mode */
1248 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE &&
1249 GetKeyStatus(CURRENT_TYPE) == TRAFFIC_HUMAN_TYPE) {
1250 currentMode = GetKeyStatus(CURRENT_MODE);
1251 currentType = GetKeyStatus(CURRENT_TYPE);
1252 OledGreenLedLigthReckonByTimeShow(timeCount);
1253 }
1254
1255 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_RETURN_MODE) {
1256 if (currentMode != GetKeyStatus(CURRENT_MODE)) {
1257 return KEY_DOWN_INTERRUPT;
1258 }
1259 }
1260
1261 if (currentType != GetKeyStatus(CURRENT_TYPE)) {
1262 currentType = GetKeyStatus(CURRENT_TYPE);
1263 return KEY_DOWN_INTERRUPT;
1264 }
1265 return 0;
1266 }
1267
OledGreenLedLigthOnFlashRecordShow(unsigned int timeCount)1268 static int OledGreenLedLigthOnFlashRecordShow(unsigned int timeCount)
1269 {
1270 int ret = 0;
1271
1272 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_AUTO_MODE) {
1273 ret = OledAutoGreenLedLigthReckonByTimeShow(timeCount);
1274 if (ret == KEY_DOWN_INTERRUPT) {
1275 return KEY_DOWN_INTERRUPT;
1276 }
1277 }
1278
1279 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE) {
1280 ret = OledHumanGreenLedLigthReckonByTimeShow(timeCount);
1281 if (ret == KEY_DOWN_INTERRUPT) {
1282 return KEY_DOWN_INTERRUPT;
1283 }
1284 }
1285
1286 return 0;
1287 }
1288
OledGreenLedLigthOnRecordShow(unsigned char timer4,unsigned char timer5)1289 int OledGreenLedLigthOnRecordShow(unsigned char timer4, unsigned char timer5)
1290 {
1291 unsigned char ret = 0;
1292
1293 if ((TrafficLightTimer.TimerGreenLightStatus == HI_TRUE) &&
1294 (TrafficLightTimer.Timer3Status == HI_FALSE) &&
1295 (TrafficLightTimer.Timer2Status == HI_FALSE) &&
1296 (TrafficLightTimer.Timer1Status == HI_FALSE)) {
1297 ret = OledGreenLedLigthOnFiveSecondCountShow(timer4);
1298 if (ret == KEY_DOWN_INTERRUPT) {
1299 return KEY_DOWN_INTERRUPT;
1300 }
1301 }
1302 /* 绿灯闪烁3s */
1303 if (TrafficLightTimer.Timer3Status == HI_TRUE) {
1304 ret = OledGreenLedLigthOnFlashRecordShow(timer5);
1305 if (ret == KEY_DOWN_INTERRUPT) {
1306 return KEY_DOWN_INTERRUPT;
1307 }
1308 if (timer5Count == LAMP_FLASHING_TIME_RESET_0) {
1309 TrafficLightTimer.TimerGreenLightStatus = HI_FALSE;
1310 TrafficLightTimer.Timer3Status = HI_FALSE;
1311 }
1312 }
1313 return 0;
1314 }
1315
OledHumanModeGreenLedLigthOnRecordShow(unsigned char timer9,unsigned char timer10)1316 int OledHumanModeGreenLedLigthOnRecordShow(unsigned char timer9, unsigned char timer10)
1317 {
1318 int ret = 0;
1319
1320 if ((TrafficLightTimer.HumanTimerGreenLightStatus == HI_TRUE) &&
1321 (TrafficLightTimer.Timer6Status == HI_FALSE) &&
1322 (TrafficLightTimer.Timer7Status == HI_FALSE) &&
1323 (TrafficLightTimer.Timer10Status == HI_FALSE)) {
1324 ret = OledHumanGreenLedLigthFiveSecondCountShow(timer9);
1325 if (ret == KEY_DOWN_INTERRUPT) {
1326 return KEY_DOWN_INTERRUPT;
1327 }
1328 }
1329 if (TrafficLightTimer.Timer9Status == HI_TRUE) {
1330 TrafficLightTimer.Timer10Status = HI_TRUE;
1331 ret = OledHumanNormalGreenLedLigthReckonByTimeShow(timer10);
1332 if (ret == KEY_DOWN_INTERRUPT) {
1333 return KEY_DOWN_INTERRUPT;
1334 }
1335 if (timer10Count == LAMP_FLASHING_TIME_RESET_0) {
1336 SetKeyType(TRAFFIC_NORMAL_TYPE);
1337 TrafficLightTimer.Timer6Status = HI_FALSE;
1338 TrafficLightTimer.Timer7Status = HI_FALSE;
1339 TrafficLightTimer.Timer8Status = HI_FALSE;
1340 TrafficLightTimer.Timer9Status = HI_FALSE;
1341 TrafficLightTimer.Timer10Status = HI_FALSE;
1342 TrafficLightTimer.HumanTimerYellowLightStatus = HI_FALSE;
1343 TrafficLightTimer.HumanTimerGreenLightStatus = HI_FALSE;
1344 TrafficLightTimer.HumanTimerGreenLightStatus = HI_FALSE;
1345 return KEY_DOWN_INTERRUPT;
1346 }
1347 }
1348 return 0;
1349 }
1350
1351 #define CN_QUEUE_WAITTIMEOUT 1000
AutoModeCountReset(void)1352 void AutoModeCountReset(void)
1353 {
1354 timer1Count = SetTimeCount(LED_FLASHING_TIME);
1355 timer2Count = SetTimeCount(AUTO_MODULE_LIGHT_ON_TIME);
1356 timer3Count = SetTimeCount(LED_FLASHING_TIME);
1357 timer4Count = SetTimeCount(AUTO_MODULE_LIGHT_ON_TIME);
1358 timer5Count = SetTimeCount(LED_FLASHING_TIME);
1359 timer6Count = SetTimeCount(AUTO_MODULE_LIGHT_ON_TIME_30_SECOND);
1360 timer7Count = SetTimeCount(LED_FLASHING_TIME);
1361 timer8Count = SetTimeCount(LED_FLASHING_TIME);
1362 timer9Count = SetTimeCount(AUTO_MODULE_LIGHT_ON_TIME);
1363 timer10Count = SetTimeCount(LED_FLASHING_TIME);
1364
1365 humanTimerCount = SetTimeCount(LED_FLASHING_TIME);
1366 humanRedTimerCount = SetTimeCount(AUTO_MODULE_LIGHT_ON_TIME);
1367 yellowHumanCount = SetTimeCount(LED_FLASHING_TIME);
1368 humanGreenTimerCount = SetTimeCount(AUTO_MODULE_LIGHT_ON_TIME);
1369 humanGreenFlashCount = SetTimeCount(LED_FLASHING_TIME);
1370
1371 TrafficLightTimer.Timer1Count = SetTimeCount(LED_FLASHING_TIME);
1372 TrafficLightTimer.Timer2Count = SetTimeCount(AUTO_MODULE_LIGHT_ON_TIME);
1373 TrafficLightTimer.Timer3Count = SetTimeCount(LED_FLASHING_TIME);
1374 TrafficLightTimer.Timer4Count = SetTimeCount(AUTO_MODULE_LIGHT_ON_TIME);
1375 TrafficLightTimer.Timer5Count = SetTimeCount(LED_FLASHING_TIME);
1376 TrafficLightTimer.Timer6Count = SetTimeCount(AUTO_MODULE_LIGHT_ON_TIME_30_SECOND);
1377 TrafficLightTimer.Timer7Count = SetTimeCount(LED_FLASHING_TIME);
1378 TrafficLightTimer.Timer8Count = SetTimeCount(LED_FLASHING_TIME);
1379 TrafficLightTimer.Timer9Count = SetTimeCount(AUTO_MODULE_LIGHT_ON_TIME);
1380 TrafficLightTimer.Timer10Count = SetTimeCount(LED_FLASHING_TIME);
1381
1382 TrafficLightTimer.Timer1Status = 0;
1383 TrafficLightTimer.Timer2Status = 0;
1384 TrafficLightTimer.Timer3Status = 0;
1385 TrafficLightTimer.Timer4Status = 0;
1386 TrafficLightTimer.Timer5Status = 0;
1387 TrafficLightTimer.Timer6Status = 0;
1388 TrafficLightTimer.Timer7Status = 0;
1389 TrafficLightTimer.Timer8Status = 0;
1390 TrafficLightTimer.Timer9Status = 0;
1391 TrafficLightTimer.Timer10Status = 0;
1392 TrafficLightTimer.TimerRedLightStatus = 0;
1393 TrafficLightTimer.TimerYellowLightStatus = 0;
1394 TrafficLightTimer.TimerGreenLightStatus = 0;
1395 TrafficLightTimer.HumanTimerRedLightStatus = 0;
1396 TrafficLightTimer.HumanTimerYellowLightStatus = 0;
1397 TrafficLightTimer.HumanTimerGreenLightStatus = 0;
1398 }
1399
1400 /* traffic auto mode */
TrafficAutoModeSample(void)1401 void TrafficAutoModeSample(void)
1402 {
1403 int ret = 0;
1404
1405 IoTPwmInit(0); /* PWM0 */
1406 IoSetFunc(IOT_GPIO_INDEX_9, IO_FUNC_GPIO_9_PWM0_OUT);
1407 IoTGpioSetDir(IOT_GPIO_INDEX_9, IOT_GPIO_DIR_OUT);
1408 AutoModeCountReset();
1409 while (1) {
1410 ret = OledRedLedLigthOnRecordShow(TrafficLightTimer.Timer2Count,
1411 TrafficLightTimer.Timer1Count);
1412 if (ret == KEY_DOWN_INTERRUPT) {
1413 printf("red led close\r\n");
1414 AllLedOff();
1415 (void)SetKeyType(TRAFFIC_NORMAL_TYPE);
1416 break;
1417 }
1418 ret = OledYellowLedLigthOnRecordShow(TrafficLightTimer.Timer3Count);
1419 if (ret == KEY_DOWN_INTERRUPT) {
1420 printf("yellow led close\r\n");
1421 AllLedOff();
1422 (void)SetKeyType(TRAFFIC_NORMAL_TYPE);
1423 break;
1424 }
1425 ret = OledGreenLedLigthOnRecordShow(TrafficLightTimer.Timer4Count,
1426 TrafficLightTimer.Timer5Count);
1427 if (ret == KEY_DOWN_INTERRUPT) {
1428 printf("green led close\r\n");
1429 AllLedOff();
1430 (void)SetKeyType(TRAFFIC_NORMAL_TYPE);
1431 break;
1432 }
1433 }
1434 }
1435
NormalTypeRedLedLightOnRecord30Second(unsigned char normalTimeCount)1436 void NormalTypeRedLedLightOnRecord30Second(unsigned char normalTimeCount)
1437 {
1438 GpioControl(IOT_GPIO_INDEX_10, IOT_GPIO_INDEX_10, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE1, IO_FUNC_GPIO_OUT);
1439 if (GetKeyStatus(OC_BEEP_STATUS) == BEEP_ON) {
1440 SetBeepStatus(DELAY_1_S, BEEP_BY_HALF_SECOND, BEEP_ON);
1441 } else {
1442 SetBeepStatus(DELAY_1_S, BEEP_BY_HALF_SECOND, BEEP_OFF);
1443 }
1444
1445 if (normalTimeCount < AUTO_MODULE_LIGHT_ON_TIME_30_SECOND) {
1446 OledLedLightHumanReckonShow(normalTimeCount);
1447 } else {
1448 RedOledLedLigthTimeShowNum0();
1449 }
1450
1451 if (normalTimeCount == COUNT_RESET) {
1452 GpioControl(IOT_GPIO_INDEX_10, IOT_GPIO_INDEX_10, IOT_GPIO_DIR_OUT, IOT_GPIO_VALUE0, IO_FUNC_GPIO_OUT);
1453 TrafficLightTimer.Timer6Status = HI_TRUE;
1454 }
1455 }
1456
NormalTypeRedLedLightOnRecord(unsigned char normalTimeCount1,unsigned char normalTimeCount2)1457 int NormalTypeRedLedLightOnRecord(unsigned char normalTimeCount1, unsigned char normalTimeCount2)
1458 {
1459 int ret = 0;
1460 // 红灯亮30秒
1461 if (TrafficLightTimer.Timer6Status == HI_FALSE &&
1462 TrafficLightTimer.Timer7Status == HI_FALSE &&
1463 TrafficLightTimer.HumanTimerYellowLightStatus == HI_FALSE &&
1464 TrafficLightTimer.HumanTimerGreenLightStatus == HI_FALSE &&
1465 TrafficLightTimer.Timer8Status == HI_FALSE &&
1466 TrafficLightTimer.Timer9Status == HI_FALSE) {
1467 ret = OledHumanRedLedLigth30SecondCountShow(normalTimeCount1);
1468 if (ret == KEY_DOWN_INTERRUPT) {
1469 return KEY_DOWN_INTERRUPT;
1470 }
1471 }
1472
1473 // 红灯闪3秒
1474 if (TrafficLightTimer.Timer6Status == HI_TRUE &&
1475 TrafficLightTimer.Timer2Status == HI_FALSE &&
1476 TrafficLightTimer.Timer1Status == HI_FALSE) {
1477 TrafficLightTimer.Timer7Status = HI_TRUE;
1478 ret = OledHumanNormalRedLedLigthReckonByTimeShow(normalTimeCount2);
1479 if (ret == KEY_DOWN_INTERRUPT) {
1480 return KEY_DOWN_INTERRUPT;
1481 }
1482 if (normalTimeCount2 == LAMP_FLASHING_TIME_RESET_0) {
1483 TrafficLightTimer.HumanTimerYellowLightStatus = HI_TRUE;
1484 TrafficLightTimer.Timer6Status = HI_FALSE;
1485 TrafficLightTimer.Timer7Status = HI_FALSE;
1486 }
1487 }
1488 return 0;
1489 }
1490
1491 /* traffic normal type */
TrafficNormalType(void)1492 void TrafficNormalType(void)
1493 {
1494 int ret = 0;
1495
1496 IoTPwmInit(0); /* PWM0 */
1497 IoSetFunc(IOT_GPIO_INDEX_9, IO_FUNC_GPIO_9_PWM0_OUT);
1498 IoTGpioSetDir(IOT_GPIO_INDEX_9, IOT_GPIO_DIR_OUT);
1499 AutoModeCountReset();
1500 while (1) {
1501 ret = NormalTypeRedLedLightOnRecord(TrafficLightTimer.Timer6Count,
1502 TrafficLightTimer.Timer7Count);
1503 if (ret == KEY_DOWN_INTERRUPT) {
1504 printf("normal type red led\r\n");
1505 AllLedOff();
1506 break;
1507 }
1508 ret = OledHumanNormalYellowLedLigthOnRecordShow(TrafficLightTimer.Timer8Count);
1509 if (ret == KEY_DOWN_INTERRUPT) {
1510 printf("normal type yellow led\r\n");
1511 AllLedOff();
1512
1513 break;
1514 }
1515 ret = OledHumanModeGreenLedLigthOnRecordShow(TrafficLightTimer.Timer9Count,
1516 TrafficLightTimer.Timer10Count);
1517 if (ret == KEY_DOWN_INTERRUPT) {
1518 printf("normal type green led\r\n");
1519 AllLedOff();
1520 break;
1521 }
1522 }
1523 }
1524
1525 /*
1526 @bref traffic human type
1527 @param void
1528 */
TrafficHumanType(void)1529 void TrafficHumanType(void)
1530 {
1531 TrafficAutoModeSample();
1532 }
1533
1534 /* traffic human mode */
TrafficHumanModeSample(void)1535 void TrafficHumanModeSample(void)
1536 {
1537 IoTPwmInit(0); /* PWM0 */
1538 IoSetFunc(IOT_GPIO_INDEX_9, IO_FUNC_GPIO_9_PWM0_OUT);
1539 IoTGpioSetDir(IOT_GPIO_INDEX_9, IOT_GPIO_DIR_OUT);
1540
1541 switch (GetKeyStatus(CURRENT_TYPE)) {
1542 case TRAFFIC_NORMAL_TYPE:
1543 TrafficNormalType();
1544 break;
1545 case TRAFFIC_HUMAN_TYPE:
1546 TrafficHumanType();
1547 break;
1548 default:
1549 break;
1550 }
1551 }
1552
OledTrafficControlModeShow(void)1553 void OledTrafficControlModeShow(void)
1554 {
1555 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_0, \
1556 "WiFi-AP OFF U:0", OLED_DISPLAY_STRING_TYPE_1); /* 0, 0, xx, 1 */
1557 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_1, \
1558 " ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 1, xx, 1 */
1559 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_2, \
1560 " Traffic Light ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 2, xx, 1 */
1561 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_3, \
1562 " ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 3, xx, 1 */
1563 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_4, \
1564 "Mode: ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 4, xx, 1 */
1565 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_5, \
1566 "1.Control mode: ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 5, xx, 1 */
1567 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_6, \
1568 " ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 6, xx, 1 */
1569 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7, \
1570 " ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
1571 switch (GetKeyStatus(CURRENT_TYPE)) {
1572 case RED_ON:
1573 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7, "1.Red On ",
1574 OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
1575 break;
1576 case YELLOW_ON:
1577 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7, "2.Yellow On ",
1578 OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
1579 break;
1580 case GREEN_ON:
1581 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7, "3.Green On ",
1582 OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
1583 break;
1584 default:
1585 break;
1586 }
1587 TrafficControlModeSample();
1588 }
1589
OledTrafficAutoModeShow(void)1590 void OledTrafficAutoModeShow(void)
1591 {
1592 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_4, \
1593 "Mode: ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 4, xx, 1 */
1594 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_5, \
1595 "2.Auto mode: ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 5, xx, 1 */
1596 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_6, \
1597 " ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 6, xx, 1 */
1598 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7, \
1599 "R:0 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
1600 AllLedOff();
1601 TrafficAutoModeSample();
1602 }
1603
OledTrafficHumanModeShow(void)1604 void OledTrafficHumanModeShow(void)
1605 {
1606 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_4, \
1607 "Mode: ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 4, xx, 1 */
1608 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_5, \
1609 "3.Human mode: ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 5, xx, 1 */
1610 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_6, \
1611 " ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 6, xx, 1 */
1612 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7, \
1613 "R:0 Y:0 G:0 B:0 ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
1614 AllLedOff();
1615 TrafficHumanModeSample();
1616 }
1617
OledTrafficReturnModeShow(void)1618 void OledTrafficReturnModeShow(void)
1619 {
1620 static int status = 0;
1621 static unsigned char currentMode = 0;
1622
1623 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_4, \
1624 "Return Menu ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 4, xx, 1 */
1625 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_5, \
1626 " ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 5, xx, 1 */
1627 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_6, \
1628 " ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 6, xx, 1 */
1629 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7, \
1630 "Continue ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
1631 AllLedOff();
1632 IoTPwmStart(HI_PWM0, PWM_LOW_DUTY, PWM_FULL_DUTY); // 关闭beep
1633 if (!status) {
1634 status = HI_TRUE;
1635 currentMode = GetKeyStatus(CURRENT_MODE);
1636 }
1637 if (currentMode != GetKeyStatus(CURRENT_MODE)) {
1638 return;
1639 }
1640 }
1641
TrafficDisplayInit(void)1642 void TrafficDisplayInit(void)
1643 {
1644 // clean screen
1645 OledFillScreen(OLED_CLEAN_SCREEN);
1646 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_0, \
1647 "WiFi-AP ON U:1", OLED_DISPLAY_STRING_TYPE_1); /* 0, 0, xx, 1 */
1648 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_1, \
1649 " ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 1, xx, 1 */
1650 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_2, \
1651 " Traffic Light ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 2, xx, 1 */
1652 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_3, \
1653 " ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 3, xx, 1 */
1654 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_4, \
1655 "Mode: ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 4, xx, 1 */
1656 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_5, \
1657 "1.Control mode: ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 5, xx, 1 */
1658 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_6, \
1659 " ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 6, xx, 1 */
1660 OledShowStr(OLED_X_POSITION_0, OLED_Y_POSITION_7, \
1661 " ", OLED_DISPLAY_STRING_TYPE_1); /* 0, 7, xx, 1 */
1662 }
1663
TrafficDisplay(void)1664 void TrafficDisplay(void)
1665 {
1666 unsigned char currentType = 0;
1667 while (HI_ERR_SUCCESS != OledInit()) {
1668 }
1669 /* 按键中断初始化 */
1670 TestGpioInit();
1671 // clean screen
1672 TrafficDisplayInit();
1673 currentType = SetKeyType(KEY_UP);
1674 while (1) {
1675 switch (GetKeyStatus(CURRENT_MODE)) {
1676 case TRAFFIC_CONTROL_MODE:
1677 OledTrafficControlModeShow();
1678 break;
1679 case TRAFFIC_AUTO_MODE:
1680 OledTrafficAutoModeShow();
1681 break;
1682 case TRAFFIC_HUMAN_MODE:
1683 OledTrafficHumanModeShow();
1684 break;
1685 case TRAFFIC_RETURN_MODE:
1686 OledTrafficReturnModeShow();
1687 break;
1688 default:
1689 break;
1690 }
1691 }
1692 }
1693 /* timer */
Timer1Callback(unsigned int arg)1694 void Timer1Callback(unsigned int arg)
1695 {
1696 if (timer1Count == LAMP_FLASHING_TIME_RESET_0) {
1697 timer1Count = LED_FLASHING_TIME;
1698 TrafficLightTimer.Timer1Count = LED_FLASHING_TIME;
1699 return;
1700 }
1701 if (timer7Count == LAMP_FLASHING_TIME_RESET_0) {
1702 timer7Count = LED_FLASHING_TIME;
1703 TrafficLightTimer.Timer7Count = LED_FLASHING_TIME;
1704 return;
1705 }
1706 if (humanTimerCount == LAMP_FLASHING_TIME_RESET_0) {
1707 humanTimerCount = LED_FLASHING_TIME;
1708 TrafficLightTimer.Timer1Count = LED_FLASHING_TIME;
1709 return;
1710 }
1711 if ((TrafficLightTimer.Timer2Status == HI_TRUE) &&
1712 (TrafficLightTimer.Timer1Status == HI_TRUE)) {
1713 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_AUTO_MODE) {
1714 timer1Count--;
1715 TrafficLightTimer.Timer1Count = timer1Count;
1716 printf("Timer1Count = %d\r\n", TrafficLightTimer.Timer1Count);
1717 }
1718 }
1719 if (TrafficLightTimer.Timer6Status == HI_TRUE &&
1720 TrafficLightTimer.Timer7Status == HI_TRUE) {
1721 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE &&
1722 GetKeyStatus(CURRENT_TYPE) == TRAFFIC_NORMAL_TYPE) {
1723 timer7Count--;
1724 TrafficLightTimer.Timer7Count = timer7Count;
1725 if (TrafficLightTimer.Timer7Count == DATA_OUT_OF_BOUND) {
1726 TrafficLightTimer.Timer7Count = LAMP_FLASHING_TIME_RESET_0;
1727 }
1728 printf("Timer7Count = %d\r\n", TrafficLightTimer.Timer7Count);
1729 }
1730 }
1731 /* 人工干预模式 */
1732 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE &&
1733 GetKeyStatus(CURRENT_TYPE) == TRAFFIC_HUMAN_TYPE &&
1734 TrafficLightTimer.Timer2Status == HI_TRUE &&
1735 TrafficLightTimer.Timer1Status == HI_TRUE) {
1736 humanTimerCount--;
1737 TrafficLightTimer.Timer1Count = humanTimerCount;
1738 printf("humanTimerCount = %d\r\n", TrafficLightTimer.Timer1Count);
1739 }
1740 }
1741
HumanTimer2Cb(void)1742 void HumanTimer2Cb(void)
1743 {
1744 if (TrafficLightTimer.Timer6Status == HI_FALSE &&
1745 TrafficLightTimer.Timer7Status == HI_FALSE &&
1746 TrafficLightTimer.HumanTimerYellowLightStatus == HI_FALSE &&
1747 TrafficLightTimer.HumanTimerGreenLightStatus == HI_FALSE &&
1748 TrafficLightTimer.Timer8Status == HI_FALSE &&
1749 TrafficLightTimer.Timer9Status == HI_FALSE) {
1750 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE &&
1751 GetKeyStatus(CURRENT_TYPE) == TRAFFIC_NORMAL_TYPE) {
1752 timer6Count--;
1753 TrafficLightTimer.Timer6Count = timer6Count;
1754 if (TrafficLightTimer.Timer6Count == DATA_OUT_OF_BOUND) {
1755 TrafficLightTimer.Timer6Count = LAMP_FLASHING_TIME_RESET_0;
1756 }
1757 }
1758 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE &&
1759 GetKeyStatus(CURRENT_TYPE) == TRAFFIC_HUMAN_TYPE &&
1760 TrafficLightTimer.Timer2Status == HI_FALSE &&
1761 TrafficLightTimer.Timer1Status == HI_FALSE &&
1762 (TrafficLightTimer.TimerYellowLightStatus == HI_FALSE) &&
1763 (TrafficLightTimer.TimerGreenLightStatus == HI_FALSE)) {
1764 humanRedTimerCount--;
1765 TrafficLightTimer.Timer2Count = humanRedTimerCount;
1766 if (TrafficLightTimer.Timer2Count == DATA_OUT_OF_BOUND) {
1767 TrafficLightTimer.Timer2Count = LAMP_FLASHING_TIME_RESET_0;
1768 }
1769 }
1770 }
1771 }
1772
Timer2Callback(int arg)1773 void Timer2Callback(int arg)
1774 {
1775 if (timer2Count == LAMP_FLASHING_TIME_RESET_0) {
1776 TrafficLightTimer.Timer2Count = AUTO_MODULE_LIGHT_ON_TIME;
1777 timer2Count = AUTO_MODULE_LIGHT_ON_TIME;
1778 return;
1779 }
1780 if (timer6Count == LAMP_FLASHING_TIME_RESET_0) {
1781 TrafficLightTimer.Timer6Count = AUTO_MODULE_LIGHT_ON_TIME_30_SECOND;
1782 timer6Count = AUTO_MODULE_LIGHT_ON_TIME_30_SECOND;
1783 return;
1784 }
1785 if ((TrafficLightTimer.Timer2Status == HI_FALSE) &&
1786 (TrafficLightTimer.Timer1Status == HI_FALSE) &&
1787 (TrafficLightTimer.TimerYellowLightStatus == HI_FALSE) &&
1788 (TrafficLightTimer.TimerGreenLightStatus == HI_FALSE)) {
1789 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_AUTO_MODE) {
1790 timer2Count--;
1791 TrafficLightTimer.Timer2Count = timer2Count;
1792 if (TrafficLightTimer.Timer2Count == DATA_OUT_OF_BOUND) {
1793 TrafficLightTimer.Timer2Count = LAMP_FLASHING_TIME_RESET_0;
1794 }
1795 }
1796 }
1797 HumanTimer2Cb();
1798 }
1799
Timer3Callback(unsigned int arg)1800 void Timer3Callback(unsigned int arg)
1801 {
1802 if (timer3Count == LAMP_FLASHING_TIME_RESET_0) {
1803 timer3Count = LED_FLASHING_TIME;
1804 TrafficLightTimer.Timer3Count = LED_FLASHING_TIME;
1805 return;
1806 }
1807 if (timer8Count == LAMP_FLASHING_TIME_RESET_0) {
1808 timer8Count = LED_FLASHING_TIME;
1809 TrafficLightTimer.Timer8Count = LED_FLASHING_TIME;
1810 return;
1811 }
1812 if (yellowHumanCount == LAMP_FLASHING_TIME_RESET_0) {
1813 yellowHumanCount = LED_FLASHING_TIME;
1814 TrafficLightTimer.Timer3Count = LED_FLASHING_TIME;
1815 return;
1816 }
1817 if ((TrafficLightTimer.TimerYellowLightStatus == HI_TRUE) &&
1818 (TrafficLightTimer.TimerGreenLightStatus == HI_FALSE) &&
1819 (TrafficLightTimer.Timer1Status == HI_FALSE) &&
1820 (TrafficLightTimer.Timer2Status == HI_FALSE)) {
1821 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_AUTO_MODE) {
1822 timer3Count--;
1823 TrafficLightTimer.Timer3Count = timer3Count;
1824 printf("Timer3Count = %d\r\n", TrafficLightTimer.Timer3Count);
1825 }
1826 }
1827 if (TrafficLightTimer.HumanTimerYellowLightStatus == HI_TRUE &&
1828 TrafficLightTimer.HumanTimerGreenLightStatus == HI_FALSE &&
1829 TrafficLightTimer.Timer6Status == HI_FALSE &&
1830 TrafficLightTimer.Timer7Status == HI_FALSE) {
1831 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE) {
1832 timer8Count--;
1833 TrafficLightTimer.Timer8Count = timer8Count;
1834 printf("Timer8Count = %d\r\n", TrafficLightTimer.Timer8Count);
1835 }
1836 }
1837 /* 人工干预模式 */
1838 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE &&
1839 GetKeyStatus(CURRENT_TYPE) == TRAFFIC_HUMAN_TYPE &&
1840 TrafficLightTimer.TimerYellowLightStatus == HI_TRUE &&
1841 TrafficLightTimer.TimerGreenLightStatus == HI_FALSE &&
1842 TrafficLightTimer.Timer1Status == HI_FALSE &&
1843 TrafficLightTimer.Timer2Status == HI_FALSE) {
1844 yellowHumanCount--;
1845 TrafficLightTimer.Timer3Count = yellowHumanCount;
1846 printf("yellowHumanCount = %d\r\n", TrafficLightTimer.Timer3Count);
1847 }
1848 }
1849
Timer4Callback(unsigned int arg)1850 void Timer4Callback(unsigned int arg)
1851 {
1852 if (timer4Count == LAMP_FLASHING_TIME_RESET_0) {
1853 timer4Count = AUTO_MODULE_LIGHT_ON_TIME;
1854 TrafficLightTimer.Timer4Count = AUTO_MODULE_LIGHT_ON_TIME;
1855 return;
1856 }
1857 if (timer9Count == LAMP_FLASHING_TIME_RESET_0) {
1858 timer9Count = AUTO_MODULE_LIGHT_ON_TIME;
1859 TrafficLightTimer.Timer9Count = AUTO_MODULE_LIGHT_ON_TIME;
1860 return;
1861 }
1862 if (humanGreenTimerCount == LAMP_FLASHING_TIME_RESET_0) {
1863 humanGreenTimerCount = AUTO_MODULE_LIGHT_ON_TIME;
1864 TrafficLightTimer.Timer9Count = AUTO_MODULE_LIGHT_ON_TIME;
1865 return;
1866 }
1867 if ((TrafficLightTimer.TimerGreenLightStatus == HI_TRUE) &&
1868 (TrafficLightTimer.TimerYellowLightStatus == HI_FALSE) &&
1869 (TrafficLightTimer.Timer3Status == HI_FALSE) &&
1870 (TrafficLightTimer.Timer1Status == HI_FALSE) &&
1871 (TrafficLightTimer.Timer2Status == HI_FALSE)) {
1872 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_AUTO_MODE) {
1873 timer4Count--;
1874 TrafficLightTimer.Timer4Count = timer4Count;
1875 printf("Timer4Count = %d\r\n", TrafficLightTimer.Timer4Count);
1876 }
1877 }
1878 if (TrafficLightTimer.HumanTimerGreenLightStatus == HI_TRUE &&
1879 TrafficLightTimer.HumanTimerYellowLightStatus == HI_FALSE &&
1880 TrafficLightTimer.Timer10Status == HI_FALSE) {
1881 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE) {
1882 timer9Count--;
1883 TrafficLightTimer.Timer9Count = timer9Count;
1884 printf("Timer9Count = %d\r\n", TrafficLightTimer.Timer9Count);
1885 }
1886 }
1887 /* 人工干预模式 */
1888 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE &&
1889 GetKeyStatus(CURRENT_TYPE) == TRAFFIC_HUMAN_TYPE &&
1890 (TrafficLightTimer.TimerGreenLightStatus == HI_TRUE) &&
1891 (TrafficLightTimer.TimerYellowLightStatus == HI_FALSE) &&
1892 (TrafficLightTimer.Timer3Status == HI_FALSE) &&
1893 (TrafficLightTimer.Timer1Status == HI_FALSE) &&
1894 (TrafficLightTimer.Timer2Status == HI_FALSE)) {
1895 humanGreenTimerCount--;
1896 TrafficLightTimer.Timer4Count = humanGreenTimerCount;
1897 printf("humanGreenTimerCount = %d\r\n", TrafficLightTimer.Timer4Count);
1898 }
1899 }
1900
Timer5Callback(unsigned int arg)1901 void Timer5Callback(unsigned int arg)
1902 {
1903 if (timer5Count == LAMP_FLASHING_TIME_RESET_0) {
1904 timer5Count = LED_FLASHING_TIME;
1905 TrafficLightTimer.Timer5Count = LED_FLASHING_TIME;
1906 return;
1907 }
1908 if (timer10Count == LAMP_FLASHING_TIME_RESET_0) {
1909 timer10Count = LED_FLASHING_TIME;
1910 TrafficLightTimer.Timer10Count = LED_FLASHING_TIME;
1911 return;
1912 }
1913 if (humanGreenFlashCount == LAMP_FLASHING_TIME_RESET_0) {
1914 humanGreenFlashCount = LED_FLASHING_TIME;
1915 TrafficLightTimer.Timer5Count = LED_FLASHING_TIME;
1916 return;
1917 }
1918 if ((TrafficLightTimer.TimerGreenLightStatus == HI_TRUE) &&
1919 (TrafficLightTimer.TimerYellowLightStatus == HI_FALSE) &&
1920 (TrafficLightTimer.Timer3Status == HI_TRUE) &&
1921 (TrafficLightTimer.Timer1Status == HI_FALSE) &&
1922 (TrafficLightTimer.Timer2Status == HI_FALSE)) {
1923 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_AUTO_MODE) {
1924 timer5Count--;
1925 TrafficLightTimer.Timer5Count = timer5Count;
1926 printf("Timer5Count = %d\r\n", TrafficLightTimer.Timer5Count);
1927 }
1928 }
1929 /* human mode */
1930 if (TrafficLightTimer.Timer10Status == HI_TRUE) {
1931 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE) {
1932 timer10Count--;
1933 TrafficLightTimer.Timer10Count = timer10Count;
1934 printf("Timer10Count = %d\r\n", TrafficLightTimer.Timer10Count);
1935 }
1936 }
1937 /* 人工干预模式 */
1938 if (GetKeyStatus(CURRENT_MODE) == TRAFFIC_HUMAN_MODE &&
1939 GetKeyStatus(CURRENT_TYPE) == TRAFFIC_HUMAN_TYPE &&
1940 (TrafficLightTimer.TimerGreenLightStatus == HI_TRUE) &&
1941 (TrafficLightTimer.TimerYellowLightStatus == HI_FALSE) &&
1942 (TrafficLightTimer.Timer3Status == HI_TRUE) &&
1943 (TrafficLightTimer.Timer1Status == HI_FALSE) &&
1944 (TrafficLightTimer.Timer2Status == HI_FALSE)) {
1945 humanGreenFlashCount--;
1946 TrafficLightTimer.Timer5Count = humanGreenFlashCount;
1947 printf("humanGreenFlashCount = %d\r\n", TrafficLightTimer.Timer5Count);
1948 }
1949 }
1950
1951 #define CN_QUEUE_MSGNUM 16
1952 #define CN_QUEUE_MSGSIZE (sizeof(hi_pvoid))
1953
SoftwareTimersTaskEntry(void)1954 void SoftwareTimersTaskEntry(void)
1955 {
1956 unsigned int timerId1;
1957 unsigned int timerId2;
1958 unsigned int timerId3;
1959 unsigned int timerId4;
1960 unsigned int timerId5;
1961 unsigned int ret;
1962
1963 /* 创建周期性软件定时器,时间为1000ms,启动到1000ms数时执行回调函数1 */
1964 ret = hi_timer_create(&timerId1);
1965 if (ret != HI_ERR_SUCCESS) {
1966 printf("Failed to create timer 1\r\n");
1967 }
1968 /* 创建周期性软件定时器,每1000ms数执行回调函数2 */
1969 ret = hi_timer_create(&timerId2);
1970 if (ret != HI_ERR_SUCCESS) {
1971 printf("Failed to create timer 2\r\n");
1972 }
1973 /* 创建周期性软件定时器,每1000ms数执行回调函数3 */
1974 ret = hi_timer_create(&timerId3);
1975 if (ret != HI_ERR_SUCCESS) {
1976 printf("Failed to create timer 3\r\n");
1977 }
1978 /* 创建周期性软件定时器,每1000ms数执行回调函数4 */
1979 ret = hi_timer_create(&timerId4);
1980 if (ret != HI_ERR_SUCCESS) {
1981 printf("Failed to create timer 4\r\n");
1982 }
1983 /* 创建周期性软件定时器,每1000ms数执行回调函数5 */
1984 ret = hi_timer_create(&timerId5);
1985 if (ret != HI_ERR_SUCCESS) {
1986 printf("Failed to create timer 5\r\n");
1987 }
1988
1989 ret = hi_timer_start(timerId1, HI_TIMER_TYPE_PERIOD, 1000, Timer1Callback, 0); /* 1000: timer 1000ms */
1990 if (ret != HI_ERR_SUCCESS) {
1991 printf("Failed to start timer 1\r\n");
1992 }
1993
1994 ret = hi_timer_start(timerId2, HI_TIMER_TYPE_PERIOD, 1000, Timer2Callback, 0); /* 1000: timer 1000ms */
1995 if (ret != HI_ERR_SUCCESS) {
1996 printf("Failed to start timer 2\r\n");
1997 }
1998
1999 ret = hi_timer_start(timerId3, HI_TIMER_TYPE_PERIOD, 1000, Timer3Callback, 0); /* 1000: timer 1000ms */
2000 if (ret != HI_ERR_SUCCESS) {
2001 printf("Failed to start timer 2\r\n");
2002 }
2003
2004 ret = hi_timer_start(timerId4, HI_TIMER_TYPE_PERIOD, 1000, Timer4Callback, 0); /* 1000: timer 1000ms */
2005 if (ret != HI_ERR_SUCCESS) {
2006 printf("Failed to start timer 2\r\n");
2007 }
2008
2009 ret = hi_timer_start(timerId5, HI_TIMER_TYPE_PERIOD, 1000, Timer5Callback, 0); /* 1000: timer 1000ms */
2010 if (ret != HI_ERR_SUCCESS) {
2011 printf("Failed to start timer 2\r\n");
2012 }
2013 }
2014
2015 #define TIMER_TASK_STACK (1024 * 4)
2016
TimerTask(void)2017 static void TimerTask(void)
2018 {
2019 osThreadAttr_t attr;
2020 IoTWatchDogDisable();
2021
2022 attr.name = "TrafficLightDemo";
2023 attr.attr_bits = 0U;
2024 attr.cb_mem = NULL;
2025 attr.cb_size = 0U;
2026 attr.stack_mem = NULL;
2027 attr.stack_size = TIMER_TASK_STACK;
2028 attr.priority = osPriorityNormal;
2029
2030 if (osThreadNew((osThreadFunc_t)SoftwareTimersTaskEntry, NULL, &attr) == NULL) {
2031 printf("[TrafficLight] Failed to create SoftwareTimersTaskEntry!\n");
2032 }
2033 }
2034
2035 SYS_RUN(TimerTask);
2036