-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhelmet_draw.cpp
More file actions
182 lines (134 loc) · 3.87 KB
/
helmet_draw.cpp
File metadata and controls
182 lines (134 loc) · 3.87 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
#include "ledscape.h"
#include "bonelib/kbdio.hpp"
//Animation include files//
#include "smiley.hpp"
#include "blank.hpp"
#include "fullColor.hpp"
#include "colorSquare.hpp"
#include "colorSquareRapid.hpp"
#include "scanner.hpp"
#include "pinwheel.hpp"
#include "upvote.hpp"
#include "stars.hpp"
#include "rainbowWheel.hpp"
#include "stringScroll.hpp"
#include "shootingStars.hpp"
#include "rainbowRoad.hpp"
static unsigned int use_frame = 0;
static ledscape_frame_t *frame[2];
const unsigned num_pixels = 170;
ledscape_t* const leds = ledscape_init(num_pixels);
void draw(const Frame* picture) {
int counter = 0;
for(int i = 0; i < sideHeight; i++) {
for(int j = 0; j < sideLength; j++) {
ledscape_set_color(frame[use_frame],22,counter,picture->m_side[j][sideHeight - 1 - i].r,picture->m_side[j][sideHeight - 1 - i].g,picture->m_side[j][sideHeight - 1 - i].b); //Left Rainbow Drawing
ledscape_set_color(frame[use_frame],10,counter,picture->m_side[j][sideHeight - 1 - i].r,picture->m_side[j][sideHeight - 1 - i].g,picture->m_side[j][sideHeight - 1 - i].b); //Right Rainbow Drawing
counter++;
}
}
counter = 0;
for(int i = 0; i < mainLength/2; i++) {
for(int j = 0; j < mainHeight; j++) {
if(i == 1) {
ledscape_set_color(frame[use_frame],11,counter,picture->m_face[i][j].r,picture->m_face[i][j].g,picture->m_face[i][j].b); //Left Drawing
}
else {
ledscape_set_color(frame[use_frame],11,counter,picture->m_face[mainLength/2 - 1 - i][mainHeight -1 - j].r,picture->m_face[mainLength/2 - 1 - i][mainHeight -1 - j].g,picture->m_face[mainLength/2 - 1 - i][mainHeight -1 - j].b); //Left Drawing
}
counter++;
}
}
counter = 0;
for(int i = 3; i < mainLength; i++) {
for(int j = 0; j < mainHeight; j++) {
if(i == 4) {
ledscape_set_color(frame[use_frame],14,counter,picture->m_face[i][j].r,picture->m_face[i][j].g,picture->m_face[i][j].b); //Left Drawing
}
else {
ledscape_set_color(frame[use_frame],14,counter,picture->m_face[i][mainHeight -1 - j].r,picture->m_face[i][mainHeight -1 - j].g,picture->m_face[i][mainHeight -1 - j].b); //Left Drawing
}
counter++;
}
}
ledscape_draw(leds, use_frame);
use_frame = (use_frame + 1)%2;
printf("BEFORE %d\n", picture->delay);
if (picture->delay > 0) usleep(picture->delay);
printf("AFTER\n");
return;
}
int main(void) {
frame[0] = ledscape_frame(leds, 0);
frame[1] = ledscape_frame(leds, 1);
int nextAnimation;
Animation* new_drawing = new Smiley();
BeagleBone::kbdio::echo(0);
Animation* drawing = NULL;
const Frame *frame;
bool quit = 0;
while(!quit) {
if (drawing != new_drawing) {
delete drawing;
drawing = new_drawing;
frame = drawing->getNextFrame();
draw(frame);
} else if (frame->delay > 0) {
frame = drawing->getNextFrame();
draw(frame);
}
if(BeagleBone::kbdio::kbhit() > 0) {
nextAnimation = BeagleBone::kbdio::getch();
//Keyboard Mapping
switch (nextAnimation) {
case 's':
new_drawing = new Smiley();
break;
case 'q':
new_drawing = new Blank();
break;
case 'd':
case 'f':
new_drawing = new FullColor();
break;
case 'w':
new_drawing = new ColorSquare();
break;
case 'W':
new_drawing = new ColorSquareRapid();
break;
case 'e':
new_drawing = new Scanner();
break;
case 'r':
new_drawing = new Pinwheel();
break;
case 't':
new_drawing = new Upvote();
break;
case 'z':
new_drawing = new Stars();
break;
case 'Z':
new_drawing = new ShootingStars();
break;
case 'x':
new_drawing = new RainbowWheel();
break;
case 'X':
new_drawing = new RainbowRoad();
break;
case 'p':
new_drawing = new StringScroll("SPACE ROCKS");
break;
case 'l':
new_drawing = new StringScroll("CULT");
break;
case 'Q':
quit = 1;
break;
}
}
}
BeagleBone::kbdio::echo(1);
}