Browse Source

Strings now in program memory.

Thomas Buck 12 years ago
parent
commit
bc2a3143f3
6 changed files with 175 additions and 33 deletions
  1. 51
    31
      CubeFirmware/main.c
  2. 1
    0
      CubeFirmware/makefile
  3. 23
    1
      CubeFirmware/snake.c
  4. 75
    0
      CubeFirmware/strings.c
  5. 24
    0
      CubeFirmware/strings.h
  6. 1
    1
      CubeFirmware/time.h

+ 51
- 31
CubeFirmware/main.c View File

@@ -28,12 +28,6 @@
28 28
 #define OK 0x42
29 29
 #define ERROR 0x23
30 30
 
31
-#ifdef DEBUG
32
-#define VERSION "v2 (Debug Build)\nNOT COMPATIBLE WITH CubeControl!\n"
33
-#else
34
-#define VERSION "v2 Release\n"
35
-#endif
36
-
37 31
 #include <avr/io.h>
38 32
 #include <util/delay.h>
39 33
 #include <avr/interrupt.h>
@@ -48,6 +42,7 @@
48 42
 #include "mem.h"
49 43
 #include "memLayer.h"
50 44
 #include "twi.h"
45
+#include "strings.h"
51 46
 
52 47
 #define NOERROR 0
53 48
 // Audio does not answer
