Browse Source

CubeFirmware major rewrite.

Removed buggy idle animations. Killed idle frames alltogether.
Thomas Buck 12 years ago
parent
commit
3a492fc89f
7 changed files with 1449 additions and 1629 deletions
  1. 37
    150
      CubeFirmware/animations.c
  2. 0
    64
      CubeFirmware/builtInFrames.c
  3. 2
    1
      CubeFirmware/header/transmit.h
  4. 144
    178
      CubeFirmware/main.c
  5. 1212
    1233
      CubeFirmware/main.hex
  6. 51
    0
      CubeFirmware/transmit.c
  7. 3
    3
      UploadTest/main.c

+ 37
- 150
CubeFirmware/animations.c View File

39
 */
39
 */
40
 
40
 
41
 // Prototypes for all animations
41
 // Prototypes for all animations
42
-void upWave(void);
43
-void downWave(void);
44
-void xWave1(void);
45
-void xWave2(void);
46
-void zWave1(void);
47
-void zWave2(void);
48
-void tinyCube(void);
49
-void smallCube(void);
50
-void bigCube(void);
51
-void fullCube(void);
52
-
42
+void upWave(uint8_t i);
43
+void downWave(uint8_t i);
44
+void xWave1(uint8_t i);
45
+void xWave2(uint8_t i);
46
+void zWave1(uint8_t i);
47
+void zWave2(uint8_t i);
53
 
48
 
54
 // Array of animation functions
49
 // Array of animation functions
55
-#define NUMOFANIMATIONS 10
56
-void (*animations[NUMOFANIMATIONS])(void) = { &upWave, &downWave,
57
-								&xWave1, &xWave2, &zWave1,
58
-								&zWave2, &tinyCube, &smallCube, &bigCube, &fullCube };
50
+#define NUMOFANIMATIONS 0
51
+void (*animations[NUMOFANIMATIONS])(void) = { };
59
 
52
 
60
 #define WAVELENGTH 2
53
 #define WAVELENGTH 2
61
 
54
 
62
 uint8_t numOfAnimations(void) {
55
 uint8_t numOfAnimations(void) {
63
-	return NUMOFANIMATIONS;
56
+	return NUMOFANIMATIONS + 24;
64
 }
57
 }
65
 
58
 
66
 void executeAnimation(uint8_t id) {
59
 void executeAnimation(uint8_t id) {
67
-	if (id < NUMOFANIMATIONS) {
68
-		animations[id](); // Call animation
60
+	if (id < (6*4)) {
61
+		if (id < 4) {
62
+			upWave(id);
63
+		} else if (id < 8) {
64
+			downWave(id - 4);
65
+		} else if (id < 12) {
66
+			xWave1(id - 8);
67
+		} else if (id < 16) {
68
+			xWave2(id - 12);
69
+		} else if (id < 20) {
70
+			zWave1(id - 16);
71
+		} else {
72
+			zWave2(id - 20);
73
+		}
74
+	} else if ((id - (6*4)) < NUMOFANIMATIONS) {
75
+		animations[id - (6*4)](); // Call animation
69
 	}
76
 	}
70
 }
77
 }
71
 
78
 
