forked from pixelmatix/aurora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingsClockColor.h
185 lines (156 loc) · 5.71 KB
/
SettingsClockColor.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* Aurora: https://github.com/pixelmatix/aurora
* Copyright (c) 2014 Jason Coon
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SettingsClockColor_H
#define SettingsClockColor_H
class SettingsClockColor : public Runnable {
private:
int cursorX = 0;
int cursorY = 0;
boolean hasChanges = false;
public:
void start() {
CHSV chsv;
CRGB crgb;
for (int x = 0; x < MATRIX_WIDTH - 1; x += 1) {
uint8_t hue = x * 8;
for (int y = 0; y < MATRIX_HEIGHT; y += 1) {
if (y <= 16) {
chsv = CHSV(hue, y * 15 + 15, 255);
}
else {
chsv = CHSV(hue, 255, 255 - (y - 17) * 15);
}
hsv2rgb_rainbow(chsv, crgb);
if (crgb.r == clockDisplay.color.red &&
crgb.g == clockDisplay.color.green &&
crgb.b == clockDisplay.color.blue) {
cursorX = x;
cursorY = y;
return;
}
}
}
}
void run() {
while (true) {
drawFrame();
// draw an RGB grid, Hue from 0 to 248 left to right (256 is the same as 0)
// Saturation from 15 (mostly white) to 255 (fully-saturated color) top to middle (0 to 16), skipping 0 which is white and will be handled in the right-most column)
// then Value from 255 (fully-saturated color) to 45 (mostly black) middle to bottom, skipping anything lower than 45 which is indistinguishable from black.
CHSV chsv;
CRGB crgb;
CRGB selectedColor = CRGB::White;
for (int x = 0; x < MATRIX_WIDTH - 1; x += 1) {
uint8_t hue = x * 8;
for (int y = 0; y < MATRIX_HEIGHT; y += 1) {
if (y <= 16) {
chsv = CHSV(hue, y * 15 + 15, 255);
}
else {
chsv = CHSV(hue, 255, 255 - (y - 17) * 15);
}
hsv2rgb_rainbow(chsv, crgb);
matrix.drawPixel(x, y, crgb);
if (x == cursorX && y == cursorY)
selectedColor = crgb;
}
}
// draw a grayscale strip down the right edge
// from 0 (white) to 69 (mostly black), skipping anything lower than 69 which is almost indistinguishable from black.
int x = MATRIX_WIDTH - 1;
for (int y = 0; y < MATRIX_HEIGHT; y += 1) {
chsv = CHSV(0, 0, 255 - y * 6);
hsv2rgb_rainbow(chsv, crgb);
matrix.drawPixel(x, y, crgb);
if (x == cursorX && y == cursorY)
selectedColor = crgb;
}
// draw the cursor crosshairs
uint8_t v = cursorY * 8;
crgb = CRGB(v, v, v);
// horizontal cursor lines
matrix.drawLine(cursorX - 4, cursorY, cursorX - 2, cursorY, crgb);
matrix.drawLine(cursorX + 4, cursorY, cursorX + 2, cursorY, crgb);
// vertical cursor lines
matrix.drawLine(cursorX, cursorY - 4, cursorX, cursorY - 2, crgb);
matrix.drawLine(cursorX, cursorY + 4, cursorX, cursorY + 2, crgb);
// draw the clock numbers at the bottom, so we can see the selected color better, without leaving the settings item
clockDisplay.setColor(selectedColor);
clockDisplay.readTime();
if (cursorY >= 18) {
clockDigitalShort.drawFrame(0);
}
else {
clockDigitalShort.drawFrame(23);
}
matrix.displayForegroundDrawing(false);
matrix.swapBuffers();
InputCommand command = readCommand(defaultHoldDelay);
switch (command) {
case InputCommand::Left:
cursorX -= 1;
hasChanges = true;
break;
case InputCommand::Right:
cursorX += 1;
hasChanges = true;
break;
case InputCommand::Up:
cursorY -= 1;
hasChanges = true;
break;
case InputCommand::Down:
cursorY += 1;
hasChanges = true;
break;
case InputCommand::Select:
case InputCommand::Back:
if (hasChanges) {
save(selectedColor);
hasChanges = false;
}
return;
default:
break;
}
if (cursorX < 0)
cursorX = MATRIX_WIDTH - 1;
else if (cursorX >= MATRIX_WIDTH)
cursorX = 0;
if (cursorY < 0)
cursorY = MATRIX_HEIGHT - 1;
else if (cursorY >= MATRIX_HEIGHT)
cursorY = 0;
}
}
unsigned int drawFrame() {
matrix.fillScreen(CRGB(CRGB::Black));
matrix.setFont(font3x5);
matrix.drawString(0, 27, { 255, 255, 255 }, versionText);
return 0;
}
void save(CRGB crgb) {
clockDisplay.setColor(crgb);
clockDisplay.saveColor();
}
};
#endif