|
@@ -29,24 +29,34 @@
|
29
|
29
|
#include "cube.h"
|
30
|
30
|
#include "time.h"
|
31
|
31
|
#include "audio.h"
|
|
32
|
+#include "memLayer.h"
|
32
|
33
|
|
33
|
34
|
#ifndef F_CPU
|
34
|
35
|
#define F_CPU 16000000L
|
35
|
36
|
#endif
|
36
|
37
|
|
|
38
|
+#define OK 0x42
|
|
39
|
+#define ERROR 0x23
|
|
40
|
+
|
|
41
|
+void serialHandler(char c);
|
|
42
|
+void recieveAnimations(void);
|
|
43
|
+void transmitAnimations(void);
|
37
|
44
|
uint8_t audioModeSelected(void);
|
38
|
45
|
inline void setPixelBuffer(uint8_t x, uint8_t y, uint8_t z, uint8_t **buf);
|
39
|
46
|
inline void clearPixelBuffer(uint8_t x, uint8_t y, uint8_t z, uint8_t **buf);
|
40
|
47
|
void setRow(uint8_t x, uint8_t z, uint8_t height, uint8_t **buf);
|
41
|
48
|
void visualizeAudioData(uint8_t *audioData, uint8_t **imageData);
|
42
|
49
|
|
|
50
|
+uint8_t refreshAnimationCount = 1;
|
|
51
|
+
|
43
|
52
|
int main(void) {
|
44
|
|
- char c;
|
|
53
|
+ unsigned int character;
|
45
|
54
|
uint8_t *audioData;
|
46
|
55
|
uint8_t **imageData;
|
47
|
|
- uint8_t i, j;
|
|
56
|
+ uint8_t i;
|
48
|
57
|
uint64_t lastTimeChecked;
|
49
|
58
|
uint8_t audioMode;
|
|
59
|
+ uint16_t count;
|
50
|
60
|
|
51
|
61
|
DDRD = 0xFF; // Mosfets as Output
|
52
|
62
|
DDRB = 0xFE;
|
|
@@ -77,7 +87,20 @@ int main(void) {
|
77
|
87
|
while(!isFinished()); // Wait for it to display
|
78
|
88
|
} else {
|
79
|
89
|
// Look for commands, play from fram
|
80
|
|
-
|
|
90
|
+ // We have 128*1024 bytes
|
|
91
|
+ // A Frame needs 65 bytes (64 data + duration)
|
|
92
|
+ // We place 2016 Frames in mem => 131040
|
|
93
|
+ // That gives us 32 bytes at the beginning, 0 -> 31
|
|
94
|
+ // The first frame starts at 32
|
|
95
|
+ character = uart_getc();
|
|
96
|
+ if (!(character & 0xFF00)) { // No error...
|
|
97
|
+ serialHandler((char)(character & 0x00FF));
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+ if (refreshAnimationCount) {
|
|
101
|
+ count = getAnimationCount();
|
|
102
|
+ refreshAnimationCount = 0;
|
|
103
|
+ }
|
81
|
104
|
}
|
82
|
105
|
|
83
|
106
|
if ((getSystemTime() - lastTimeChecked) > 1000) {
|
|
@@ -91,6 +114,109 @@ int main(void) {
|
91
|
114
|
return 0;
|
92
|
115
|
}
|
93
|
116
|
|
|
117
|
+void serialHandler(char c) {
|
|
118
|
+ // Got a char on serial line...
|
|
119
|
+ // React accordingly
|
|
120
|
+ // Set refreshAnimationCount if Animation Data in Ram was changed...
|
|
121
|
+ // We do a complete transaction in one call of this routine...
|
|
122
|
+
|
|
123
|
+ switch(c) {
|
|
124
|
+ case OK:
|
|
125
|
+ // Send "Hello World"
|
|
126
|
+ uart_putc(OK);
|
|
127
|
+ break;
|
|
128
|
+
|
|
129
|
+ case 'd': case 'D':
|
|
130
|
+ clearMem();
|
|
131
|
+ uart_putc(OK);
|
|
132
|
+ break;
|
|
133
|
+
|
|
134
|
+ case 'g': case 'G':
|
|
135
|
+ transmitAnimations();
|
|
136
|
+ break;
|
|
137
|
+
|
|
138
|
+ case 's': case 'S':
|
|
139
|
+ recieveAnimations();
|
|
140
|
+ break;
|
|
141
|
+
|
|
142
|
+ default:
|
|
143
|
+ uart_putc(ERROR);
|
|
144
|
+ break;
|
|
145
|
+ }
|
|
146
|
+}
|
|
147
|
+
|
|
148
|
+void recieveAnimations() {
|
|
149
|
+ uint8_t animCount, a, frameCount, f, i;
|
|
150
|
+ uint16_t completeCount = 0, character;
|
|
151
|
+ uint8_t frame[65];
|
|
152
|
+
|
|
153
|
+ uart_putc(OK); // We are ready...
|
|
154
|
+
|
|
155
|
+ character = uart_getc();
|
|
156
|
+ while (character & 0xFF00) { // Wait for answer
|
|
157
|
+ character = uart_getc();
|
|
158
|
+ }
|
|
159
|
+
|
|
160
|
+ animCount = (uint8_t)(character & 0x00FF); // Got animation count
|
|
161
|
+ uart_putc(OK);
|
|
162
|
+
|
|
163
|
+ for (a = 0; a < animCount; a++) {
|
|
164
|
+ character = uart_getc();
|
|
165
|
+ while (character & 0xFF00) { // Wait for answer
|
|
166
|
+ character = uart_getc();
|
|
167
|
+ }
|
|
168
|
+
|
|
169
|
+ frameCount = (uint8_t)(character & 0x00FF); // Got frame count
|
|
170
|
+ uart_putc(OK);
|
|
171
|
+
|
|
172
|
+ for (f = 0; f < frameCount; f++) {
|
|
173
|
+ character = uart_getc();
|
|
174
|
+ while (character & 0xFF00) { // Wait for answer
|
|
175
|
+ character = uart_getc();
|
|
176
|
+ }
|
|
177
|
+
|
|
178
|
+ frame[64] = (uint8_t)(character & 0x00FF); // Got duration
|
|
179
|
+ uart_putc(OK);
|
|
180
|
+
|
|
181
|
+ for (i = 0; i < 64; i++) {
|
|
182
|
+ character = uart_getc();
|
|
183
|
+ while (character & 0xFF00) { // Wait for answer
|
|
184
|
+ character = uart_getc();
|
|
185
|
+ }
|
|
186
|
+
|
|
187
|
+ frame[i] = (uint8_t)(character & 0x00FF); // Got data byte
|
|
188
|
+ }
|
|
189
|
+ uart_putc(OK);
|
|
190
|
+
|
|
191
|
+ setFrame(completeCount++, frame);
|
|
192
|
+ }
|
|
193
|
+ }
|
|
194
|
+
|
|
195
|
+ character = uart_getc();
|
|
196
|
+ while (character & 0xFF00) { // Wait for answer
|
|
197
|
+ character = uart_getc();
|
|
198
|
+ }
|
|
199
|
+ character = uart_getc();
|
|
200
|
+ while (character & 0xFF00) { // Wait for answer
|
|
201
|
+ character = uart_getc();
|
|
202
|
+ }
|
|
203
|
+ character = uart_getc();
|
|
204
|
+ while (character & 0xFF00) { // Wait for answer
|
|
205
|
+ character = uart_getc();
|
|
206
|
+ }
|
|
207
|
+ character = uart_getc();
|
|
208
|
+ while (character & 0xFF00) { // Wait for answer
|
|
209
|
+ character = uart_getc();
|
|
210
|
+ }
|
|
211
|
+ uart_putc(OK);
|
|
212
|
+ setAnimationCount(completeCount);
|
|
213
|
+ refreshAnimationCount = 1;
|
|
214
|
+}
|
|
215
|
+
|
|
216
|
+void transmitAnimations() {
|
|
217
|
+ uart_putc(ERROR);
|
|
218
|
+}
|
|
219
|
+
|
94
|
220
|
// Blocks 10ms or more
|
95
|
221
|
uint8_t audioModeSelected(void) {
|
96
|
222
|
// Switch: PB0, Low active
|