@@ -114,7 +109,7 @@ int main(void) {
114 109
 
115 110
 	i = selfTest();
116 111
 	if (i) {
117
-		serialWriteString("Self-Test Error: 0b");
112
+		serialWriteString(getString(1));
118 113
 		serialWriteString(itoa(i, buffer, 2));
119 114
 		serialWrite('\n');
120 115
 		printErrors(i);
@@ -122,8 +117,8 @@ int main(void) {
122 117
 #endif
123 118
 
124 119
 #ifdef DEBUG
125
-	serialWriteString("\n\nInitialized: ");
126
-	serialWriteString(VERSION);
120
+	serialWriteString(getString(2));
121
+	serialWriteString(getString(0));
127 122
 	serialWriteString("Took ");
128 123
 	serialWriteString(itoa(getSystemTime(), buffer, 10));
129 124
 	serialWriteString(" ms!\n");
@@ -214,13 +209,13 @@ uint8_t selfTest(void) {
214 209
 
215 210
 void printErrors(uint8_t e) {
216 211
 	if (ISERROR(e, AUDIOERROR)) {
217
-		serialWriteString(" => No answer from Audio!\n");
212
+		serialWriteString(getString(3));
218 213
 	}
219 214
 	if (ISERROR(e, MEMORYERROR)) {
220
-		serialWriteString(" => No answer from Memory!\n");
215
+		serialWriteString(getString(4));
221 216
 	}
222 217
 	if (ISERROR(e, MEMORYWRITEERROR)) {
223
-		serialWriteString(" => Can't write to Memory!\n");
218
+		serialWriteString(getString(5));
224 219
 	}
225 220
 }
226 221
 #endif
@@ -228,6 +223,7 @@ void printErrors(uint8_t e) {
228 223
 void serialHandler(char c) {
229 224
 	// Used letters:
230 225
 	// a, c, d, g, s, t, v, x
226
+	uint8_t i, y, z;
231 227
 #ifdef DEBUG
232 228
 	serialWrite(c);
233 229
 	serialWriteString(": ");
@@ -239,14 +235,15 @@ void serialHandler(char c) {
239 235
 		break;
240 236
 
241 237
 	case 'h': case 'H': case '?':
242
-		serialWriteString("(d)elete, (g)et anims, (s)et anims, (v)ersion\n");
238
+		serialWriteString(getString(6));
243 239
 #ifdef DEBUG
244
-		serialWriteString("(t)ime, (a)udio, (c)ount, (x)Custom count\n");
245
-		serialWriteString("(y)Set fixed animation count\n");
246
-		serialWriteString("S(e)lf Test\n");
247
-		serialWriteString("Play S(n)ake\n");
248
-		serialWriteString("(0): All LEDs Off\n");
249
-		serialWriteString("(1): All LEDs On\n");
240
+		serialWriteString(getString(7));
241
+		serialWriteString(getString(8));
242
+		serialWriteString(getString(9));
243
+		serialWriteString(getString(10));
244
+		serialWriteString(getString(11));
245
+		serialWriteString(getString(12));
246
+		serialWriteString(getString(13));
250 247
 #endif
251 248
 		break;
252 249
 
@@ -264,12 +261,12 @@ void serialHandler(char c) {
264 261
 		break;
265 262
 
266 263
 	case 'v': case 'V':
267
-		serialWriteString(VERSION);
264
+		serialWriteString(getString(0));
268 265
 		break;
269 266
 
270 267
 #ifdef DEBUG
271 268
 	case 't': case 'T':
272
-		serialWriteString("System Time: ");
269
+		serialWriteString(getString(14));
273 270
 		serialWriteString(ltoa(getSystemTime(), buffer, 10));
274 271
 		serialWriteString("ms");
275 272
 		if (getSystemTime() > 1000) {
@@ -296,27 +293,27 @@ void serialHandler(char c) {
296 293
 
297 294
 	case 'c': case 'C':
298 295
 		serialWriteString(itoa(getAnimationCount(), buffer, 10));
299
-		serialWriteString(" Frames stored\n");
296
+		serialWriteString(getString(15));
300 297
 		break;
301 298
 
302 299
 	case 'x': case 'X':
303 300
 		// Get byte, store as animation count
304
-		serialWriteString("Send a byte... ");
301
+		serialWriteString(getString(16));
305 302
 		while (!serialHasChar());
306 303
 		c = serialGet();
307 304
 		setAnimationCount(c);
308 305
 		serialWriteString(itoa(c, buffer, 10));
309
-		serialWriteString(" written!\n");
306
+		serialWriteString(getString(17));
310 307
 		break;
311 308
 
312 309
 	case 'y': case 'Y':
313 310
 		setAnimationCount(0x2201);
314
-		serialWriteString("Animation count now 8705!\n");
311
+		serialWriteString(getString(18));
315 312
 		break;
316 313
 
317 314
 	case 'e': case 'E':
318 315
 		c = selfTest();
319
-		serialWriteString("Self-Test: 0b");
316
+		serialWriteString(getString(19));
320 317
 		serialWriteString(itoa(c, buffer, 2));
321 318
 		serialWrite('\n');
322 319
 		printErrors(c);
@@ -327,17 +324,40 @@ void serialHandler(char c) {
327 324
 		break;
328 325
 
329 326
 	case '0':
330
-		fillBuffer(0x00);
327
+		fillBuffer(0);
331 328
 		setAnimationCount(0);
332 329
 		refreshAnimationCount = 1;
333
-		serialWriteString("Killed Animation Counter!\n");
330
+		serialWriteString(getString(20));
334 331
 		break;
335 332
 
336 333
 	case '1':
337 334
 		fillBuffer(0xFF);
338 335
 		setAnimationCount(0);
339 336
 		refreshAnimationCount = 1;
340
-		serialWriteString("Killed Animation Counter!\n");
337
+		serialWriteString(getString(20));
338
+		break;
339
+
340
+	case '2':
341
+		fillBuffer(0);
342
+		for (i = 0; i < 64; i++) {
343
+			defaultImage[i] = 0;
344
+		}
345
+		while(1) {
346
+			for (i = 0; i < 8; i++) {
347
+				for (y = 0; y < 8; y++) {
348
+					defaultImage[y + (i * 8)] = 0;
349
+					for (z = 0; z < 8; z++) {
350
+						defaultImage[y + (i * 8)] |= (1 << z);
351
+						setImage(defaultImage);
352
+						while (isFinished() == 0);
353
+					}
354
+					defaultImage[y + (i * 8)] = 0;
355
+				}
356
+			}
357
+			if (serialHasChar()) {
358
+				break;
359
+			}
360
+		}
341 361
 		break;
342 362
 #endif
343 363
 
@@ -353,9 +373,9 @@ void sendAudioData(void) {
353 373
 	uint8_t i;
354 374
 	uint8_t *audioData = getAudioData();
355 375
 	if (audioData == NULL) {
356
-		serialWriteString("Could not access device!\n");
376
+		serialWriteString(getString(21));
357 377
 	} else {
358
-		serialWriteString("Audio Data:\n");
378
+		serialWriteString(getString(22));
359 379
 		for (i = 0; i < 7; i++) {
360 380
 			serialWrite(i + '0');
361 381
 			serialWriteString(": ");

+ 1
- 0
CubeFirmware/makefile View File

@@ -44,6 +44,7 @@ SRC += mem.c
44 44
 SRC += audio.c
45 45
 SRC += time.c
46 46
 SRC += memLayer.c
47
+SRC += strings.c
47 48
 
48 49
 # List Assembler source files here.
49 50
 # Make them always end in a capital .S.  Files ending in a lowercase .s

+ 23
- 1
CubeFirmware/snake.c View File

@@ -1,3 +1,25 @@
1
+/*
2
+ * snake.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
+ */
1 23
 #define UP 1
2 24
 #define DOWN 2
3 25
 #define LEFT 3
@@ -136,7 +158,7 @@ void snake() {
136 158
 	}
137 159
 	setPixel(3, 3, 3, snake);
138 160
 
139
-	serialWriteString("Controls: W A S D Q E, x to quit\n");
161
+	serialWriteString(getString(23));
140 162
 
141 163
 	while(1) {
142 164
 		if (serialHasChar()) {

+ 75
- 0
CubeFirmware/strings.c View File

@@ -0,0 +1,75 @@
1
+/*
2
+ * strings.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 <avr/pgmspace.h>
24
+
25
+char buffer[60];
26
+
27
+#ifdef DEBUG
28
+char stringVersion[] PROGMEM = "v2 (Debug Build)\nNOT COMPATIBLE WITH CubeControl!\n"; // 0
29
+#else
30
+char stringVersion[] PROGMEM = "v2 Release\n" // 0
31
+#endif
32
+
33
+char stringInit[] PROGMEM = "\n\nInitialized: "; // 1
34
+char stringSelfTestError[] PROGMEM = "Self-Test Error: 0b"; // 2
35
+char stringAudioError[] PROGMEM = " => No answer from Audio!\n"; // 3
36
+char stringMemError[] PROGMEM = " => No answer from Memory!\n"; // 4
37
+char stringMemWriteError[] PROGMEM = " => Can't write to Memory!\n"; // 5
38
+char stringHelp1[] PROGMEM = "(d)elete, (g)et anims, (s)et anims, (v)ersion\n"; // 6
39
+char stringHelp2[] PROGMEM = "(t)ime, (a)udio, (c)ount, (x)Custom count\n"; // 7
40
+char stringHelp3[] PROGMEM = "(y)Set fixed animation count\n"; // 8
41
+char stringHelp4[] PROGMEM = "S(e)lf Test\n"; // 9
42
+char stringHelp5[] PROGMEM = "Play S(n)ake\n"; // 10
43
+char stringHelp6[] PROGMEM = "(0): All LEDs Off\n"; // 11
44
+char stringHelp7[] PROGMEM = "(1): All LEDs On\n"; // 12
45
+char stringHelp8[] PROGMEM = "(2): Test Anim. 1\n"; // 13
46
+char stringTime[] PROGMEM = "System Time: "; // 14
47
+char stringFrames[] PROGMEM = " Frames stored\n"; // 15
48
+char stringByte[] PROGMEM = "Send a byte... "; // 16
49
+char stringWritten[] PROGMEM = " written!\n"; // 17
50
+char stringCount[] PROGMEM = "Animation count now 8705!\n"; // 18
51
+char stringSelfTest[] PROGMEM = "Self-Test: 0b"; // 19
52
+char stringKillCount[] PROGMEM = "Killed Animation Counter!\n"; // 20
53
+char stringAccessError[] PROGMEM = "Could not access device!\n"; // 21
54
+char stringAudioData[] PROGMEM = "Audio Data:\n"; // 22
55
+char stringSnakeControl[] PROGMEM = "Controls: W A S D Q E, x to quit\n"; // 23
56
+
57
+#define STRINGNUM 24
58
+
59
+PGM_P stringTable[STRINGNUM] PROGMEM = { stringVersion, stringSelfTestError, stringInit,
60
+								stringAudioError, stringMemError, stringMemWriteError,
61
+								stringHelp1, stringHelp2, stringHelp3, stringHelp4, stringHelp5,
62
+								stringHelp6, stringHelp7, stringHelp8, stringTime, stringFrames,
63
+								stringByte, stringWritten, stringCount, stringSelfTest,
64
+								stringKillCount, stringAccessError, stringAudioData, stringSnakeControl };
65
+
66
+char stringNotFoundError[] PROGMEM = "String not found!\n";
67
+
68
+char *getString(uint8_t id) {
69
+	if (id < STRINGNUM) {
70
+		strcpy_P(buffer, (PGM_P)pgm_read_word(&(stringTable[id])));
71
+	} else {
72
+		strcpy_P(buffer, (PGM_P)pgm_read_word(&stringNotFoundError));
73
+	}
74
+	return buffer;
75
+}

+ 24
- 0
CubeFirmware/strings.h View File

@@ -0,0 +1,24 @@
1
+/*
2
+ * strings.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
+char *getString(uint8_t id);

+ 1
- 1
CubeFirmware/time.h View File

@@ -1,5 +1,5 @@
1 1
 /*
2
- * time.c
2
+ * time.h
3 3
  *
4 4
  * Copyright 2011 Thomas Buck <xythobuz@me.com>
5 5
  * Copyright 2011 Max Nuding <max.nuding@gmail.com>

Loading…
Cancel
Save