-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequencer.h
65 lines (52 loc) · 1.56 KB
/
sequencer.h
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
#ifndef SEQUENCER_H
#define SEQUENCER_H
struct SequenceEvent {
unsigned long timeout;
void (*callback)(void); // Function pointer for functions of the type void foo(void)
};
class Sequence {
public:
Sequence(SequenceEvent* eventsList, int eventsLength);
/** Kicks off the sequence. */
void start();
void start(unsigned long time);
/** Returns true if the sequence is running. */
bool running();
/**
* Called on every iteration of the loop(). Use Sequence helper instead
* if several sequences are active at the same time. Uses micros() to determine
* current time.
*/
void tick();
/**
* Called on every iteration of the loop(). Accepts a timestamp in
* microseconds.
* Useful for testing, or when you want to pass the same timestamp to all
* sequences for each iteration of the loop().
*/
void tick(unsigned long time);
private:
SequenceEvent *events;
int eventCount;
int nextEvent;
bool started;
unsigned long lastEventTime; /* us */
};
class SequenceHelper {
public:
/**
* Initializes a SequenceHelper for a max of the given number of Sequences.
* Params:
* s: Array of pointers to Sequence.
* c: Number of squences in the array.
*/
SequenceHelper(Sequence **s, int c);
/** Returns true if all sequences are done. */
bool done();
/** This function should be called on every iteration of the loop(). */
void tick();
private:
Sequence **sequences; // Array of pointers to Sequence.
int count;
};
#endif