-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwitchList.cpp
50 lines (43 loc) · 878 Bytes
/
SwitchList.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
#include "SwitchList.h"
// Append new switch element (new HEAD)
Switch& SwitchList::add(const char* name, bool isLight) {
Switch *n = new Switch(name, isLight);
if (m_head) {
// list not empty
Switch *s = m_head;
while (s->next()) {
s = s->next();
}
// reached last element
s->setNext(n);
return *n;
}
else {
// list empty - 1st element
m_head = n;
return *n;
}
}
Switch* SwitchList::find(uint8_t id) {
Switch *s = m_head;
while (s) {
if (s->getId() == id) {
return s;
}
s = s->next();
}
return NULL;
}
uint8_t SwitchList::poll() {
uint8_t updatedSwitches = 0;
Switch* s = m_head;
while (s) {
Button* buttonUpdated = s->getBls()->poll();
if (buttonUpdated) {
s->callback(buttonUpdated);
updatedSwitches++;
}
s = s->next();
}
return updatedSwitches;
}