-
Notifications
You must be signed in to change notification settings - Fork 0
/
Routine.cpp
102 lines (77 loc) · 2.23 KB
/
Routine.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "Routine.h"
#include "Matrix.h"
#include "GFX.h"
void (*Routine::DisplayUpdate)() = Display::UpdateFromMatrix;
void (*Routine::UpdateMatrix)() = Matrix::GameOfLife;
void (*Routine::Led)() = LED::Toggle;
void (*Routine::Buttons)() = Buttons::Read;
uint16_t Routine::sleep;
uint16_t Routine::pause;
void Routine::Initialize() {
// random seed
randomSeed(analogRead(0));
Routine::sleep = 0;
Routine::pause = 0;
}
void Routine::Nop() {
}
void Routine::Sleep() {
if (Routine::sleep > 0) {
delay(Routine::sleep);
}
}
void Routine::Reset() {
Matrix::InitializeProbability(random(32, 128));
GFX::RandomSwipe();
delay(300);
}
void Routine::Pause() {
String str, count_live_str, count_dead_str, percent_str;
uint16_t count_live, count_dead, percent;
uint16_t len_padding;
if (Routine::pause == 0) {
Routine::pause = 1;
Routine::DisplayUpdate = Routine::Nop;
Routine::UpdateMatrix = Routine::Nop;
Routine::Led = Routine::Nop;
Matrix::GetInfo(count_live, count_dead, percent);
count_live_str = String(count_live);
count_dead_str = String(count_dead);
percent_str = String(percent);
str = String(" Paused ");
GFX::Message(0, 0, str);
str = String(count_live_str + "/" + count_dead_str + "=" + percent_str + "% ");
str = str.substring(0, 14);
GFX::Message(0, 41, str);
Display::UpdateFromDisplay();
} else {
Routine::pause = 0;
Routine::DisplayUpdate = Display::UpdateFromMatrix;
Routine::UpdateMatrix = Matrix::GameOfLife;
Routine::Led = LED::Toggle;
}
}
void Routine::Flip() {
Matrix::Flip();
}
void Routine::DecreaseDelay() {
// achtung Routine::sleep overflows when under 0
if (BETWEEN(Routine::sleep - SLEEP_STEP, 0, SLEEP_MAX)) {
Routine::sleep -= SLEEP_STEP;
String n = String(Routine::sleep);
String s = String("Delay: " + n + "ms");
GFX::Message(10, 10, s);
Display::UpdateFromDisplay();
delay(500);
}
}
void Routine::IncreaseDelay() {
if (Routine::sleep + SLEEP_STEP <= SLEEP_MAX) {
Routine::sleep += SLEEP_STEP;
String n = String(Routine::sleep);
String s = String("Delay: " + n + "ms");
GFX::Message(10, 10, s);
Display::UpdateFromDisplay();
delay(500);
}
}