Browse Source

Cube can receive animations

Thomas Buck 12 years ago
parent
commit
9b0ab03d68
6 changed files with 222 additions and 6 deletions
  1. 1
    1
      CubeControl/cubeWorker.java
  2. 129
    3
      CubeFirmware/main.c
  3. 1
    1
      CubeFirmware/makefile
  4. 2
    1
      CubeFirmware/mem.h
  5. 55
    0
      CubeFirmware/memLayer.c
  6. 34
    0
      CubeFirmware/memLayer.h

+ 1
- 1
CubeControl/cubeWorker.java View File

@@ -411,7 +411,7 @@ public class cubeWorker {
411 411
 		for (int i = 0; i < animations.size(); i++) {
412 412
 			size += animations.get(i).size();
413 413
 		}
414
-		if (size > 2016) {
414
+		if (size > framesRemaining) {
415 415
 			return -1;
416 416
 		}
417 417
 		return 0;

+ 129
- 3
CubeFirmware/main.c View File

@@ -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

+ 1
- 1
CubeFirmware/makefile View File

@@ -42,6 +42,7 @@ SRC += twi.c
42 42
 SRC += mem.c
43 43
 SRC += audio.c
44 44
 SRC += time.c
45
+SRC += memLayer.c
45 46
 
46 47
 # List Assembler source files here.
47 48
 # Make them always end in a capital .S.  Files ending in a lowercase .s
@@ -63,7 +64,6 @@ OPT = s
63 64
 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
64 65
 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
65 66
 #DEBUG = stabs
66
-DEBUG = dwarf-2
67 67
 
68 68
 # List any extra directories to look for include files here.
69 69
 #     Each directory must be seperated by a space.

+ 2
- 1
CubeFirmware/mem.h View File

@@ -22,6 +22,7 @@
22 22
  */
23 23
 
24 24
 #define MEMTWIADDRESS 0xA0
25
+#define MemLength 131072
25 26
 
26 27
 // address is a number between (inclusive) zero and 131071
27 28
 uint8_t memGetByte(uint32_t address);
@@ -31,4 +32,4 @@ uint8_t *memGetBytes(uint32_t address, uint8_t length);
31 32
 
32 33
 void memWriteByte(uint32_t address, uint8_t data);
33 34
 
34
-void memWriteBytes(uint32_t address, uint8_t *data, uint8_t length);
35
+void memWriteBytes(uint32_t address, uint8_t *data, uint8_t length);

+ 55
- 0
CubeFirmware/memLayer.c View File

@@ -0,0 +1,55 @@
1
+/*
2
+ * memLayer.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
+ #include <stdint.h>
24
+ #include <avr/io.h>
25
+ #include <stdlib.h>
26
+ #include "mem.h"
27
+ #include "memLayer.h"
28
+
29
+// Free after usage!
30
+uint8_t *getFrame(uint16_t frameNumber) {
31
+	return memGetBytes(32 + (65 * frameNumber), 65);
32
+}
33
+
34
+// 65 bytes framedata, data and duration...
35
+void setFrame(uint16_t frameNumber, uint8_t *frameData) {
36
+	memWriteBytes(32 + (65 * frameNumber), frameData, 65);
37
+}
38
+
39
+void clearMem() {
40
+	uint32_t i;
41
+	for (i = 0; i < MemLength; i++) {
42
+		memWriteByte(i, 0);
43
+	}
44
+}
45
+
46
+uint16_t getAnimationCount() {
47
+	uint16_t animationCount = memGetByte(0);
48
+	animationCount |= (memGetByte(1) << 8);
49
+	return animationCount;
50
+}
51
+
52
+void setAnimationCount(uint16_t c) {
53
+	memWriteByte(0, (uint8_t)(c & 0x00FF));
54
+	memWriteByte(0, (uint8_t)((c & 0xFF00) >> 8));
55
+}

+ 34
- 0
CubeFirmware/memLayer.h View File

@@ -0,0 +1,34 @@
1
+/*
2
+ * memLayer.h
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
+// Free after usage!
25
+uint8_t *getFrame(uint16_t frameNumber);
26
+
27
+// 65 bytes framedata, data and duration...
28
+void setFrame(uint16_t frameNumber, uint8_t *frameData);
29
+
30
+void clearMem(void);
31
+
32
+uint16_t getAnimationCount(void);
33
+
34
+void setAnimationCount(uint16_t c);

Loading…
Cancel
Save