72
-void upWave(void) {
79
+void upWave(uint8_t i) {
73
 	uint8_t *buff;
80
 	uint8_t *buff;
74
 	int8_t x, y, z;
81
 	int8_t x, y, z;
75
 
82
 
76
 	buff = buffNew();
83
 	buff = buffNew();
77
 	// Up-wave
84
 	// Up-wave
78
-	for(y = 0; y < 8; y++) {
85
+	for(y = (i * 2); y < ((i * 2) + 2); y++) {
79
 		for(x = 0; x < 8; x++) {
86
 		for(x = 0; x < 8; x++) {
80
 			for(z = 0; z < 8; z++) {
87
 			for(z = 0; z < 8; z++) {
81
 				buffSetPixel(buff, x, y, z);
88
 				buffSetPixel(buff, x, y, z);
90
 	free(buff);
97
 	free(buff);
91
 }
98
 }
92
 
99
 
93
-void downWave(void) {
100
+void downWave(uint8_t i) {
94
 	uint8_t *buff;
101
 	uint8_t *buff;
95
 	int8_t x, y, z;
102
 	int8_t x, y, z;
96
 
103
 
97
 	buff = buffNew();
104
 	buff = buffNew();
98
 	// Down-wave (Frames 9-15 of showoff.cube)
105
 	// Down-wave (Frames 9-15 of showoff.cube)
99
-	for(y = 7; y >= 0; y--) {
106
+	for(y = (7 - (2 * i)); y >= ((7 - (2 * i)) - 1); y--) {
100
 		for(x = 0; x < 8; x++) {
107
 		for(x = 0; x < 8; x++) {
101
 			for(z = 0; z < 8; z++) {
108
 			for(z = 0; z < 8; z++) {
102
 				buffSetPixel(buff, x, y, z);
109
 				buffSetPixel(buff, x, y, z);
111
 	free(buff);
118
 	free(buff);
112
 }
119
 }
113
 
120
 
114
-void xWave1(void) {
121
+void xWave1(uint8_t i) {
115
 	uint8_t *buff;
122
 	uint8_t *buff;
116
 	int8_t x, y, z;
123
 	int8_t x, y, z;
117
 
124
 
118
 	buff = buffNew();
125
 	buff = buffNew();
119
 	// x-axis wave
126
 	// x-axis wave
120
-	for(x = 0; x < 8; x++) {
127
+	for(x = (i * 2); x < ((i * 2) + 2); x++) {
121
 		for(y = 0; y < 8; y++) {
128
 		for(y = 0; y < 8; y++) {
122
 			for(z = 0; z < 8; z++) {
129
 			for(z = 0; z < 8; z++) {
123
 				buffSetPixel(buff, x, y, z);
130
 				buffSetPixel(buff, x, y, z);
132
 	free(buff);
139
 	free(buff);
133
 }
140
 }
134
 
141
 
135
-void xWave2(void) {
142
+void xWave2(uint8_t i) {
136
 	uint8_t *buff;
143
 	uint8_t *buff;
137
 	int8_t x, y, z;
144
 	int8_t x, y, z;
138
 
145
 
139
 	buff = buffNew();
146
 	buff = buffNew();
140
-	for(x = 7; x >= 0; x--) {
147
+	for(x = (7 - (2 * i)); x >= ((7 - (2 * i)) - 1); x--) {
141
 		for(y = 0; y < 8; y++) {
148
 		for(y = 0; y < 8; y++) {
142
 			for(z = 0; z < 8; z++) {
149
 			for(z = 0; z < 8; z++) {
143
 				buffSetPixel(buff, x, y, z);
150
 				buffSetPixel(buff, x, y, z);
152
 	free(buff);
159
 	free(buff);
153
 }
160
 }
154
 
161
 
155
-void zWave1(void) {
162
+void zWave1(uint8_t i) {
156
 	uint8_t *buff;
163
 	uint8_t *buff;
157
 	int8_t x, y, z;
164
 	int8_t x, y, z;
158
 
165
 
159
 	buff = buffNew();
166
 	buff = buffNew();
160
 	// z-axis-wave
167
 	// z-axis-wave
161
-	for(z = 0; z < 8; z++) {
168
+	for(z = (i * 2); z < ((i * 2) + 2); z++) {
162
 		for(y = 0; y < 8; y++) {
169
 		for(y = 0; y < 8; y++) {
163
 			for(x = 0; x < 8; x++) {
170
 			for(x = 0; x < 8; x++) {
164
 				buffSetPixel(buff, x, y, z);
171
 				buffSetPixel(buff, x, y, z);
173
 	free(buff);
180
 	free(buff);
174
 }
181
 }
175
 
182
 
176
-void zWave2(void) {
183
+void zWave2(uint8_t i) {
177
 	uint8_t *buff;
184
 	uint8_t *buff;
178
 	int8_t x, y, z;
185
 	int8_t x, y, z;
179
 
186
 
180
 	buff = buffNew();
187
 	buff = buffNew();
181
-	for(z = 7; z >= 0; z--) {
188
+	for(z = (7 - (2 * i)); z >= ((7 - (2 * i)) - 1); z--) {
182
 		for(x = 0; x < 8; x++) {
189
 		for(x = 0; x < 8; x++) {
183
 			for(y = 0; y < 8; y++) {
190
 			for(y = 0; y < 8; y++) {
184
 				buffSetPixel(buff, x, y, z);
191
 				buffSetPixel(buff, x, y, z);
192
 	}
199
 	}
193
 	free(buff);
200
 	free(buff);
194
 }
201
 }
195
-
196
-void tinyCube(void) {
197
-	uint8_t *buff;
198
-
199
-	buff = buffNew();
200
-
201
-	//Cube_1
202
-	buffSetPixel(buff, 3, 3, 3);
203
-	buffSetPixel(buff, 4, 3, 3);
204
-	buffSetPixel(buff, 4, 4, 3);
205
-	buffSetPixel(buff, 4, 4, 4);
206
-	setImage(buff);
207
-	while(isFinished() < WAVELENGTH) {
208
-		wdt_reset();	
209
-	}
210
-	buffClearAllPixels(buff);
211
-
212
-	free(buff);
213
-}
214
-
215
-void smallCube (void){
216
-	uint8_t *buff;
217
-	int8_t x, y, z;
218
-
219
-	buff = buffNew();
220
-
221
-	//Cube_2
222
-	for(x = 2; x < 6; x++) {
223
-		for(y = 2; y < 6; y++) {
224
-			buffSetPixel(buff, x, y, 2);
225
-			buffSetPixel(buff, x, y, 5);
226
-		}
227
-	}
228
-	for(y = 2; y < 6; y++) {
229
-		for(z = 2; z < 6; z++) {
230
-			buffSetPixel(buff, 2, y, z);
231
-			buffSetPixel(buff, 5, y, z);
232
-		}
233
-	}
234
-	for(x = 2; x < 6; x++) {
235
-		for(z = 2; z < 6; z++) {
236
-			buffSetPixel(buff, x, 2, z);
237
-			buffSetPixel(buff, x, 5, z);
238
-		}
239
-	}
240
-	setImage(buff);
241
-	while(isFinished() < WAVELENGTH) {
242
-		wdt_reset();	
243
-	}
244
-	buffClearAllPixels(buff);
245
-	free(buff);
246
-}
247
-
248
-void bigCube (void) {
249
-	uint8_t *buff;
250
-	int8_t x, y, z;
251
-
252
-	buff = buffNew();
253
-
254
-	//Cube_3
255
-	for(x = 1; x < 7; x++){
256
-		for(y = 1; y < 7; y++) {
257
-			buffSetPixel(buff, x, y, 1);
258
-			buffSetPixel(buff, x, y, 6);
259
-		}
260
-	}
261
-	for(y = 1; y < 7; y++){
262
-		for(z = 1; z < 7; z++) {
263
-			buffSetPixel(buff, 1, y, z);
264
-			buffSetPixel(buff, 6, y, z);
265
-		}
266
-	}
267
-	for(x = 1; x < 7; x++){
268
-		for(z = 1; z < 7; z++) {
269
-			buffSetPixel(buff, x, 1, z);
270
-			buffSetPixel(buff, x, 6, z);
271
-		}
272
-	}
273
-	setImage(buff);
274
-	while(isFinished() < WAVELENGTH) {
275
-		wdt_reset();	
276
-	}
277
-	buffClearAllPixels(buff);
278
-
279
-	free(buff);
280
-}
281
-
282
-void fullCube (void) {
283
-	uint8_t *buff;
284
-	int8_t x, y, z;
285
-
286
-	buff = buffNew();
287
-	
288
-	//Cube_4
289
-	for(x = 0; x < 8; x++){
290
-		for(y = 0; y < 8; y++) {
291
-			buffSetPixel(buff, x, y, 0);
292
-			buffSetPixel(buff, x, y, 7);
293
-		}
294
-	}
295
-	for(y = 0; y < 8; y++){
296
-		for(z = 0; z < 8; z++) {
297
-			buffSetPixel(buff, 0, y, z);
298
-			buffSetPixel(buff, 8, y, z);
299
-		}
300
-	}
301
-	for(x = 0; x < 8; x++){
302
-		for(z = 0; z < 8; z++) {
303
-			buffSetPixel(buff, x, 0, z);
304
-			buffSetPixel(buff, x, 8, z);
305
-		}
306
-	}
307
-	setImage(buff);
308
-	while(isFinished() < WAVELENGTH) {
309
-		wdt_reset();	
310
-	}
311
-	buffClearAllPixels(buff);
312
-
313
-	free(buff);
314
-}

+ 0
- 64
CubeFirmware/builtInFrames.c View File

1
-/*
2
- * builtInFrames.c
3
- *
4
- * Copyright 2011 Thomas Buck <xythobuz@me.com>
5
- * Copyright 2011 Max Nuding <max.nuding@gmail.com>
6
- * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
7
- *
8
- * This file is part of LED-Cube.
9
- *
10
- * LED-Cube is free software: you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
12
- * the Free Software Foundation, either version 3 of the License, or
13
- * (at your option) any later version.
14
- *
15
- * LED-Cube is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
- * GNU General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU General Public License
21
- * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
22
- */
23
-
24
-// First image loaded after initializing cube code.
25
-// Only visible for a short period of time after every reset.
26
-uint8_t defaultImageCube[64] = {	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
27
-									0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF,
28
-									0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF,
29
-									0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF,
30
-									0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF,
31
-									0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF,
32
-									0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF,
33
-									0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
34
-
35
-// Idle animation. Displayed when no animations are stored in memory.
36
-uint8_t defaultImageA[64] = {	0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
37
-								0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
38
-								0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
39
-								0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
40
-								0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
41
-								0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
42
-								0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
43
-								0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff };
44
-
45
-uint8_t defaultImageB[64] = {	0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
46
-								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
47
-								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
48
-								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
49
-								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
50
-								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
51
-								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
52
-								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81 };
53
-
54
-uint8_t defaultImageC[64] = {	0x1e, 0x42, 0x42, 0x42, 0x1e, 0x02, 0x02, 0x02,
55
-								0x1e, 0x42, 0x42, 0x42, 0x1e, 0x02, 0x02, 0x02,
56
-								0x1e, 0x42, 0x42, 0x42, 0x1e, 0x02, 0x02, 0x02,
57
-								0x1e, 0x42, 0x42, 0x42, 0x1e, 0x02, 0x02, 0x02,
58
-								0x1e, 0x42, 0x42, 0x42, 0x1e, 0x02, 0x02, 0x02,
59
-								0x1e, 0x42, 0x42, 0x42, 0x1e, 0x02, 0x02, 0x02,
60
-								0x1e, 0x42, 0x42, 0x42, 0x1e, 0x02, 0x02, 0x02,
61
-								0x1e, 0x42, 0x42, 0x42, 0x1e, 0x02, 0x02, 0x02 };
62
-
63
-#define IDLEANIMATIONCOUNT 3
64
-uint8_t *idleAnimation[IDLEANIMATIONCOUNT] = { defaultImageA, defaultImageB, defaultImageC };

+ 2
- 1
CubeFirmware/header/transmit.h View File

23
 
23
 
24
 void recieveAnimations(void);
24
 void recieveAnimations(void);
25
 void transmitAnimations(void);
25
 void transmitAnimations(void);
26
-void sendAudioData(void);
26
+void sendAudioData(void);
27
+void printTime(void);

+ 144
- 178
CubeFirmware/main.c View File

48
 #include "animations.h"
48
 #include "animations.h"
49
 #include "transmit.h"
49
 #include "transmit.h"
50
 
50
 
51
+// Length of an idle animation frame, 24 -> 1 second
52
+#define IDLELENGTH 48
53
+
54
+void init(void);
55
+uint8_t audioModeSelected(void);
56
+uint8_t selfTest(void);
57
+void serialHandler(char c);
58
+
59
+uint8_t defaultImageCube[64] = {	0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81,
60
+									0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61
+									0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62
+									0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63
+									0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
64
+									0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
65
+									0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
66
+									0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
67
+
51
 #define NOERROR 0
68
 #define NOERROR 0
52
 // Audio does not answer
69
 // Audio does not answer
53
 #define AUDIOERROR 1
70
 #define AUDIOERROR 1
58
 // x = errorcode, e = error definition, not NOERROR
75
 // x = errorcode, e = error definition, not NOERROR
59
 #define ISERROR(x, e) ((x) & (e))
76
 #define ISERROR(x, e) ((x) & (e))
60
 
77
 
61
-// Length of an idle animation frame, 24 -> 1 second
62
-#define IDLELENGTH 48
63
-
64
-void serialHandler(char c);
65
-uint8_t audioModeSelected(void);
66
-void printErrors(uint8_t e);
67
-uint8_t selfTest(void);
68
-void printTime(void);
69
-
70
-// #include "snake.c"
71
-
72
 uint8_t shouldRestart = 0;
78
 uint8_t shouldRestart = 0;
73
-uint8_t refreshAnimationCount = 1;
79
+uint8_t refreshAnimationCount = 0;
74
 uint8_t lastButtonState = 0;
80
 uint8_t lastButtonState = 0;
75
-uint8_t maxButtonState = 0;
76
-char buffer[11];
77
-
78
-#include "builtInFrames.c"
81
+uint8_t maxButtonState = 1; // No audio, get's checked later
82
+uint8_t disableAudioData = 0;
83
+uint8_t disableMemory = 0;
84
+uint8_t disableAnim = 0;
79
 
85
 
80
-uint8_t DebugDone = 0; // Bit 0: 10s int. count, Bit 1: idle switch
81
-					   // Bit 2: state changed, disable idle
86
+char buffer[11];
82
 
87
 
83
 int main(void) {
88
 int main(void) {
84
-	uint8_t *audioData = NULL;
85
-	uint8_t *imageData = NULL;
86
-	uint8_t i, length = 0;
87
-	uint16_t count;
88
-	uint64_t lastChecked;
89
-	uint8_t idleCounter = 0;
89
+	/*
90
+		Quick Summary of the jobs main has to do:
91
+		- Initialize Cube
92
+		- Regularly check the buttonstate
93
+		- Check for incoming serial transmission and run serialHandler
94
+		- Check if animations are stored
95
+		--> If yes, display them
96
+		--> If no, display our idle animations
97
+	*/
98
+
99
+	uint8_t i;
100
+	uint8_t imageIndex = 0, imageCount = 0;
101
+	uint8_t idleIndex = 0, idleCount = 0;
102
+	uint8_t lastButtonCheck, fpsWasSent = 0;
90
 	uint32_t temp;
103
 	uint32_t temp;
104
+	uint8_t *imageData = NULL, *audioData = NULL;
105
+	uint8_t duration = 0;
91
 
106
 
92
-	MCUCSR = 0;
107
+	// Initialization:
108
+	MCUCSR = 0; // Reset Watchdog
93
 	wdt_disable();
109
 	wdt_disable();
94
-
95
-	DDRA = 0xFF; // Latch Data Bus as Output
96
-	DDRD = 0xFC; DDRB = 24; // Mosfets as Output
97
-	DDRC = 0xFC; DDRB |= 6; // Latch Enable as Output
98
-	DDRB &= ~(1 << PB0); // Pushbutton as Input
99
-
100
-	initCube();
101
-	serialInit(25, 8, NONE, 1);
102
-	i2c_init();
103
-	initSystemTimer();
104
-	sei(); // Enable Interrupts
105
-
106
-	setImage(defaultImageCube); // Display something
107
-
110
+	init(); // Initialize all subsystems, set port directions, enable interrupts
108
 	wdt_enable(WDTO_1S); // Watchdog reset after 1 second
111
 	wdt_enable(WDTO_1S); // Watchdog reset after 1 second
109
-
110
-	serialWriteString(getString(2)); // "Initialized: "
111
-
112
-	i = selfTest();
113
-	if (i) {
114
-		serialWriteString(getString(1)); // Selftest error
115
-		serialWriteString(itoa(i, buffer, 2));
116
-		serialWrite('\n');
117
-		printErrors(i);
118
-	}
119
-
120
-	serialWriteString(getString(0)); // Version
121
-
122
-	maxButtonState = numberOfVisualizations() + 1; // All visualizations and anim mode
123
-
124
-	audioModeSelected();
125
-	lastChecked = getSystemTime();
126
-
127
-	i = 0; // Image count
128
-	count = getAnimationCount();
129
-
130
-	while (1) {
131
-		// Reset if requested
132
-		if (!shouldRestart) {
112
+	i = selfTest(); // Run selftest, print errors
113
+	// Disable subsystems if they are unavailable
114
+	if (ISERROR(i, AUDIOERROR))
115
+		disableAudioData = 1;
116
+	if (ISERROR(i, MEMORYERROR) || ISERROR(i, MEMORYWRITEERROR))
117
+		disableMemory = 1;
118
+	serialWriteString(getString(0)); // Print Version
119
+
120
+	audioModeSelected(); // Initial button state check
121
+	lastButtonCheck = getSystemTime(); // Time we checked
122
+
123
+	if (disableMemory == 0)
124
+		imageCount = getAnimationCount(); // Retrieve image count from memory
125
+	idleCount = numOfAnimations();
126
+	if (disableAudioData == 0)
127
+		maxButtonState = numberOfVisualizations() + 1; // Number of toggle steps for button
128
+
129
+	while(1) { // Our Mainloop
130
+		if (!shouldRestart) { // A flag to trigger a watchdog reset
133
 			wdt_reset();
131
 			wdt_reset();
134
 		}
132
 		}
135
 
133
 
136
-		if(lastButtonState >= 1) {
137
-			// Get Audio Data and visualize it.
138
-			// Visualization id is in (lastButtonState - 1)
139
-			if (isFinished()) {
140
-				audioData = getAudioData(); // Not malloc'ed => Don't free
141
-				if (audioData != NULL) {
142
-					runVisualization(audioData, lastButtonState - 1);
143
-				}
144
-			}
145
-		} else {
146
-			if (refreshAnimationCount) {
147
-				// Get animation count stored in FRAM via TWI, if needed
148
-				count = getAnimationCount();
149
-				refreshAnimationCount = 0;
150
-				i = 0;
151
-			}
134
+		if (refreshAnimationCount) {
135
+			refreshAnimationCount = 0;
136
+			if (disableMemory == 0)
137
+				imageCount = getAnimationCount();
138
+		}
152
 
139
 
153
-			if (count > 0) { // We have frames stored
154
-				if (isFinished() > length) {
155
-					// Load next image
156
-					if (i < (count - 1)) {
157
-						i++;
158
-					} else {
159
-						i = 0;
160
-					}
140
+		if (serialHasChar()) { // Run serialHandler
141
+			serialHandler((char)(serialGet()));
142
+		}
161
 
143
 
162
-					imageData = getFrame(i);
163
-					length = imageData[64];
164
-					setImage(imageData);
165
-					free(imageData);
166
-				}
167
-			} else { // No frames available
168
-				if (!(DebugDone & 4)) { // Idle animation allowed
169
-					if (DebugDone & 2) {
170
-						if (idleCounter < numOfAnimations()) {
171
-							executeAnimation(idleCounter++);
144
+		if ((getSystemTime() - lastButtonCheck) > 150) { // Check button state every 150ms
145
+			audioModeSelected();
146
+			lastButtonCheck = getSystemTime();
147
+		}
148
+
149
+		if (lastButtonState == 0) {
150
+			// Display animations, stored or built-in
151
+			if (disableAnim == 0) {
152
+				if ((imageCount > 0) && (disableMemory == 0)) {
153
+					// Memory frames
154
+					if (isFinished() > duration) {
155
+						// Last frame was displayed long enough
156
+						imageIndex = (imageIndex < (imageCount - 1)) ? (imageIndex + 1) : 0;
157
+						imageData = getFrame(i);
158
+						if (imageData == NULL) {
159
+							duration = 24;
160
+							setImage(defaultImageCube);
172
 						} else {
161
 						} else {
173
-							idleCounter = 0;
174
-							DebugDone &= ~(2); // Show frames again
175
-						}
176
-					} else {
177
-						// Show idle frames
178
-						if (isFinished() >= IDLELENGTH) {
179
-							setImage(idleAnimation[idleCounter]);
180
-							if (idleCounter < IDLEANIMATIONCOUNT) {
181
-								idleCounter++;
182
-							} else {
183
-								idleCounter = 0;
184
-								DebugDone |= 2; // Show animation
185
-							}
162
+							duration = imageData[64];
163
+							setImage(imageData);
164
+							free(imageData);
186
 						}
165
 						}
187
 					}
166
 					}
167
+				} else {
168
+					// Built-In Frames
169
+					if (isFinished()) {
170
+						idleIndex = (idleIndex < (idleCount - 1)) ? (idleIndex + 1) : 0;
171
+						executeAnimation(idleIndex);
172
+					}
188
 				}
173
 				}
189
 			}
174
 			}
190
-		}
175
+		} else {
176
+			// An audiomode is selected
191
 
177
 
192
-		if (serialHasChar()) {
193
-			serialHandler((char)(serialGet()));
194
 		}
178
 		}
195
 
179
 
196
 		// Print fps after one second
180
 		// Print fps after one second
197
-		if ((getSystemTime() >= 1000) && ((DebugDone & 1) == 0)) {
181
+		if ((getSystemTime() >= 1000) && (fpsWasSent == 0)) {
198
 			temp = getTriggerCount();
182
 			temp = getTriggerCount();
199
 			serialWriteString(ltoa(temp, buffer, 10));
183
 			serialWriteString(ltoa(temp, buffer, 10));
200
 			serialWriteString(getString(27));
184
 			serialWriteString(getString(27));
201
 			serialWriteString(ltoa((temp / 8), buffer, 10));
185
 			serialWriteString(ltoa((temp / 8), buffer, 10));
202
 			serialWriteString(getString(28));
186
 			serialWriteString(getString(28));
203
-			DebugDone |= 1;
187
+			fpsWasSent = 1;
204
 		}
188
 		}
205
 
189
 
206
-		if ((getSystemTime() - lastChecked) > 150) { // Check button state every 150ms
207
-			audioModeSelected();
208
-			lastChecked = getSystemTime();
209
-		} 
210
 	}
190
 	}
211
 
191
 
212
-	close();
192
+	close(); // This is of course unneccessary. We never reach this point.
213
 	return 0;
193
 	return 0;
214
 }
194
 }
215
 
195
 
196
+void init(void) {
197
+	DDRA = 0xFF; // Latch Data Bus as Output
198
+	DDRD = 0xFC; DDRB = 24; // Mosfets as Output
199
+	DDRC = 0xFC; DDRB |= 6; // Latch Enable as Output
200
+	DDRB &= ~(1 << PB0); // Pushbutton as Input
201
+
202
+	initCube();
203
+	serialInit(25, 8, NONE, 1);
204
+	i2c_init();
205
+	initSystemTimer();
206
+	sei(); // Enable Interrupts
207
+
208
+	setImage(defaultImageCube); // Display something
209
+}
210
+
216
 uint8_t audioModeSelected(void) {
211
 uint8_t audioModeSelected(void) {
217
 	// Pushbutton: PB0, Low active
212
 	// Pushbutton: PB0, Low active
218
 
213
 
250
 		result |= MEMORYWRITEERROR;
245
 		result |= MEMORYWRITEERROR;
251
 	}
246
 	}
252
 
247
 
253
-	return result;
254
-}
255
-
256
-void printErrors(uint8_t e) {
257
-	if (ISERROR(e, AUDIOERROR)) {
258
-		serialWriteString(getString(3));
259
-	}
260
-	if (ISERROR(e, MEMORYERROR)) {
261
-		serialWriteString(getString(4));
262
-	}
263
-	if (ISERROR(e, MEMORYWRITEERROR)) {
264
-		serialWriteString(getString(5));
248
+	if (result) { // Error in Selftest
249
+		serialWriteString(getString(1));
250
+		serialWriteString(itoa(result, buffer, 2));
251
+		serialWrite('\n');
252
+		if (ISERROR(result, AUDIOERROR)) {
253
+			serialWriteString(getString(3));
254
+		}
255
+		if (ISERROR(result, MEMORYERROR)) {
256
+			serialWriteString(getString(4));
257
+		}
258
+		if (ISERROR(result, MEMORYWRITEERROR)) {
259
+			serialWriteString(getString(5));
260
+		}
265
 	}
261
 	}
262
+
263
+	return result;
266
 }
264
 }
267
 
265
 
268
 void randomAnimation(void) {
266
 void randomAnimation(void) {
276
 		b[x] = 0;
274
 		b[x] = 0;
277
 	}
275
 	}
278
 	while(1) {
276
 	while(1) {
277
+		wdt_reset();
279
 		setImage(b);
278
 		setImage(b);
280
 		while(isFinished() == 0);
279
 		while(isFinished() == 0);
281
 		x = rand() / 4096;
280
 		x = rand() / 4096;
286
 		if (serialHasChar()) {
285
 		if (serialHasChar()) {
287
 			serialWriteString(getString(25));
286
 			serialWriteString(getString(25));
288
 			free(b);
287
 			free(b);
289
-			serialHandler(serialGet());
288
+			serialGet();
290
 			return;
289
 			return;
291
 		}
290
 		}
292
 	}
291
 	}
316
 		break;
315
 		break;
317
 
316
 
318
 	case 'd': case 'D':
317
 	case 'd': case 'D':
319
-		clearMem();
318
+		// clearMem(); // Much too invasive
319
+		setAnimationCount(0);
320
 		serialWrite(OK);
320
 		serialWrite(OK);
321
+		refreshAnimationCount = 1;
321
 		break;
322
 		break;
322
 
323
 
323
 	case 'g': case 'G':
324
 	case 'g': case 'G':
379
 		break;
380
 		break;
380
 
381
 
381
 	case 'e': case 'E':
382
 	case 'e': case 'E':
382
-		c = selfTest();
383
-		serialWriteString(getString(19));
384
-		serialWriteString(itoa(c, buffer, 2));
385
-		serialWrite('\n');
386
-		printErrors(c);
383
+		selfTest();
387
 		break;
384
 		break;
388
 
385
 
389
 	case 'n': case 'N':
386
 	case 'n': case 'N':
392
 
389
 
393
 	case '0':
390
 	case '0':
394
 		fillBuffer(0);
391
 		fillBuffer(0);
395
-		DebugDone |= 4;
392
+		disableAnim = 1;
396
 		break;
393
 		break;
397
 
394
 
398
 	case '1':
395
 	case '1':
399
 		fillBuffer(0xFF);
396
 		fillBuffer(0xFF);
400
-		DebugDone |= 4;
397
+		disableAnim = 1;
401
 		break;
398
 		break;
402
 
399
 
403
 	case '3':
400
 	case '3':
404
 		setImage(defaultImageCube);
401
 		setImage(defaultImageCube);
405
-		DebugDone |= 4;
402
+		disableAnim = 1;
406
 		break;
403
 		break;
407
 
404
 
408
 	case '2':
405
 	case '2':
409
-		DebugDone |= 4;
410
 		fillBuffer(0);
406
 		fillBuffer(0);
411
-		for (i = 0; i < 64; i++) {
412
-			defaultImageA[i] = 0;
413
-		}
414
 		while(1) {
407
 		while(1) {
415
 			for (i = 0; i < 8; i++) {
408
 			for (i = 0; i < 8; i++) {
416
 				for (y = 0; y < 8; y++) {
409
 				for (y = 0; y < 8; y++) {
417
-					defaultImageA[y + (i * 8)] = 0;
410
+					defaultImageCube[y + (i * 8)] = 0;
418
 					for (z = 0; z < 8; z++) {
411
 					for (z = 0; z < 8; z++) {
419
-						defaultImageA[y + (i * 8)] |= (1 << z);
420
-						setImage(defaultImageA);
412
+						defaultImageCube[y + (i * 8)] |= (1 << z);
413
+						setImage(defaultImageCube);
421
 						while (isFinished() == 0) {
414
 						while (isFinished() == 0) {
422
 							wdt_reset();
415
 							wdt_reset();
423
 							if (serialHasChar()) {
416
 							if (serialHasChar()) {
426
 							}
419
 							}
427
 						}
420
 						}
428
 					}
421
 					}
429
-					defaultImageA[y + (i * 8)] = 0;
422
+					// defaultImageCube[y + (i * 8)] = 0;
430
 				}
423
 				}
431
 			}
424
 			}
432
 		}
425
 		}
433
 		break;
426
 		break;
434
 killMeForIt:
427
 killMeForIt:
435
-		serialGet();
428
+		serialGet(); // Killed because we got a serial char. Remove it from buffer.
436
 		serialWriteString(getString(25));
429
 		serialWriteString(getString(25));
437
 		break;
430
 		break;
438
 
431
 
447
 	}
440
 	}
448
 	// c was used as temp var and does not contain the char anymore...!
441
 	// c was used as temp var and does not contain the char anymore...!
449
 }
442
 }
450
-
451
-void printTime(void) {
452
-	serialWriteString(getString(14));
453
-	serialWriteString(ltoa(getSystemTime(), buffer, 10));
454
-	serialWriteString("ms");
455
-	if (getSystemTime() > 60000) {
456
-		serialWriteString(" (");
457
-		serialWriteString(itoa(getSystemTime() / 60000, buffer, 10));
458
-		serialWriteString(" min)");
459
-	}
460
-	if (getSystemTime() > 1000) {
461
-		serialWriteString(" (");
462
-		serialWriteString(itoa(getSystemTime() / 1000, buffer, 10));
463
-		itoa(getSystemTime() % 1000, buffer, 10);
464
-		if (buffer[0] != '\0')
465
-			serialWrite('.');
466
-		if (buffer[2] == '\0') 
467
-			serialWrite('0');
468
-		if (buffer[1] == '\0')
469
-			serialWrite('0');
470
-		if (buffer[0] != '\0')
471
-			serialWriteString(buffer);
472
-		serialWriteString("s)\n");
473
-	} else {
474
-		serialWrite('\n');
475
-	}
476
-}

+ 1212
- 1233
CubeFirmware/main.hex
File diff suppressed because it is too large
View File


+ 51
- 0
CubeFirmware/transmit.c View File

51
 	while (!serialHasChar()) { // Wait for answer
51
 	while (!serialHasChar()) { // Wait for answer
52
 		if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
52
 		if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
53
 			wdt_reset();
53
 			wdt_reset();
54
+		} else {
55
+			setAnimationCount(0);
56
+			return;
54
 		}
57
 		}
55
 	}
58
 	}
56
 	c = serialGet();
59
 	c = serialGet();
61
 		while (!serialHasChar()) { // Wait for answer
64
 		while (!serialHasChar()) { // Wait for answer
62
 			if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
65
 			if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
63
 				wdt_reset();
66
 				wdt_reset();
67
+			} else {
68
+				setAnimationCount(0);
69
+				return;
64
 			}
70
 			}
65
 		}
71
 		}
66
 		c = serialGet();
72
 		c = serialGet();
71
 			while (!serialHasChar()) { // Wait for answer
77
 			while (!serialHasChar()) { // Wait for answer
72
 				if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
78
 				if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
73
 					wdt_reset();
79
 					wdt_reset();
80
+				} else {
81
+					setAnimationCount(0);
82
+					return;
74
 				}
83
 				}
75
 			}
84
 			}
76
 			c = serialGet();
85
 			c = serialGet();
81
 				while (!serialHasChar()) { // Wait for answer
90
 				while (!serialHasChar()) { // Wait for answer
82
 					if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
91
 					if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
83
 						wdt_reset();
92
 						wdt_reset();
93
+					} else {
94
+						setAnimationCount(0);
95
+						return;
84
 					}
96
 					}
85
 				}
97
 				}
86
 				c = serialGet();
98
 				c = serialGet();
96
 	while (!serialHasChar()) { // Wait for answer
108
 	while (!serialHasChar()) { // Wait for answer
97
 		if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
109
 		if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
98
 			wdt_reset();
110
 			wdt_reset();
111
+		} else {
112
+			setAnimationCount(0);
113
+			return;
99
 		}
114
 		}
100
 	}
115
 	}
101
 	c = serialGet();
116
 	c = serialGet();
102
 	while (!serialHasChar()) { // Wait for answer
117
 	while (!serialHasChar()) { // Wait for answer
103
 		if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
118
 		if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
104
 			wdt_reset();
119
 			wdt_reset();
120
+		} else {
121
+			setAnimationCount(0);
122
+			return;
105
 		}
123
 		}
106
 	}
124
 	}
107
 	c = serialGet();
125
 	c = serialGet();
108
 	while (!serialHasChar()) { // Wait for answer
126
 	while (!serialHasChar()) { // Wait for answer
109
 		if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
127
 		if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
110
 			wdt_reset();
128
 			wdt_reset();
129
+		} else {
130
+			setAnimationCount(0);
131
+			return;
111
 		}
132
 		}
112
 	}
133
 	}
113
 	c = serialGet();
134
 	c = serialGet();
114
 	while (!serialHasChar()) { // Wait for answer
135
 	while (!serialHasChar()) { // Wait for answer
115
 		if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
136
 		if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
116
 			wdt_reset();
137
 			wdt_reset();
138
+		} else {
139
+			setAnimationCount(0);
140
+			return;
117
 		}
141
 		}
118
 	}
142
 	}
119
 	c = serialGet();
143
 	c = serialGet();
210
 			serialWrite('\n');
234
 			serialWrite('\n');
211
 		}
235
 		}
212
 	}
236
 	}
237
+}
238
+
239
+void printTime(void) {
240
+	serialWriteString(getString(14));
241
+	serialWriteString(ltoa(getSystemTime(), buffer, 10));
242
+	serialWriteString("ms");
243
+	if (getSystemTime() > 60000) {
244
+		serialWriteString(" (");
245
+		serialWriteString(itoa(getSystemTime() / 60000, buffer, 10));
246
+		serialWriteString(" min)");
247
+	}
248
+	if (getSystemTime() > 1000) {
249
+		serialWriteString(" (");
250
+		serialWriteString(itoa(getSystemTime() / 1000, buffer, 10));
251
+		itoa(getSystemTime() % 1000, buffer, 10);
252
+		if (buffer[0] != '\0')
253
+			serialWrite('.');
254
+		if (buffer[2] == '\0') 
255
+			serialWrite('0');
256
+		if (buffer[1] == '\0')
257
+			serialWrite('0');
258
+		if (buffer[0] != '\0')
259
+			serialWriteString(buffer);
260
+		serialWriteString("s)\n");
261
+	} else {
262
+		serialWrite('\n');
263
+	}
213
 }
264
 }

+ 3
- 3
UploadTest/main.c View File

69
 
69
 
70
 	readAck();
70
 	readAck();
71
 
71
 
72
-	printf("\tSending anim count (1)...");
72
+	printf("\tSending anim count (%d)...", animationCount);
73
 	c = (char)animationCount;
73
 	c = (char)animationCount;
74
 	if (serialWriteTry(&c, 1) != 0) {
74
 	if (serialWriteTry(&c, 1) != 0) {
75
 		printf(" Could not send it!\n");
75
 		printf(" Could not send it!\n");
79
 
79
 
80
 	readAck();
80
 	readAck();
81
 
81
 
82
-	printf("\tSending frame count (2)...");
82
+	printf("\tSending frame count (%d)...", frameCount);
83
 	c = (char)frameCount;
83
 	c = (char)frameCount;
84
 	if (serialWriteTry(&c, 1) != 0) {
84
 	if (serialWriteTry(&c, 1) != 0) {
85
 		printf(" Could not send it!\n");
85
 		printf(" Could not send it!\n");
90
 	readAck();
90
 	readAck();
91
 
91
 
92
 	for (f = 0; f < frameCount; f++) {
92
 	for (f = 0; f < frameCount; f++) {
93
-		printf("\tSending duration (3)...");
93
+		printf("\tSending duration (%d)...", duration);
94
 		c = (char)duration;
94
 		c = (char)duration;
95
 		if (serialWriteTry(&c, 1) != 0) {
95
 		if (serialWriteTry(&c, 1) != 0) {
96
 			printf(" Could not send it!\n");
96
 			printf(" Could not send it!\n");

Loading…
Cancel
Save