-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLedNode.cpp
77 lines (60 loc) · 1.32 KB
/
LedNode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* LedNode.cpp
*
* Created on: Nov 26, 2012
* Author: joost
*/
#include "LedNode.h"
#include <Arduino.h>
LedNode::LedNode() {
brightness = 0;
colour = Main::baseColour;
}
LedNode::~LedNode() {
}
void LedNode::ping() {
list<Bullet*> occupants = getOccupants();
//Serial.println(":Ping");
if (occupants.size() == maxOccupants && maxOccupants != 0) {
full = true;
} else {
full = false;
}
if (Main::activated) {
colour.approach(Main::activatedColour);
} else if (occupants.size() > 0) {
Colour c = Colour(occupants.front()->getColour());
for (list<Bullet*>::iterator it = occupants.begin(); it != occupants.end(); it++) {
c.average((*it)->getColour());
}
colour.quickApproach(c);
} else if (Main::leftActivated > 0 && Main::rightActivated > 0) {
colour.approach(Main::pathColour);
} else {
colour.approach(Main::baseColour);
}
}
bool LedNode::isFull() {
return full;
}
uint8_t LedNode::getBrightness() {
return brightness;
}
Colour LedNode::getColour() {
return colour;
}
void LedNode::setColour(Colour c) {
colour = c;
}
void LedNode::addOccupant(Bullet *b) {
b->setNode(this);
}
list<Bullet*> LedNode::getOccupants() {
list<Bullet*> bs;
for (int i = 0; i < Main::bullets.size(); i++) {
if (Main::bullets[i]->getNode() == this) {
bs.push_back(Main::bullets[i]);
}
}
return bs;
}