-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSequence.cpp
More file actions
77 lines (63 loc) · 1.38 KB
/
Sequence.cpp
File metadata and controls
77 lines (63 loc) · 1.38 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "Sequence.h"
#include "LED_Controller.h"
#include <Arduino.h>
#include "DEBUG.h"
namespace LEDAnimation {
Sequence::Sequence(Step* first) : first(first), iterator(first), timeOfRun(0) {
first->setNext(first);
}
Sequence::~Sequence() {}
void Sequence::toStart() {
iterator = first;
}
void Sequence::next() {
iterator = iterator->getNext();
}
void Sequence::runStep() {
iterator->doActions();
timeOfRun = millis();
}
Sequence& Sequence::operator<<(Step* step) {
if (iterator->getNext() != first) {
for (; iterator->getNext() != nullptr && iterator->getNext() != first; next());
}
iterator->setNext(step);
step->setNext(first);
return *this;
}
bool Sequence::checkWait() {
return (millis() - timeOfRun) >= iterator->getWait();
}
void Sequence::runfor(unsigned long runTime) {
unsigned long startTime = millis();
start();
do {
if (checkWait()) {
doNext();
}
} while (millis() - startTime <= runTime);
}
void Sequence::runforCycles(uint8_t cycles) {
uint8_t cycle = 1;
start();
do {
if (checkWait()) {
if (iterator->getNext() == first) {
if (++cycle > cycles)
break;
}
doNext();
}
} while (true);
}
void Sequence::start() {
DEBUG_PRINT("New seq starting\n")
LED_Controller::getInstance()->setAll(LEDstate::off);
toStart();
runStep();
}
void Sequence::doNext() {
next();
runStep();
}
}