Browse Source

Can now transmit animations

Thomas Buck 12 years ago
parent
commit
d91837dd41
1 changed files with 71 additions and 1 deletions
  1. 71
    1
      CubeFirmware/main.c

+ 71
- 1
CubeFirmware/main.c View File

@@ -213,8 +213,78 @@ void recieveAnimations() {
213 213
 	refreshAnimationCount = 1;
214 214
 }
215 215
 
216
+#define CAF(x) (x % 256)
217
+#define CAS(x) (x / 256)
218
+#define CALCANIMATIONS(x) ((CAF(x) == 0) ? (CAS(x)) : (CAS(x) + 1))
219
+
216 220
 void transmitAnimations() {
217
-	uart_putc(ERROR);
221
+	// We store no animation information in here
222
+	// So we have to place all frames in one or more
223
+	// animations... We need 8 animations max...
224
+	uint8_t animationsToGo;
225
+	uint16_t framesToGo = getAnimationCount();
226
+	uint16_t character;
227
+	uint8_t a;
228
+	uint8_t f, fMax, i;
229
+	uint8_t *frame;
230
+
231
+	if ((framesToGo % 255) == 0) {
232
+		animationsToGo = framesToGo / 255;
233
+	} else {
234
+		animationsToGo = (framesToGo / 255) + 1;
235
+	}
236
+
237
+	uart_putc(OK);
238
+	uart_putc(animationsToGo);
239
+	while ((character = uart_getc()) & 0xFF00); // Wait for answer
240
+	if ((character & 0x00FF) != OK) { // Error code recieved
241
+		return;
242
+	}
243
+
244
+	for (a = 0; a < animationsToGo; a++) {
245
+		if (framesToGo > 255) {
246
+			fMax = 255;
247
+		} else {
248
+			fMax = framesToGo;
249
+		}
250
+
251
+		uart_putc(fMax); // Number of Frames in current animation
252
+		while ((character = uart_getc()) & 0xFF00); // Wait for answer
253
+		if ((character & 0x00FF) != OK) { // Error code recieved
254
+			return;
255
+		}
256
+
257
+		for (f = 0; f < fMax; f++) {
258
+			frame = getFrame(f + (255 * a));
259
+
260
+			uart_putc(frame[64]); // frame duration
261
+			while ((character = uart_getc()) & 0xFF00); // Wait for answer
262
+			if ((character & 0x00FF) != OK) { // Error code recieved
263
+				free(frame);
264
+				return;
265
+			}
266
+
267
+			for (i = 0; i < 64; i++) {
268
+				uart_putc(frame[i]);
269
+			}
270
+			while ((character = uart_getc()) & 0xFF00); // Wait for answer
271
+			if ((character & 0x00FF) != OK) { // Error code recieved
272
+				free(frame);
273
+				return;
274
+			}
275
+
276
+			free(frame);
277
+		}
278
+		framesToGo -= fMax;
279
+	}
280
+
281
+	uart_putc(OK);
282
+	uart_putc(OK);
283
+	uart_putc(OK);
284
+	uart_putc(OK);
285
+
286
+	while ((character = uart_getc()) & 0xFF00); // Wait for answer
287
+	// Error code ignored...
218 288
 }
219 289
 
220 290
 // Blocks 10ms or more

Loading…
Cancel
Save