-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAlertSystem.cpp
More file actions
59 lines (53 loc) · 1.58 KB
/
Copy pathAlertSystem.cpp
File metadata and controls
59 lines (53 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "AlertSystem.h"
#include "Util.h"
AlertSystem::AlertSystem() {
_graph.build();
_i2_light = _graph.getI2Light();
}
void AlertSystem::alertTrafficLights(LinkedList<DetectionResult*>* detectionResult) {
for (int i = 0; i < detectionResult->size(); i++) {
DetectionResult* result = detectionResult->get(i);
LinkedList<Intersection*> *retList = _graph.dfsTraverse(result->intersectionId, result->exitStreetId);
for (int j = 0; j < retList->size(); j++) {
Intersection *intersection = retList->get(j);
if (intersection->hasTrafficLight()) {
RgbLED *light = intersection->getLight();
light->setStartBlinkingTime(millis());
boolean existing = false;
for (int k = 0; k < _alertedLights.size(); k++) {
if (_alertedLights.get(k) == light) {
existing = true;
break;
}
}
if (!existing) {
_alertedLights.add(light);
}
}
}
delete retList;
}
}
void AlertSystem::blinkAlertedLights() {
for (int i = 0; i < _alertedLights.size(); i++) {
RgbLED *light = _alertedLights.get(i);
light->blinkLED();
}
}
void AlertSystem::resetAlertedLights() {
unsigned long curTime = millis();
int i = 0;
while (i < _alertedLights.size()) {
RgbLED *light = _alertedLights.get(i);
if (curTime - light->getStartBlinkingTime() >= Util::BLINK_DURATION) {
light->turnOffBlink();
_alertedLights.remove(i);
} else {
i++;
}
}
}
void AlertSystem::turnI2Red() {
Util::debugMsg("Turn i2 light to red...");
_i2_light->turnOnRed();
}