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