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

+ 1
- 0
CubeFirmware/makefile View File

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

+ 23
- 1
CubeFirmware/snake.c View File

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
 #define UP 1
23
 #define UP 1
2
 #define DOWN 2
24
 #define DOWN 2
3
 #define LEFT 3
25
 #define LEFT 3
136
 	}
158
 	}
137
 	setPixel(3, 3, 3, snake);
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
 	while(1) {
163
 	while(1) {
142
 		if (serialHasChar()) {
164
 		if (serialHasChar()) {

+ 75
- 0
CubeFirmware/strings.c View File

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

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

Loading…
Cancel
Save