-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRGBManager.cpp
More file actions
196 lines (158 loc) · 4.89 KB
/
Copy pathRGBManager.cpp
File metadata and controls
196 lines (158 loc) · 4.89 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
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
186
187
188
189
190
191
192
193
194
195
196
#include "RGBManager.h"
#include "Utilities.h"
RGBManager::RGBManager(TFT_eSPI* screen, RGB_EFFECT effect, int speed, int width, int height) {
this->screen = screen;
this->effect = effect;
this->color = 0;
this->speed = speed;
this->direction = 0;
this->width = width;
this->height = height;
this->x = 0;
this->y = 0;
this->speedCounter = 0;
}
void RGBManager::draw() {
if (RGB_EFFECT::NONE == this->effect) {
if (updated) {
for (int i = 0; i < width; i++) {
screen->drawRect(x + i, y + i, screen->width() - (i * 2), screen->height() - (i * 2), TFT_BLACK);
}
updated = false;
}
return;
}
//if single color and not updated, skip
if (RGB_EFFECT::SINGLE_COLOR == this->effect && !updated) {
return;
}
speedCounter++;
if (speedCounter == speed) {
switch (this->effect) {
case RGB_EFFECT::SINGLE_COLOR:
single_color();
break;
case RGB_EFFECT::RAINBOW_LINE:
rainbow_line();
break;
case RGB_EFFECT::RAINBOW_SNAKE:
//rainbow_snake();
break;
default:
break;
}
speedCounter = 0;
//calculate next position
//the line should go around the screen at the edge
//from top left, top right, bottom right, bottom left
//then back to top left
//top left
if (x == 0 && y == 0) {
x = 0;
y = 0;
direction = 0;
}
//top right
else if (x == screen->width() - width && y == 0) {
x = screen->width() - width;
y = 0;
direction = 1;
}
//bottom right
else if (x == screen->width() - width && y == screen->height() - height) {
x = screen->width() - width;
y = screen->height() - height;
direction = 2;
}
//bottom left
else if (x == 0 && y == screen->height() - height) {
x = 0;
y = screen->height() - height;
direction = 3;
}
}
}
void RGBManager::single_color() {
if (updated) {
//based on width, draw a rectangle with that thickness by going through for loop and drawing a rectangle for each width
//so if width is 4, draw 4 rectangles
//first at 0,0 with width and height of screen width and height
//second at 1,1 with width and height of screen width - 2 and height - 2
//third at 2,2 with width and height of screen width - 4 and height - 4
//etc
for (int i = 0; i < width; i++) {
screen->drawRect(x + i, y + i, screen->width() - (i * 2), screen->height() - (i * 2), color);
}
//depening on width and height, draw a rectangle around the screen with the set thickness of width and height
//using two for loops, one for the width and one for the height
//draw a rectangle at the current x and y position (line by line)
// //draw the top and bottom lines with the height as thickness
// //using the drawLine function
// //call it height times
// for(int i = 0; i < height; i++){
// screen->drawLine(x, y + i, screen->width() - width, y + i, color);
// screen->drawLine(x, screen->height() - height + i, screen->width() - width, screen->height() - height + i, color);
// }
// //draw the left and right lines with the width as thickness
// //using the drawLine function
// //call it width times
// for(int i = 0; i < width; i++){
// screen->drawLine(x + i, y, x + i, screen->height() - height, color);
// screen->drawLine(screen->width() - width + i, y, screen->width() - width + i, screen->height() - height, color);
// }
//screen->drawRect(x, y, screen->width() - width, screen->height() - height, color);
updated = false;
}
}
void RGBManager::rainbow_line() {
//if (updated)
{
color = cycleRainbow(color);
for (int i = 0; i < width; i++) {
screen->drawRect(x + i, y + i, screen->width() - (i * 2), screen->height() - (i * 2), color);
}
updated = false;
}
}
void RGBManager::set_effect(RGB_EFFECT effect) {
this->effect = effect;
updated = true;
}
RGB_EFFECT RGBManager::get_effect() {
return this->effect;
}
void RGBManager::set_color(uint16_t color) {
this->color = color;
updated = true;
}
uint16_t RGBManager::get_color() {
return this->color;
}
void RGBManager::set_speed(int speed) {
this->speed = speed;
updated = true;
speedCounter = 0;
}
int RGBManager::get_speed() {
return this->speed;
}
void RGBManager::set_direction(int direction) {
this->direction = direction;
}
int RGBManager::get_direction() {
return this->direction;
}
void RGBManager::set_width(int width) {
this->width = width;
updated = true;
}
int RGBManager::get_width() {
return this->width;
}
void RGBManager::set_height(int height) {
this->height = height;
updated = true;
}
int RGBManager::get_height() {
return this->height;
}