Browse Source

Uploading animations with up to 4 frames works.

Larger animations get everything but the last 4 frames corrupted.
Thomas Buck 12 years ago
parent
commit
04d9bbf0d3

+ 9
- 56
CubeFirmware/animations.c View File

@@ -42,8 +42,6 @@ D)	Implement your animation!
42 42
 // Prototypes for all animations
43 43
 void upWave(uint8_t i);
44 44
 void downWave(uint8_t i);
45
-void xWave1(uint8_t i);
46
-void xWave2(uint8_t i);
47 45
 void zWave1(uint8_t i);
48 46
 void zWave2(uint8_t i);
49 47
 
@@ -51,30 +49,26 @@ void zWave2(uint8_t i);
51 49
 #define NUMOFANIMATIONS 0
52 50
 uint8_t (*animations[NUMOFANIMATIONS])(void) = { };
53 51
 
54
-#define WAVELENGTH 2
52
+#define WAVELENGTH 1
55 53
 
56 54
 uint8_t numOfAnimations(void) {
57
-	return NUMOFANIMATIONS + 24;
55
+	return NUMOFANIMATIONS + (4*4);
58 56
 }
59 57
 
60 58
 uint8_t executeAnimation(uint8_t id) {
61
-	if (id < (6*4)) {
59
+	if (id < (4*4)) {
62 60
 		if (id < 4) {
63
-			upWave(id);
61
+			zWave1(id);
64 62
 		} else if (id < 8) {
65
-			downWave(id - 4);
63
+			zWave2(id - 4);
66 64
 		} else if (id < 12) {
67
-			xWave1(id - 8);
65
+			upWave(id - 8);
68 66
 		} else if (id < 16) {
69
-			xWave2(id - 12);
70
-		} else if (id < 20) {
71
-			zWave1(id - 16);
72
-		} else {
73
-			zWave2(id - 20);
67
+			downWave(id - 12);
74 68
 		}
75 69
 		return 1;
76
-	} else if ((id - (6*4)) < NUMOFANIMATIONS) {
77
-		return animations[id - (6*4)](); // Call animation
70
+	} else if ((id - (4*4)) < NUMOFANIMATIONS) {
71
+		return animations[id - (4*4)](); // Call animation
78 72
 	}
79 73
 	return 1;
80 74
 }
@@ -121,47 +115,6 @@ void downWave(uint8_t i) {
121 115
 	free(buff);
122 116
 }
123 117
 
124
-void xWave1(uint8_t i) {
125
-	uint8_t *buff;
126
-	int8_t x, y, z;
127
-
128
-	buff = buffNew();
129
-	// x-axis wave
130
-	for(x = (i * 2); x < ((i * 2) + 2); x++) {
131
-		for(y = 0; y < 8; y++) {
132
-			for(z = 0; z < 8; z++) {
133
-				buffSetPixel(buff, x, y, z);
134
-			}
135
-		}
136
-		setImage(buff);
137
-		while(isFinished() < WAVELENGTH) {
138
-			wdt_reset();
139
-		}
140
-		buffClearAllPixels(buff);
141
-	}
142
-	free(buff);
143
-}
144
-
145
-void xWave2(uint8_t i) {
146
-	uint8_t *buff;
147
-	int8_t x, y, z;
148
-
149
-	buff = buffNew();
150
-	for(x = (7 - (2 * i)); x >= ((7 - (2 * i)) - 1); x--) {
151
-		for(y = 0; y < 8; y++) {
152
-			for(z = 0; z < 8; z++) {
153
-				buffSetPixel(buff, x, y, z);
154
-			}
155
-		}
156
-		setImage(buff);
157
-		while(isFinished() < WAVELENGTH) {
158
-			wdt_reset();
159
-		}
160
-		buffClearAllPixels(buff);
161
-	}
162
-	free(buff);
163
-}
164
-
165 118
 void zWave1(uint8_t i) {
166 119
 	uint8_t *buff;
167 120
 	int8_t x, y, z;

+ 67
- 83
CubeFirmware/cube.c View File

@@ -25,6 +25,7 @@
25 25
 #include <avr/interrupt.h>
26 26
 #include <stdlib.h>
27 27
 #include <util/atomic.h>
28
+#include <avr/pgmspace.h>
28 29
 
29 30
 #include "cube.h"
30 31
 
@@ -55,41 +56,77 @@ volatile uint8_t imgFlag = 0;
55 56
 volatile uint8_t layer = 0;
56 57
 volatile uint8_t toggleFlag = 0;
57 58
 
58
-inline void isrCall(void);
59
-
60 59
 volatile uint32_t timesTriggered = 0;
61 60
 volatile uint8_t warningDisplayed = 0;
62 61
 
63
-uint8_t lookUp[] = { 	0,  64,  128,  192,  16,  80,  144,  208,  32,  96,  160,
64
-					224,  48,  112,  176,  240,  4,  68,  132,  196,  20,
65
-					84,  148,  212,  36,  100,  164,  228,  52,  116,  180,
66
-					244,  8,  72,  136,  200,  24,  88,  152,  216,  40,
67
-					104,  168,  232,  56,  120,  184,  248,  12,  76,  140,
68
-					204,  28,  92,  156,  220,  44,  108,  172,  236,  60,
69
-					124,  188,  252,  1,  65,  129,  193,  17,  81,  145,
70
-					209,  33,  97,  161,  225,  49,  113,  177,  241,  5,
71
-					69,  133,  197,  21,  85,  149,  213,  37,  101,  165,
72
-					229,  53,  117,  181,  245,  9,  73,  137,  201,  25,
73
-					89,  153,  217,  41,  105,  169,  233,  57,  121,  185,
74
-					249,  13,  77,  141,  205,  29,  93,  157,  221,  45,
75
-					109,  173,  237,  61,  125,  189,  253,  2,  66,  130,
76
-					194,  18,  82,  146,  210,  34,  98,  162,  226,  50,
77
-					114,  178,  242,  6,  70,  134,  198,  22,  86,  150,
78
-					214,  38,  102,  166,  230,  54,  118,  182,  246,  10,
79
-					74,  138,  202,  26,  90,  154,  218,  42,  106,  170,
80
-					234,  58,  122,  186,  250,  14,  78,  142,  206,  30,
81
-					94,  158,  222,  46,  110,  174,  238,  62,  126,  190,
82
-					254,  3,  67,  131,  195,  19,  83,  147,  211,  35,
83
-					99,  163,  227,  51,  115,  179,  243,  7,  71,  135,
84
-					199,  23,  87,  151,  215,  39,  103,  167,  231,  55,
85
-					119,  183,  247,  11,  75,  139,  203,  27,  91,  155,
86
-					219,  43,  107,  171,  235,  59,  123,  187,  251,  15,
87
-					79,  143,  207,  31,  95,  159,  223,  47,  111,  175,
88
-					239,  63,  127,  191,  255 };
62
+// A fix for our mirrored 64pin cable.
63
+uint8_t lookUp[256] PROGMEM = { 	0,  64,  128,  192,  16,  80,  144,  208,  32,  96,  160,
64
+									224,  48,  112,  176,  240,  4,  68,  132,  196,  20,
65
+									84,  148,  212,  36,  100,  164,  228,  52,  116,  180,
66
+									244,  8,  72,  136,  200,  24,  88,  152,  216,  40,
67
+									104,  168,  232,  56,  120,  184,  248,  12,  76,  140,
68
+									204,  28,  92,  156,  220,  44,  108,  172,  236,  60,
69
+									124,  188,  252,  1,  65,  129,  193,  17,  81,  145,
70
+									209,  33,  97,  161,  225,  49,  113,  177,  241,  5,
71
+									69,  133,  197,  21,  85,  149,  213,  37,  101,  165,
72
+									229,  53,  117,  181,  245,  9,  73,  137,  201,  25,
73
+									89,  153,  217,  41,  105,  169,  233,  57,  121,  185,
74
+									249,  13,  77,  141,  205,  29,  93,  157,  221,  45,
75
+									109,  173,  237,  61,  125,  189,  253,  2,  66,  130,
76
+									194,  18,  82,  146,  210,  34,  98,  162,  226,  50,
77
+									114,  178,  242,  6,  70,  134,  198,  22,  86,  150,
78
+									214,  38,  102,  166,  230,  54,  118,  182,  246,  10,
79
+									74,  138,  202,  26,  90,  154,  218,  42,  106,  170,
80
+									234,  58,  122,  186,  250,  14,  78,  142,  206,  30,
81
+									94,  158,  222,  46,  110,  174,  238,  62,  126,  190,
82
+									254,  3,  67,  131,  195,  19,  83,  147,  211,  35,
83
+									99,  163,  227,  51,  115,  179,  243,  7,  71,  135,
84
+									199,  23,  87,  151,  215,  39,  103,  167,  231,  55,
85
+									119,  183,  247,  11,  75,  139,  203,  27,  91,  155,
86
+									219,  43,  107,  171,  235,  59,  123,  187,  251,  15,
87
+									79,  143,  207,  31,  95,  159,  223,  47,  111,  175,
88
+									239,  63,  127,  191,  255 };
89 89
 
90 90
 ISR(TIMER1_COMPA_vect) {
91
+	uint8_t latchCtr;
91 92
 	if (toggleFlag >= COUNT2) {
92
-		isrCall();
93
+
94
+		if (changedFlag != 0) {
95
+			// The picture changed. Restart!
96
+			layer = 0;
97
+			changedFlag = 0;
98
+		}
99
+
100
+		PORTD = 0;
101
+		PORTB &= ~(24); // Disable all Fets
102
+
103
+		for (latchCtr = 0; latchCtr < 8; latchCtr++) {
104
+			// Disable all latches
105
+			PORTC &= ~(0xFC); // 2 - 7
106
+			PORTB &= ~(6); // 0 & 1
107
+
108
+			PORTA = imgBuffer[layer][latchCtr]; // Put latch data
109
+
110
+			// Enable desired latch
111
+			if (latchCtr > 1) {
112
+				PORTC |= (1 << latchCtr);
113
+			} else {
114
+				PORTB |= (1 << (latchCtr + 1));
115
+			}
116
+		}
117
+
118
+		// Set FET
119
+		PORTD = (1 << layer); // PD2 to 7
120
+		PORTB = (PORTB & ~(24)) | (((1 << layer) << 3) & 24); // PB3 & 4
121
+		
122
+		// Select next layer
123
+		if (layer < 7) {
124
+			layer++;
125
+		} else {
126
+			layer = 0;
127
+			imgFlag++; // Finished
128
+		}
129
+
93 130
 		toggleFlag = 0;
94 131
 		timesTriggered++;
95 132
 	} else {
@@ -101,10 +138,6 @@ uint32_t getTriggerCount(void) {
101 138
 	return timesTriggered;
102 139
 }
103 140
 
104
-uint8_t bitSwitch(uint8_t d) {
105
-	return lookUp[d];
106
-}
107
-
108 141
 void setImage(uint8_t *img) {
109 142
 	uint8_t i, j;
110 143
 	ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
@@ -113,7 +146,7 @@ void setImage(uint8_t *img) {
113 146
 		toggleFlag = 0;
114 147
 		for (i = 0; i < 8; i++) {
115 148
 			for (j = 0; j < 8; j++) {
116
-				imgBuffer[j][7 - i] = ~(bitSwitch(img[j + (i * 8)]));
149
+				imgBuffer[j][7 - i] = ~(pgm_read_byte(&(lookUp[img[j + (i * 8)]])));
117 150
 			}
118 151
 		}
119 152
 	}
@@ -170,52 +203,3 @@ void initCube(void) {
170 203
 void close(void) {
171 204
 	TIMSK &= ~(1 << OCIE1A); // Disable interrupt
172 205
 }
173
-
174
-// Data is sent to 8 Fet bits...
175
-inline void setFet(uint8_t data) {
176
-	PORTD = (data & ~(3)); // Doesn't interfere with serial communication...
177
-	PORTB = (PORTB & ~(24)) | ((data << 3) & 24);
178
-}
179
-
180
-// Give id of latch, 0 - 7
181
-inline void selectLatch(uint8_t latchNr) {
182
-	// Disable all latches
183
-	PORTC &= ~(0xFC); // 2 - 7
184
-	PORTB &= ~(6); // 0 & 1
185
-
186
-	// Enable desired latch
187
-	if (latchNr > 1) {
188
-		PORTC |= (1 << latchNr);
189
-	} else {
190
-		PORTB |= (1 << (latchNr + 1));
191
-	}
192
-}
193
-
194
-inline void setLatch(uint8_t latchNr, uint8_t data) {
195
-	selectLatch(latchNr); // Activate current latch
196
-	PORTA = data; // Put latch data
197
-	asm volatile("nop"::); // Wait for latch
198
-}
199
-
200
-inline void isrCall(void) {
201
-	uint8_t latchCtr = 0;
202
-
203
-	if (changedFlag != 0) {
204
-		// The picture changed. Restart!
205
-		layer = 0;
206
-		changedFlag = 0;
207
-	}
208
-	setFet(0);
209
-	for (; latchCtr < 8; latchCtr++) {
210
-		setLatch(latchCtr, imgBuffer[layer][latchCtr]); // Put out all the data
211
-	}
212
-	setFet(1 << layer);
213
-	
214
-	// Select next layer
215
-	if (layer < 7) {
216
-		layer++;
217
-	} else {
218
-		layer = 0;
219
-		imgFlag++; // Finished
220
-	}
221
-}

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

@@ -24,4 +24,5 @@
24 24
 void recieveAnimations(void);
25 25
 void transmitAnimations(void);
26 26
 void sendAudioData(void);
27
-void printTime(void);
27
+void printTime(void);
28
+void dumpFrame(uint8_t *f);

+ 31
- 5
CubeFirmware/main.c View File

@@ -155,7 +155,7 @@ int main(void) {
155 155
 					if (isFinished() > duration) {
156 156
 						// Last frame was displayed long enough
157 157
 						imageIndex = (imageIndex < (imageCount - 1)) ? (imageIndex + 1) : 0;
158
-						imageData = getFrame(i);
158
+						imageData = getFrame(imageIndex);
159 159
 						if (imageData == NULL) {
160 160
 							duration = 24;
161 161
 							setImage(defaultImageCube);
@@ -166,7 +166,7 @@ int main(void) {
166 166
 						}
167 167
 					}
168 168
 				} else {
169
-					// Built-In Frames
169
+					// Built-In Anims
170 170
 					if (isFinished() > duration) {
171 171
 						idleIndex = (idleIndex < (idleCount - 1)) ? (idleIndex + 1) : 0;
172 172
 						duration = executeAnimation(idleIndex);
@@ -307,8 +307,9 @@ void randomAnimation(void) {
307 307
 
308 308
 void serialHandler(char c) {
309 309
 	// Used letters:
310
-	// a, b, c, d, e, g, i, n, q, r, s, t, v, x, y, 0, 1, 2, 3, #
310
+	// a, b, c, d, e, f, g, h, i, n, q, r, s, t, u, v, x, y, 0, 1, 2, 3, #
311 311
 	uint8_t i, y, z;
312
+	uint8_t *tmp;
312 313
 
313 314
 	switch(c) {
314 315
 	case OK:
@@ -321,25 +322,34 @@ void serialHandler(char c) {
321 322
 		serialWriteString(getString(8));
322 323
 		serialWriteString(getString(9));
323 324
 		serialWriteString(getString(10));
325
+		serialWriteString(getString(26));
326
+		serialWriteString(getString(34));
327
+
324 328
 		serialWriteString(getString(11));
325 329
 		serialWriteString(getString(12));
326 330
 		serialWriteString(getString(13));
327
-		serialWriteString(getString(26));
328 331
 		break;
329 332
 
330 333
 	case 'd': case 'D':
331
-		// clearMem(); // Much too invasive
332 334
 		setAnimationCount(0);
333 335
 		serialWrite(OK);
334 336
 		refreshAnimationCount = 1;
335 337
 		break;
336 338
 
339
+	case 'f': case 'F':
340
+		serialWriteString(getString(32));
341
+		clearMem();
342
+		serialWriteString(getString(33));
343
+		refreshAnimationCount = 1;
344
+		break;
345
+
337 346
 	case 'g': case 'G':
338 347
 		transmitAnimations();
339 348
 		break;
340 349
 
341 350
 	case 's': case 'S':
342 351
 		recieveAnimations();
352
+		refreshAnimationCount = 1;
343 353
 		break;
344 354
 
345 355
 	case 'v': case 'V':
@@ -378,9 +388,25 @@ void serialHandler(char c) {
378 388
 
379 389
 	case 'c': case 'C':
380 390
 		serialWriteString(itoa(getAnimationCount(), buffer, 10));
391
+		serialWriteString(" (");
392
+		serialWriteString(itoa(refreshAnimationCount, buffer, 10));
393
+		serialWriteString(")");
381 394
 		serialWriteString(getString(15));
382 395
 		break;
383 396
 
397
+	case 'u': case 'U':
398
+		serialWriteString(getString(31));
399
+		while(!serialHasChar()) {
400
+			wdt_reset();
401
+		}
402
+		i = serialGet() - '0';
403
+		serialWrite(i + '0');
404
+		serialWrite('\n');
405
+		tmp = getFrame(i);
406
+		dumpFrame(tmp);
407
+		free(tmp);
408
+		break;
409
+
384 410
 	case 'x': case 'X':
385 411
 		// Get byte, store as animation count
386 412
 		serialWriteString(getString(16));

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


+ 2
- 0
CubeFirmware/memLayer.c View File

@@ -23,6 +23,7 @@
23 23
  #include <stdint.h>
24 24
  #include <avr/io.h>
25 25
  #include <stdlib.h>
26
+ #include <avr/wdt.h>
26 27
  #include "mem.h"
27 28
  #include "memLayer.h"
28 29
  #include "serial.h"
@@ -47,6 +48,7 @@ void clearMem() {
47 48
 	uint32_t i;
48 49
 	for (i = 0; i < MemLength; i++) {
49 50
 		memWriteByte(i, 0);
51
+		wdt_reset();
50 52
 	}
51 53
 }
52 54
 

+ 6
- 6
CubeFirmware/strings.c View File

@@ -33,7 +33,7 @@ const char stringMemWriteError[] PROGMEM = " => Can't write to Memory!\n"; // 5
33 33
 const char stringHelp1[] PROGMEM = "(d)elete, (g)et anims, (s)et anims, (v)ersion\n"; // 6
34 34
 const char stringHelp2[] PROGMEM = "(t)ime, (a)udio, (c)ount, (x)Custom count\n"; // 7
35 35
 const char stringHelp3[] PROGMEM = "(y)Set fixed animation count\n"; // 8
36
-const char stringHelp4[] PROGMEM = "S(e)lf Test, (m)ode\n"; // 9
36
+const char stringHelp4[] PROGMEM = "S(e)lf Test, (m)ode, d(u)mp\n"; // 9
37 37
 const char stringHelp5[] PROGMEM = "Play S(n)ake\n"; // 10
38 38
 const char stringHelp6[] PROGMEM = "All LEDs Off/On (0/1)\n"; // 11
39 39
 const char stringHelp7[] PROGMEM = "(2): Test Anim. 1\n"; // 12
@@ -55,13 +55,13 @@ const char stringInterrupts[] PROGMEM = " Interrupts after 1000msec\n"; // 27
55 55
 const char stringFrames2[] PROGMEM = " Frames per Second\n"; // 28
56 56
 const char stringDeleted[] PROGMEM = "Memory deleted!\n"; // 29
57 57
 const char stringReset[] PROGMEM = "Reset in 500ms. Bye!\n"; // 30
58
-const char stringWatchdog[] PROGMEM = ""; // 31
59
-const char stringBrownout[] PROGMEM = ""; // 32
60
-const char stringNothing[] PROGMEM = ""; // 33
61
-const char stringExtern[] PROGMEM = ""; // 34
58
+const char stringWatchdog[] PROGMEM = "Enter frame to dump: "; // 31
59
+const char stringBrownout[] PROGMEM = "Formatting memory... "; // 32
60
+const char stringNothing[] PROGMEM = "Done!\n"; // 33
61
+const char stringExtern[] PROGMEM = "(f)ormat memory\n"; // 34
62 62
 const char stringJtag[] PROGMEM = ""; // 35
63 63
 const char stringPowerOn[] PROGMEM = ""; // 36
64
-const char stringMinute[] PROGMEM = "Yay! Another minute passed :)\n"; // 37
64
+const char stringMinute[] PROGMEM = ""; // 37
65 65
 const char stringAudioMode[] PROGMEM = ""; // 38
66 66
 const char stringCubeMode[] PROGMEM = ""; // 39
67 67
 const char stringModeChange[] PROGMEM = "Cube mode entered!\n"; // 40

+ 31
- 79
CubeFirmware/transmit.c View File

@@ -34,22 +34,22 @@
34 34
 #define OK 0x42
35 35
 #define ERROR 0x23
36 36
 
37
-#define TRANSTIMEOUT 2500
37
+#define TIMEOUTPERFRAME 500
38 38
 
39 39
 // These are global variables from main.c
40 40
 extern char buffer[11];
41
-extern uint8_t refreshAnimationCount;
42 41
 
43 42
 void recieveAnimations(void) {
44 43
 	uint8_t animCount, a, frameCount, f, i, c;
45 44
 	uint16_t completeCount = 0;
46 45
 	uint8_t *frame = (uint8_t *)malloc(65);
47 46
 	uint64_t timestamp = getSystemTime();
47
+	uint64_t timeout = TIMEOUTPERFRAME;
48 48
 
49 49
 	serialWrite(OK); // We are ready...
50 50
 
51 51
 	while (!serialHasChar()) { // Wait for answer
52
-		if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
52
+		if ((getSystemTime() - timestamp) <= timeout) {
53 53
 			wdt_reset();
54 54
 		} else {
55 55
 			setAnimationCount(0);
@@ -62,7 +62,7 @@ void recieveAnimations(void) {
62 62
 
63 63
 	for (a = 0; a < animCount; a++) {
64 64
 		while (!serialHasChar()) { // Wait for answer
65
-			if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
65
+			if ((getSystemTime() - timestamp) <= timeout) {
66 66
 				wdt_reset();
67 67
 			} else {
68 68
 				setAnimationCount(0);
@@ -74,8 +74,9 @@ void recieveAnimations(void) {
74 74
 		serialWrite(OK);
75 75
 
76 76
 		for (f = 0; f < frameCount; f++) {
77
+			timeout += TIMEOUTPERFRAME;
77 78
 			while (!serialHasChar()) { // Wait for answer
78
-				if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
79
+				if ((getSystemTime() - timestamp) <= timeout) {
79 80
 					wdt_reset();
80 81
 				} else {
81 82
 					setAnimationCount(0);
@@ -88,7 +89,7 @@ void recieveAnimations(void) {
88 89
 
89 90
 			for (i = 0; i < 64; i++) {
90 91
 				while (!serialHasChar()) { // Wait for answer
91
-					if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
92
+					if ((getSystemTime() - timestamp) <= timeout) {
92 93
 						wdt_reset();
93 94
 					} else {
94 95
 						setAnimationCount(0);
@@ -106,7 +107,7 @@ void recieveAnimations(void) {
106 107
 	free(frame);
107 108
 
108 109
 	while (!serialHasChar()) { // Wait for answer
109
-		if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
110
+		if ((getSystemTime() - timestamp) <= timeout) {
110 111
 			wdt_reset();
111 112
 		} else {
112 113
 			setAnimationCount(0);
@@ -115,7 +116,7 @@ void recieveAnimations(void) {
115 116
 	}
116 117
 	c = serialGet();
117 118
 	while (!serialHasChar()) { // Wait for answer
118
-		if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
119
+		if ((getSystemTime() - timestamp) <= timeout) {
119 120
 			wdt_reset();
120 121
 		} else {
121 122
 			setAnimationCount(0);
@@ -124,7 +125,7 @@ void recieveAnimations(void) {
124 125
 	}
125 126
 	c = serialGet();
126 127
 	while (!serialHasChar()) { // Wait for answer
127
-		if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
128
+		if ((getSystemTime() - timestamp) <= timeout) {
128 129
 			wdt_reset();
129 130
 		} else {
130 131
 			setAnimationCount(0);
@@ -133,7 +134,7 @@ void recieveAnimations(void) {
133 134
 	}
134 135
 	c = serialGet();
135 136
 	while (!serialHasChar()) { // Wait for answer
136
-		if ((getSystemTime() - timestamp) <= TRANSTIMEOUT) {
137
+		if ((getSystemTime() - timestamp) <= timeout) {
137 138
 			wdt_reset();
138 139
 		} else {
139 140
 			setAnimationCount(0);
@@ -145,78 +146,11 @@ void recieveAnimations(void) {
145 146
 	serialWrite(OK);
146 147
 
147 148
 	setAnimationCount(completeCount);
148
-	refreshAnimationCount = 1;
149 149
 }
150 150
 
151 151
 // TODO: Rewrite for new Serial API
152 152
 void transmitAnimations(void) {
153
-	// We store no animation information in here
154
-	// So we have to place all frames in one or more
155
-	// animations... We need 8 animations max...
156
-	uint8_t animationsToGo;
157
-	uint16_t framesToGo = getAnimationCount();
158
-	uint16_t character;
159
-	uint8_t a;
160
-	uint8_t f, fMax, i;
161
-	uint8_t *frame;
162
-
163
-	if ((framesToGo % 255) == 0) {
164
-		animationsToGo = framesToGo / 255;
165
-	} else {
166
-		animationsToGo = (framesToGo / 255) + 1;
167
-	}
168
-
169
-	serialWrite(OK);
170
-	serialWrite(animationsToGo);
171
-	while ((character = serialGet()) & 0xFF00); // Wait for answer
172
-	if ((character & 0x00FF) != OK) { // Error code recieved
173
-		return;
174
-	}
175
-
176
-	for (a = 0; a < animationsToGo; a++) {
177
-		if (framesToGo > 255) {
178
-			fMax = 255;
179
-		} else {
180
-			fMax = framesToGo;
181
-		}
182
-
183
-		serialWrite(fMax); // Number of Frames in current animation
184
-		while ((character = serialGet()) & 0xFF00); // Wait for answer
185
-		if ((character & 0x00FF) != OK) { // Error code recieved
186
-			return;
187
-		}
188
-
189
-		for (f = 0; f < fMax; f++) {
190
-			frame = getFrame(f + (255 * a));
191
-
192
-			serialWrite(frame[64]); // frame duration
193
-			while ((character = serialGet()) & 0xFF00); // Wait for answer
194
-			if ((character & 0x00FF) != OK) { // Error code recieved
195
-				free(frame);
196
-				return;
197
-			}
198
-
199
-			for (i = 0; i < 64; i++) {
200
-				serialWrite(frame[i]);
201
-			}
202
-			while ((character = serialGet()) & 0xFF00); // Wait for answer
203
-			if ((character & 0x00FF) != OK) { // Error code recieved
204
-				free(frame);
205
-				return;
206
-			}
207
-
208
-			free(frame);
209
-		}
210
-		framesToGo -= fMax;
211
-	}
212
-
213
-	serialWrite(OK);
214
-	serialWrite(OK);
215
-	serialWrite(OK);
216
-	serialWrite(OK);
217
-
218
-	while ((character = serialGet()) & 0xFF00); // Wait for answer
219
-	// Error code ignored...
153
+	serialWrite(ERROR);
220 154
 }
221 155
 
222 156
 void sendAudioData(void) {
@@ -261,4 +195,22 @@ void printTime(void) {
261 195
 	} else {
262 196
 		serialWrite('\n');
263 197
 	}
264
-}
198
+}
199
+
200
+void dumpFrame(uint8_t *f) {
201
+	uint8_t zeile, spalte;
202
+	for (zeile = 0; zeile < 8; zeile++) {
203
+		serialWrite(zeile + '0');
204
+		serialWriteString(": ");
205
+		for (spalte = 0; spalte < 8; spalte++) {
206
+			itoa(f[(8 * zeile) + spalte], buffer, 16);
207
+			serialWriteString(buffer);
208
+			serialWrite(' ');
209
+		}
210
+		serialWrite('\n');
211
+	}
212
+	serialWriteString("Duration: ");
213
+	itoa(f[64], buffer, 10);
214
+	serialWriteString(buffer);
215
+	serialWrite('\n');
216
+}

+ 106
- 6
UploadTest/main.c View File

@@ -13,8 +13,10 @@ int serialWriteString(char *s);
13 13
 int serialReadTry(char *data, size_t length);
14 14
 int serialWriteTry(char *data, size_t length);
15 15
 void intHandler(int dummy);
16
+void transferFile(char *file);
16 17
 
17 18
 volatile int keepRunning = 1;
19
+FILE *fp = NULL;
18 20
 
19 21
 #define suicide intHandler(0)
20 22
 
@@ -28,7 +30,7 @@ int main(int argc, char *argv[]) {
28 30
 	char command = -1;
29 31
 
30 32
 	if (argc < 2) {
31
-		printf("Usage:\n%s /dev/port [-d 0xff]\n", argv[0]);
33
+		printf("Usage:\n%s /dev/port [-d 0xff] | [-f /file]\n", argv[0]);
32 34
 		return 0;
33 35
 	}
34 36
 
@@ -37,26 +39,31 @@ int main(int argc, char *argv[]) {
37 39
 		return 0;
38 40
 	}
39 41
 
40
-	if ((argc >= 4) && (strcmp(argv[2], "-d") == 0)) {
42
+	signal(SIGINT, intHandler);
43
+	signal(SIGQUIT, intHandler);
44
+
45
+	if ((argc == 4) && (strcmp(argv[2], "-d") == 0)) {
41 46
 		sscanf(argv[3], "%x", &data);
42 47
 		frameCount = 1;
43 48
 	}
44 49
 
50
+	if ((argc == 4) && (strcmp(argv[2], "-f") == 0)) {
51
+		printf("Trying to send from file.\n");
52
+		transferFile(argv[3]);
53
+	}
54
+
45 55
 	if (argc == 3) {
46 56
 		command = argv[2][0];
47 57
 	}
48 58
 
49
-	signal(SIGINT, intHandler);
50
-	signal(SIGQUIT, intHandler);
51
-
52 59
 	printf("Port opened. Sending test data:\n");
53 60
 
54
-	printf("\tSending command 's'...");
55 61
 	if (command != -1) {
56 62
 		c = command;
57 63
 	} else {
58 64
 		c = 's';
59 65
 	}
66
+	printf("\tSending command '%c'...", c);
60 67
 	if (serialWriteTry(&c, 1) != 0) {
61 68
 		printf(" Could not send it!\n");
62 69
 		suicide;
@@ -146,6 +153,96 @@ int main(int argc, char *argv[]) {
146 153
 	return 0;
147 154
 }
148 155
 
156
+void writeS(char c) {
157
+	if (serialWriteTry(&c, 1) != 0) {
158
+		printf("Error while sending!\n");
159
+		suicide;
160
+	}
161
+}
162
+
163
+int readFrame(char *frame) {
164
+	char lineBuffer[80];
165
+	char buff[3];
166
+	int lines, byte, i = 0, tmp;
167
+	buff[2] = '\0';
168
+
169
+	fgets(lineBuffer, 80, fp);// Frame name, ignore
170
+	for (lines = 0; lines < 8; lines++) {
171
+		fgets(lineBuffer, 80, fp);
172
+		for(byte = 0; byte < 8; byte++) {
173
+			buff[0] = lineBuffer[(2 * byte)];
174
+			buff[1] = lineBuffer[(2 * byte) + 1];
175
+			sscanf(buff, "%x", &tmp);
176
+			frame[i++] = (char)tmp;
177
+		}
178
+	}
179
+
180
+	fgets(lineBuffer, 80, fp);
181
+	if(lineBuffer[strlen(lineBuffer)-1] == '\n') {
182
+		lineBuffer[strlen(lineBuffer)-1] = '\0';
183
+	}
184
+	sscanf(lineBuffer, "%d", &lines);
185
+	return lines;
186
+}
187
+
188
+void transferFile(char *file) {
189
+	char lineBuffer[80];
190
+	int f, i;
191
+	int fMax = 0;
192
+	char frame[64];
193
+	int duration;
194
+
195
+	fp = fopen(file, "r");
196
+	if (fp != NULL) {
197
+		printf("File opened...\n");
198
+		fgets(lineBuffer, 80, fp);
199
+		if (lineBuffer[strlen(lineBuffer)-1] == '\n') {
200
+			lineBuffer[strlen(lineBuffer)-1] = '\0';
201
+		}
202
+		fMax = atoi(lineBuffer);
203
+		printf("Has %d frames.\n", fMax);
204
+		fgets(lineBuffer, 80, fp);
205
+		printf("Sendind command.\n");
206
+		writeS('s');
207
+		readAck();
208
+		printf("Sendind animation count.\n");
209
+		writeS(1); // Animation count
210
+		readAck();
211
+		printf("Sending frame count.\n");
212
+		writeS(fMax); // Frame count
213
+		readAck();
214
+		for (f = 0; f < fMax; f++) {
215
+			printf("Reading frame from file... ");
216
+			duration = readFrame(frame);
217
+			printf("Done!\nSending duration.\n");
218
+			writeS(duration);
219
+			readAck();
220
+			printf("Sending frame (");
221
+			for (i = 0; i < 64; i++) {
222
+				writeS(frame[i]);
223
+				printf("%x", frame[i]);
224
+				if (i < 63) {
225
+					printf(" ");
226
+				}
227
+			}
228
+			printf(") Done!\n");
229
+			readAck();
230
+			printf("Wrote frame %d\n\n", f);
231
+		}
232
+		printf("Sending end sequence!\n");
233
+		writeS(0x42);
234
+		writeS(0x42);
235
+		writeS(0x42);
236
+		writeS(0x42);
237
+		readAck();
238
+	} else {
239
+		printf("File not found\n");
240
+		suicide;
241
+	}
242
+	printf("Success!\n");
243
+	suicide;
244
+}
245
+
149 246
 void readAck() {
150 247
 	char c;
151 248
 	printf("Awaiting acknowledge...");
@@ -218,6 +315,9 @@ int serialWriteTry(char *data, size_t length) {
218 315
 
219 316
 void intHandler(int dummy) {
220 317
 	keepRunning = 0;
318
+	if (fp != NULL) {
319
+		fclose(fp);
320
+	}
221 321
 	serialClose();
222 322
 	exit(0);
223 323
 }

Loading…
Cancel
Save