Browse Source

Can render text.

Font is not pretty, but works :)
Thomas Buck 12 years ago
parent
commit
a533318567

+ 10
- 13
CubeFirmware/buffhelp.c View File

25
 #include <serial.h>
25
 #include <serial.h>
26
 #include <strings.h>
26
 #include <strings.h>
27
 
27
 
28
-uint8_t *buffNew(void) {
28
+void buffClearAllPixels(uint8_t *buffer) {
29
 	uint8_t i;
29
 	uint8_t i;
30
-	uint8_t *tmp = (uint8_t *)malloc(64);
30
+	for(i = 0; i < 64; i++) {	
31
+		buffer[i] = 0;
32
+	}
33
+}
34
+
35
+uint8_t *buffNew(void) {
36
+	uint8_t *tmp = (uint8_t *)malloc(65);
31
 	if (tmp == NULL) {
37
 	if (tmp == NULL) {
32
 		serialWriteString(getString(24)); // Display warning, don't care for CubeControl
38
 		serialWriteString(getString(24)); // Display warning, don't care for CubeControl
33
 		while(1); // Ran out of heap => Watchdog Reset
39
 		while(1); // Ran out of heap => Watchdog Reset
34
 	}
40
 	}
35
-	for (i = 0; i < 64; i++) {
36
-		// Clear pixels
37
-		tmp[i] = 0;
38
-	}
41
+	buffClearAllPixels(tmp);
42
+	tmp[64] = 1;
39
 	return tmp;
43
 	return tmp;
40
 }
44
 }
41
 
45
 
47
 	buffer[(8 * (7 - z)) + (7 - y)] &= ~(1 << x);
51
 	buffer[(8 * (7 - z)) + (7 - y)] &= ~(1 << x);
48
 }
52
 }
49
 
53
 
50
-void buffClearAllPixels(uint8_t *buffer) {
51
-	uint8_t i;
52
-	for(i = 0; i < 64; i++) {	
53
-		buffer[i] = 0;
54
-	}
55
-}
56
-
57
 void buffFree(uint8_t *buffer) {
54
 void buffFree(uint8_t *buffer) {
58
 	free(buffer);
55
 	free(buffer);
59
 }
56
 }

+ 0
- 4
CubeFirmware/cube.c View File

197
 	imgFlag = 0;
197
 	imgFlag = 0;
198
 	toggleFlag = 0;
198
 	toggleFlag = 0;
199
 }
199
 }
200
-
201
-void close(void) {
202
-	TIMSK &= ~(1 << OCIE1A); // Disable interrupt
203
-}

+ 146
- 0
CubeFirmware/font.c View File

1
+/*
2
+ * font.c
3
+ *
4
+ * Copyright 2012 Thomas Buck <xythobuz@me.com>
5
+ *
6
+ * This file is part of LED-Cube.
7
+ *
8
+ * LED-Cube is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * LED-Cube is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
21
+#include <stdint.h>
22
+#include <avr/io.h>
23
+#include <avr/pgmspace.h>
24
+
25
+uint8_t font[95][8];
26
+uint8_t fontBuff[8];
27
+
28
+uint8_t *getFont(char c) {
29
+	uint8_t i;
30
+	if (!((c >= 0x20) && (c <= 0x7E))) {
31
+		if ((c == '\r') || (c == '\n')) {
32
+			c = '!';
33
+		} else {
34
+			c = '?';
35
+		}
36
+	}
37
+	for (i = 0; i < 8; i++) {
38
+		fontBuff[i] = pgm_read_byte(&(font[(uint8_t)(c - 0x20)][i]));
39
+	}
40
+	return fontBuff;
41
+}
42
+
43
+
44
+// Source: http://www.mikrocontroller.net/topic/54860
45
+// Author: Benedikt K
46
+// This is a LCD Font originally for Codepage 850.
47
+// Because of size restraints, i cut everything but
48
+// the printable ascii range, 0x20 to 0x7E
49
+// Not really pretty on the cube, but enough for now.
50
+uint8_t font[95][8] PROGMEM = {
51
+	{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},	// 0x20
52
+	{0x0C,0x1E,0x1E,0x0C,0x0C,0x00,0x0C,0x00},	// 0x21
53
+	{0x36,0x36,0x36,0x00,0x00,0x00,0x00,0x00},	// 0x22
54
+	{0x36,0x36,0x7F,0x36,0x7F,0x36,0x36,0x00},	// 0x23
55
+	{0x0C,0x3E,0x03,0x1E,0x30,0x1F,0x0C,0x00},	// 0x24
56
+	{0x00,0x63,0x33,0x18,0x0C,0x66,0x63,0x00},	// 0x25
57
+	{0x1C,0x36,0x1C,0x6E,0x3B,0x33,0x6E,0x00},	// 0x26
58
+	{0x06,0x06,0x03,0x00,0x00,0x00,0x00,0x00},	// 0x27
59
+	{0x18,0x0C,0x06,0x06,0x06,0x0C,0x18,0x00},	// 0x28
60
+	{0x06,0x0C,0x18,0x18,0x18,0x0C,0x06,0x00},	// 0x29
61
+	{0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00},	// 0x2A
62
+	{0x00,0x0C,0x0C,0x3F,0x0C,0x0C,0x00,0x00},	// 0x2B
63
+	{0x00,0x00,0x00,0x00,0x00,0x0E,0x0C,0x06},	// 0x2C
64
+	{0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},	// 0x2D
65
+	{0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x00},	// 0x2E
66
+	{0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00},	// 0x2F
67
+	{0x1E,0x33,0x3B,0x3F,0x37,0x33,0x1E,0x00},	// 0x30
68
+	{0x0C,0x0F,0x0C,0x0C,0x0C,0x0C,0x3F,0x00},	// 0x31
69
+	{0x1E,0x33,0x30,0x1C,0x06,0x33,0x3F,0x00},	// 0x32
70
+	{0x1E,0x33,0x30,0x1C,0x30,0x33,0x1E,0x00},	// 0x33
71
+	{0x38,0x3C,0x36,0x33,0x7F,0x30,0x30,0x00},	// 0x34
72
+	{0x3F,0x03,0x1F,0x30,0x30,0x33,0x1E,0x00},	// 0x35
73
+	{0x1C,0x06,0x03,0x1F,0x33,0x33,0x1E,0x00},	// 0x36
74
+	{0x3F,0x33,0x30,0x18,0x0C,0x06,0x06,0x00},	// 0x37
75
+	{0x1E,0x33,0x33,0x1E,0x33,0x33,0x1E,0x00},	// 0x38
76
+	{0x1E,0x33,0x33,0x3E,0x30,0x18,0x0E,0x00},	// 0x39
77
+	{0x00,0x00,0x0C,0x0C,0x00,0x0C,0x0C,0x00},	// 0x3A
78
+	{0x00,0x00,0x0C,0x0C,0x00,0x0E,0x0C,0x06},	// 0x3B
79
+	{0x18,0x0C,0x06,0x03,0x06,0x0C,0x18,0x00},	// 0x3C
80
+	{0x00,0x00,0x3F,0x00,0x3F,0x00,0x00,0x00},	// 0x3D
81
+	{0x06,0x0C,0x18,0x30,0x18,0x0C,0x06,0x00},	// 0x3E
82
+	{0x1E,0x33,0x30,0x18,0x0C,0x00,0x0C,0x00},	// 0x3F
83
+	{0x3E,0x63,0x7B,0x7B,0x7B,0x03,0x1E,0x00},	// 0x40
84
+	{0x0C,0x1E,0x33,0x33,0x3F,0x33,0x33,0x00},	// 0x41
85
+	{0x3F,0x66,0x66,0x3E,0x66,0x66,0x3F,0x00},	// 0x42
86
+	{0x3C,0x66,0x03,0x03,0x03,0x66,0x3C,0x00},	// 0x43
87
+	{0x3F,0x36,0x66,0x66,0x66,0x36,0x3F,0x00},	// 0x44
88
+	{0x7F,0x46,0x16,0x1E,0x16,0x46,0x7F,0x00},	// 0x45
89
+	{0x7F,0x46,0x16,0x1E,0x16,0x06,0x0F,0x00},	// 0x46
90
+	{0x3C,0x66,0x03,0x03,0x73,0x66,0x7C,0x00},	// 0x47
91
+	{0x33,0x33,0x33,0x3F,0x33,0x33,0x33,0x00},	// 0x48
92
+	{0x1E,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00},	// 0x49
93
+	{0x78,0x30,0x30,0x30,0x33,0x33,0x1E,0x00},	// 0x4A
94
+	{0x67,0x66,0x36,0x1E,0x36,0x66,0x67,0x00},	// 0x4B
95
+	{0x0F,0x06,0x06,0x06,0x46,0x66,0x7F,0x00},	// 0x4C
96
+	{0x63,0x77,0x7F,0x6B,0x63,0x63,0x63,0x00},	// 0x4D
97
+	{0x63,0x67,0x6F,0x7B,0x73,0x63,0x63,0x00},	// 0x4E
98
+	{0x1C,0x36,0x63,0x63,0x63,0x36,0x1C,0x00},	// 0x4F
99
+	{0x3F,0x66,0x66,0x3E,0x06,0x06,0x0F,0x00},	// 0x50
100
+	{0x1E,0x33,0x33,0x33,0x3B,0x1E,0x38,0x00},	// 0x51
101
+	{0x3F,0x66,0x66,0x3E,0x1E,0x36,0x67,0x00},	// 0x52
102
+	{0x1E,0x33,0x07,0x1C,0x38,0x33,0x1E,0x00},	// 0x53
103
+	{0x3F,0x2D,0x0C,0x0C,0x0C,0x0C,0x1E,0x00},	// 0x54
104
+	{0x33,0x33,0x33,0x33,0x33,0x33,0x3F,0x00},	// 0x55
105
+	{0x33,0x33,0x33,0x33,0x33,0x1E,0x0C,0x00},	// 0x56
106
+	{0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00},	// 0x57
107
+	{0x63,0x63,0x36,0x1C,0x36,0x63,0x63,0x00},	// 0x58
108
+	{0x33,0x33,0x33,0x1E,0x0C,0x0C,0x1E,0x00},	// 0x59
109
+	{0x7F,0x33,0x19,0x0C,0x46,0x63,0x7F,0x00},	// 0x5A
110
+	{0x1E,0x06,0x06,0x06,0x06,0x06,0x1E,0x00},	// 0x5B
111
+	{0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00},	// 0x5C
112
+	{0x1E,0x18,0x18,0x18,0x18,0x18,0x1E,0x00},	// 0x5D
113
+	{0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00},	// 0x5E
114
+	{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF},	// 0x5F
115
+	{0x0C,0x0C,0x18,0x00,0x00,0x00,0x00,0x00},	// 0x60
116
+	{0x00,0x00,0x1E,0x30,0x3E,0x33,0x6E,0x00},	// 0x61
117
+	{0x07,0x06,0x3E,0x66,0x66,0x66,0x3D,0x00},	// 0x62
118
+	{0x00,0x00,0x1E,0x33,0x03,0x33,0x1E,0x00},	// 0x63
119
+	{0x38,0x30,0x30,0x3E,0x33,0x33,0x6E,0x00},	// 0x64
120
+	{0x00,0x00,0x1E,0x33,0x3F,0x03,0x1E,0x00},	// 0x65
121
+	{0x1C,0x36,0x06,0x0F,0x06,0x06,0x0F,0x00},	// 0x66
122
+	{0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x1F},	// 0x67
123
+	{0x07,0x06,0x36,0x6E,0x66,0x66,0x67,0x00},	// 0x68
124
+	{0x0C,0x00,0x0E,0x0C,0x0C,0x0C,0x1E,0x00},	// 0x69
125
+	{0x18,0x00,0x1E,0x18,0x18,0x18,0x1B,0x0E},	// 0x6A
126
+	{0x07,0x06,0x66,0x36,0x1E,0x36,0x67,0x00},	// 0x6B
127
+	{0x0E,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00},	// 0x6C
128
+	{0x00,0x00,0x37,0x7F,0x6B,0x63,0x63,0x00},	// 0x6D
129
+	{0x00,0x00,0x1F,0x33,0x33,0x33,0x33,0x00},	// 0x6E
130
+	{0x00,0x00,0x1E,0x33,0x33,0x33,0x1E,0x00},	// 0x6F
131
+	{0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F},	// 0x70
132
+	{0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78},	// 0x71
133
+	{0x00,0x00,0x1B,0x36,0x36,0x06,0x0F,0x00},	// 0x72
134
+	{0x00,0x00,0x3E,0x03,0x1E,0x30,0x1F,0x00},	// 0x73
135
+	{0x08,0x0C,0x3E,0x0C,0x0C,0x2C,0x18,0x00},	// 0x74
136
+	{0x00,0x00,0x33,0x33,0x33,0x33,0x6E,0x00},	// 0x75
137
+	{0x00,0x00,0x33,0x33,0x33,0x1E,0x0C,0x00},	// 0x76
138
+	{0x00,0x00,0x63,0x63,0x6B,0x7F,0x36,0x00},	// 0x77
139
+	{0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00},	// 0x78
140
+	{0x00,0x00,0x33,0x33,0x33,0x3E,0x30,0x1F},	// 0x79
141
+	{0x00,0x00,0x3F,0x19,0x0C,0x26,0x3F,0x00},	// 0x7A
142
+	{0x38,0x0C,0x0C,0x07,0x0C,0x0C,0x38,0x00},	// 0x7B
143
+	{0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x00},	// 0x7C
144
+	{0x07,0x0C,0x0C,0x38,0x0C,0x0C,0x07,0x00},	// 0x7D
145
+	{0x6E,0x3B,0x00,0x00,0x00,0x00,0x00,0x00},	// 0x7E
146
+};

+ 63
- 0
CubeFirmware/generator.c View File

1
+/*
2
+ * generator.c
3
+ *
4
+ * Copyright 2012 Thomas Buck <xythobuz@me.com>
5
+ *
6
+ * This file is part of LED-Cube.
7
+ *
8
+ * LED-Cube is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * LED-Cube is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
21
+#include <avr/io.h>
22
+#include <util/delay.h>
23
+#include <stdint.h>
24
+#include <stdlib.h>
25
+#include "memLayer.h"
26
+#include "font.h"
27
+#include "buffhelp.h"
28
+
29
+// Generate 8 frames, store them from index start.
30
+// data has 8 bytes --> 1 layer. This layer is moved from back to front.
31
+void generateMovingAnimation(uint8_t *data, uint8_t start, uint8_t duration) {
32
+	uint8_t i, j, d;
33
+	uint8_t *frame = (uint8_t *)malloc(65);
34
+	frame[64] = duration;
35
+
36
+	for (i = 0; i < 8; i++) {
37
+		d = 0;
38
+		for (j = 0; j < 64; j++) {
39
+			if ((j < (8 * (i + 1))) && (j >= (8 * i))) {
40
+				frame[j] = data[d++];
41
+			} else {
42
+				frame[j] = 0;
43
+			}
44
+		}
45
+		setFrame(i + start, frame);
46
+	}
47
+	free(frame);
48
+}
49
+
50
+void renderText(char *text, uint8_t start) {
51
+	uint8_t *buf;
52
+
53
+	while(text[0] != '\0') {
54
+		generateMovingAnimation(getFont(text[0]), start, 1);
55
+		start += 8;
56
+		text++;
57
+	}
58
+
59
+	buf = buffNew();
60
+	buf[64] = 10; // half second pause...
61
+	setFrame(start, buf);
62
+	free(buf);
63
+}

+ 0
- 3
CubeFirmware/header/cube.h View File

29
 // Copies the data in img into its own buffer
29
 // Copies the data in img into its own buffer
30
 extern void setImage(uint8_t *img); // img[64]
30
 extern void setImage(uint8_t *img); // img[64]
31
 extern uint8_t isFinished(void);
31
 extern uint8_t isFinished(void);
32
-extern void close(void);
33
-
34
 extern void fillBuffer(uint8_t val);
32
 extern void fillBuffer(uint8_t val);
35
-
36
 extern uint32_t getTriggerCount(void);
33
 extern uint32_t getTriggerCount(void);

+ 22
- 0
CubeFirmware/header/font.h View File

1
+/*
2
+ * font.h
3
+ *
4
+ * Copyright 2012 Thomas Buck <xythobuz@me.com>
5
+ *
6
+ * This file is part of LED-Cube.
7
+ *
8
+ * LED-Cube is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * LED-Cube is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
21
+
22
+uint8_t *getFont(char c);

+ 25
- 0
CubeFirmware/header/generator.h View File

1
+/*
2
+ * generator.h
3
+ *
4
+ * Copyright 2012 Thomas Buck <xythobuz@me.com>
5
+ *
6
+ * This file is part of LED-Cube.
7
+ *
8
+ * LED-Cube is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * LED-Cube is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
20
+ */
21
+
22
+// Generate 8 frames, store them from index start.
23
+// data has 8 bytes --> 1 layer. This layer is moved from back to front.
24
+void generateMovingAnimation(uint8_t *data, uint8_t start, uint8_t duration);
25
+void renderText(char *text, uint8_t start);

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

19
  * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
19
  * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
20
  */
20
  */
21
 
21
 
22
+#define LINEBUFFSIZE 81
23
+extern char buffer[LINEBUFFSIZE];
24
+
22
 void recieveAnimations(void);
25
 void recieveAnimations(void);
23
 void transmitAnimations(void);
26
 void transmitAnimations(void);
24
 void sendAudioData(void);
27
 void sendAudioData(void);
28
 uint8_t readNumber(uint8_t base);
31
 uint8_t readNumber(uint8_t base);
29
 void writeNumber(uint8_t num, uint8_t base);
32
 void writeNumber(uint8_t num, uint8_t base);
30
 uint8_t *readAFrame(void);
33
 uint8_t *readAFrame(void);
31
-void simpleAnimationInput(void);
34
+void simpleAnimationInput(void);
35
+void textRenderInput(void);

+ 37
- 23
CubeFirmware/main.c View File

45
 #include "visualizer.h"
45
 #include "visualizer.h"
46
 #include "animations.h"
46
 #include "animations.h"
47
 #include "transmit.h"
47
 #include "transmit.h"
48
+#include "font.h"
49
+#include "buffhelp.h"
48
 
50
 
49
 // Length of an idle animation frame, 24 -> 1 second
51
 // Length of an idle animation frame, 24 -> 1 second
50
 #define IDLELENGTH 48
52
 #define IDLELENGTH 48
80
 uint8_t disableMemory = 0;
82
 uint8_t disableMemory = 0;
81
 uint8_t disableAnim = 0;
83
 uint8_t disableAnim = 0;
82
 
84
 
83
-char buffer[11];
84
-
85
 /* Not so powerful Debouncing Example
85
 /* Not so powerful Debouncing Example
86
  * No Interrupt needed
86
  * No Interrupt needed
87
  * Author: Peter Dannegger
87
  * Author: Peter Dannegger
156
 		maxButtonState = numberOfVisualizations() + 1; // Number of toggle steps for button
156
 		maxButtonState = numberOfVisualizations() + 1; // Number of toggle steps for button
157
 		lastButtonState = 1;
157
 		lastButtonState = 1;
158
 
158
 
159
+	serialWriteString(getString(2));
159
 
160
 
160
 	while(1) { // Our Mainloop
161
 	while(1) { // Our Mainloop
161
 		if (!shouldRestart) { // A flag to trigger a watchdog reset
162
 		if (!shouldRestart) { // A flag to trigger a watchdog reset
223
 				lastButtonState = 0;
224
 				lastButtonState = 0;
224
 			}
225
 			}
225
 		}
226
 		}
226
-
227
-		// Print fps after one second
228
-		/* if ((getSystemTime() >= 1000) && (fpsWasSent == 0)) {
229
-			temp = getTriggerCount();
230
-			serialWriteString(ltoa(temp, buffer, 10));
231
-			serialWriteString(getString(27));
232
-			serialWriteString(ltoa((temp / 8), buffer, 10));
233
-			serialWriteString(getString(28));
234
-			fpsWasSent = 1;
235
-		} */
236
-
237
 	}
227
 	}
238
 
228
 
239
-	close(); // This is of course unneccessary. We never reach this point.
240
-	return 0;
229
+	return 0; // We never reach this point, of course!
241
 }
230
 }
242
 
231
 
243
 void init(void) {
232
 void init(void) {
325
 
314
 
326
 void serialHandler(char c) {
315
 void serialHandler(char c) {
327
 	// Used letters:
316
 	// Used letters:
328
-	// a, b, c, d, e, f, g, h, i, m, n, p, q, r, s, t, u, v, x, y, 0, 1, 2, 3, #
317
+	// a, b, c, d, e, f, g, h, i, m, n, o, p, q, r, s, t, u, v, w, x, y, 0, 1, 2, 3, #
329
 	uint8_t i, y, z;
318
 	uint8_t i, y, z;
330
 	uint8_t *tmp;
319
 	uint8_t *tmp;
331
 
320
 
435
 		serialWriteString(getString(33)); // Done
424
 		serialWriteString(getString(33)); // Done
436
 		break;
425
 		break;
437
 
426
 
427
+	case 'w': case 'W':
428
+		serialWriteString(getString(42)); // Text:
429
+		textRenderInput();
430
+		break;
431
+
438
 	case 'x': case 'X':
432
 	case 'x': case 'X':
439
 		// Get byte, store as animation count
433
 		// Get byte, store as animation count
440
 		serialWriteString(getString(16)); // "New animation count: "
434
 		serialWriteString(getString(16)); // "New animation count: "
472
 		disableAnim = 1;
466
 		disableAnim = 1;
473
 		break;
467
 		break;
474
 
468
 
475
-	case '3':
476
-		setImage(defaultImageCube);
477
-		disableAnim = 1;
478
-		break;
479
-
480
 	case '2':
469
 	case '2':
481
-		fillBuffer(0);
470
+		buffClearAllPixels(defaultImageCube);
482
 		while(1) {
471
 		while(1) {
483
 			for (i = 0; i < 8; i++) {
472
 			for (i = 0; i < 8; i++) {
484
 				for (y = 0; y < 8; y++) {
473
 				for (y = 0; y < 8; y++) {
499
 			}
488
 			}
500
 		}
489
 		}
501
 		break;
490
 		break;
502
-killMeForIt:
491
+	killMeForIt:
503
 		serialGet(); // Killed because we got a serial char. Remove it from buffer.
492
 		serialGet(); // Killed because we got a serial char. Remove it from buffer.
504
 		serialWriteString(getString(25));
493
 		serialWriteString(getString(25));
505
 		break;
494
 		break;
506
 
495
 
496
+	case '3':
497
+		buffClearAllPixels(defaultImageCube);
498
+		y = 0;
499
+		while(1) {
500
+			tmp = getFont(y);
501
+			if (y < 255) {
502
+				y++;
503
+			} else {
504
+				y = 0;
505
+			}
506
+			for (i = 0; i < 8; i++) {
507
+				defaultImageCube[i] = tmp[i];
508
+			}
509
+			setImage(defaultImageCube);
510
+			while (isFinished() < 12) {
511
+				wdt_reset();
512
+				if (serialHasChar()) {
513
+					goto killMeForIt; // Yes, yes. But i already need it for '2'
514
+					// So why not do it again... Please, no raptors :)
515
+					// http://xkcd.com/292/
516
+				}
517
+			}
518
+		}
519
+		break;
520
+
507
 	case 'I': case 'i':
521
 	case 'I': case 'i':
508
 		serialWriteString(ltoa(getTriggerCount(), buffer, 10));
522
 		serialWriteString(ltoa(getTriggerCount(), buffer, 10));
509
 		serialWrite('\n');
523
 		serialWrite('\n');

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


+ 2
- 0
CubeFirmware/makefile View File

49
 SRC += visualizer.c
49
 SRC += visualizer.c
50
 SRC += animations.c
50
 SRC += animations.c
51
 SRC += transmit.c
51
 SRC += transmit.c
52
+SRC += generator.c
53
+SRC += font.c
52
 
54
 
53
 # List Assembler source files here.
55
 # List Assembler source files here.
54
 # Make them always end in a capital .S.  Files ending in a lowercase .s
56
 # Make them always end in a capital .S.  Files ending in a lowercase .s

+ 16
- 8
CubeFirmware/strings.c View File

19
  * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
19
  * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
20
  */
20
  */
21
 #include <avr/pgmspace.h>
21
 #include <avr/pgmspace.h>
22
-
23
-char buffer[60];
22
+#include "transmit.h"
24
 
23
 
25
 const char stringVersion[] PROGMEM = "v2.5\n"; // 0
24
 const char stringVersion[] PROGMEM = "v2.5\n"; // 0
26
 const char stringSelfTestError[] PROGMEM = "Self-Test Error: 0b"; // 1
25
 const char stringSelfTestError[] PROGMEM = "Self-Test Error: 0b"; // 1
27
-const char stringInit[] PROGMEM = "Initialized: "; // 2
26
+const char stringInit[] PROGMEM = "Initialized!\n"; // 2
28
 const char stringAudioError[] PROGMEM = " => No answer from Audio!\n"; // 3
27
 const char stringAudioError[] PROGMEM = " => No answer from Audio!\n"; // 3
29
 const char stringMemError[] PROGMEM = " => No answer from Memory!\n"; // 4
28
 const char stringMemError[] PROGMEM = " => No answer from Memory!\n"; // 4
30
 const char stringMemWriteError[] PROGMEM = " => Can't write to Memory!\n"; // 5
29
 const char stringMemWriteError[] PROGMEM = " => Can't write to Memory!\n"; // 5
30
+
31
 const char stringHelp1[] PROGMEM = "(d)elete, (g)et anims, (s)et anims, (v)ersion\n"; // 6
31
 const char stringHelp1[] PROGMEM = "(d)elete, (g)et anims, (s)et anims, (v)ersion\n"; // 6
32
 const char stringHelp2[] PROGMEM = "(t)ime, (a)udio, (c)ount, (x)Custom count\n"; // 7
32
 const char stringHelp2[] PROGMEM = "(t)ime, (a)udio, (c)ount, (x)Custom count\n"; // 7
33
 const char stringHelp3[] PROGMEM = "(y)Set a frame, sim(p)le anim\n"; // 8
33
 const char stringHelp3[] PROGMEM = "(y)Set a frame, sim(p)le anim\n"; // 8
35
 const char stringHelp5[] PROGMEM = "Play S(n)ake\n"; // 10
35
 const char stringHelp5[] PROGMEM = "Play S(n)ake\n"; // 10
36
 const char stringHelp6[] PROGMEM = "All LEDs Off/On (0/1)\n"; // 11
36
 const char stringHelp6[] PROGMEM = "All LEDs Off/On (0/1)\n"; // 11
37
 const char stringHelp7[] PROGMEM = "(2): Test Anim. 1\n"; // 12
37
 const char stringHelp7[] PROGMEM = "(2): Test Anim. 1\n"; // 12
38
-const char stringHelp8[] PROGMEM = "(3): All Surface LEDs on\n"; // 13
38
+const char stringHelp8[] PROGMEM = "(3): Font Test\n"; // 13
39
+
39
 const char stringTime[] PROGMEM = "System Time: "; // 14
40
 const char stringTime[] PROGMEM = "System Time: "; // 14
40
 const char stringFrames[] PROGMEM = " Frames stored\n"; // 15
41
 const char stringFrames[] PROGMEM = " Frames stored\n"; // 15
41
 const char stringByte[] PROGMEM = "New animation count: "; // 16
42
 const char stringByte[] PROGMEM = "New animation count: "; // 16
42
-const char stringWritten[] PROGMEM = "durati(o)n"; // 17
43
+
44
+const char stringWritten[] PROGMEM = "durati(o)n\n"; // 17
45
+
43
 const char stringCount[] PROGMEM = "Frame to change: "; // 18
46
 const char stringCount[] PROGMEM = "Frame to change: "; // 18
44
 const char stringSelfTest[] PROGMEM = "Self-Test: 0b"; // 19
47
 const char stringSelfTest[] PROGMEM = "Self-Test: 0b"; // 19
45
 const char stringKillCount[] PROGMEM = "Killed Animation Counter!\n"; // 20
48
 const char stringKillCount[] PROGMEM = "Killed Animation Counter!\n"; // 20
48
 const char stringSnakeControl[] PROGMEM = "Controls: W A S D Q E, x to quit\n"; // 23
51
 const char stringSnakeControl[] PROGMEM = "Controls: W A S D Q E, x to quit\n"; // 23
49
 const char stringNoMoreHeap[] PROGMEM = "Ran out of Heap!\n"; // 24
52
 const char stringNoMoreHeap[] PROGMEM = "Ran out of Heap!\n"; // 24
50
 const char stringKilledAnimation[] PROGMEM = "Animation aborted!\n"; // 25
53
 const char stringKilledAnimation[] PROGMEM = "Animation aborted!\n"; // 25
54
+
51
 const char stringHelp9[] PROGMEM = "(i)nterrupt count, (r)andom, (q)reset\n"; // 26
55
 const char stringHelp9[] PROGMEM = "(i)nterrupt count, (r)andom, (q)reset\n"; // 26
56
+
52
 const char stringInterrupts[] PROGMEM = " Interrupts after 1000msec\n"; // 27
57
 const char stringInterrupts[] PROGMEM = " Interrupts after 1000msec\n"; // 27
53
 const char stringFrames2[] PROGMEM = " Frames per Second\n"; // 28
58
 const char stringFrames2[] PROGMEM = " Frames per Second\n"; // 28
54
 const char stringDeleted[] PROGMEM = "Memory deleted!\n"; // 29
59
 const char stringDeleted[] PROGMEM = "Memory deleted!\n"; // 29
56
 const char stringWatchdog[] PROGMEM = "Enter frame to dump: "; // 31
61
 const char stringWatchdog[] PROGMEM = "Enter frame to dump: "; // 31
57
 const char stringBrownout[] PROGMEM = "Formatting memory... "; // 32
62
 const char stringBrownout[] PROGMEM = "Formatting memory... "; // 32
58
 const char stringNothing[] PROGMEM = "Done!\n"; // 33
63
 const char stringNothing[] PROGMEM = "Done!\n"; // 33
59
-const char stringExtern[] PROGMEM = "(f)ormat memory\n"; // 34
64
+
65
+const char stringExtern[] PROGMEM = "(f)ormat memory, (w)rite text\n"; // 34
66
+
60
 const char stringJtag[] PROGMEM = "Duration: "; // 35
67
 const char stringJtag[] PROGMEM = "Duration: "; // 35
61
 const char stringPowerOn[] PROGMEM = "Start: "; // 36
68
 const char stringPowerOn[] PROGMEM = "Start: "; // 36
62
 const char stringMinute[] PROGMEM = "8 Layerbytes...\n"; // 37
69
 const char stringMinute[] PROGMEM = "8 Layerbytes...\n"; // 37
64
 const char stringCubeMode[] PROGMEM = "Ende: "; // 39
71
 const char stringCubeMode[] PROGMEM = "Ende: "; // 39
65
 const char stringModeChange[] PROGMEM = "Cube mode entered!\n"; // 40
72
 const char stringModeChange[] PROGMEM = "Cube mode entered!\n"; // 40
66
 const char stringModeChange2[] PROGMEM = "Audio mode entered!\n"; // 41
73
 const char stringModeChange2[] PROGMEM = "Audio mode entered!\n"; // 41
74
+const char stringRenderText[] PROGMEM = "Text: "; // 42
67
 
75
 
68
 // Last index + 1
76
 // Last index + 1
69
-#define STRINGNUM 42
77
+#define STRINGNUM 43
70
 
78
 
71
 PGM_P stringTable[STRINGNUM] PROGMEM = { stringVersion, stringSelfTestError, stringInit,
79
 PGM_P stringTable[STRINGNUM] PROGMEM = { stringVersion, stringSelfTestError, stringInit,
72
 								stringAudioError, stringMemError, stringMemWriteError,
80
 								stringAudioError, stringMemError, stringMemWriteError,
78
 								stringHelp9, stringInterrupts, stringFrames2, stringDeleted,
86
 								stringHelp9, stringInterrupts, stringFrames2, stringDeleted,
79
 								stringReset, stringWatchdog, stringBrownout, stringNothing,
87
 								stringReset, stringWatchdog, stringBrownout, stringNothing,
80
 								stringExtern, stringJtag, stringPowerOn, stringMinute, stringAudioMode,
88
 								stringExtern, stringJtag, stringPowerOn, stringMinute, stringAudioMode,
81
-								stringCubeMode, stringModeChange, stringModeChange2 };
89
+								stringCubeMode, stringModeChange, stringModeChange2, stringRenderText };
82
 
90
 
83
 char stringNotFoundError[] PROGMEM = "String not found!\n";
91
 char stringNotFoundError[] PROGMEM = "String not found!\n";
84
 
92
 

+ 27
- 21
CubeFirmware/transmit.c View File

23
 #include <stdint.h>
23
 #include <stdint.h>
24
 #include <stdlib.h>
24
 #include <stdlib.h>
25
 #include <avr/wdt.h>
25
 #include <avr/wdt.h>
26
+#include <string.h>
26
 #include "memLayer.h"
27
 #include "memLayer.h"
27
 #include "serial.h"
28
 #include "serial.h"
28
 #include "time.h"
29
 #include "time.h"
29
 #include "strings.h"
30
 #include "strings.h"
30
 #include "audio.h"
31
 #include "audio.h"
32
+#include "generator.h"
33
+
34
+#include "transmit.h"
31
 
35
 
32
 #define OK 0x42
36
 #define OK 0x42
33
 #define ERROR 0x23
37
 #define ERROR 0x23
34
 
38
 
35
 #define TIMEOUTPERFRAME 500
39
 #define TIMEOUTPERFRAME 500
36
 
40
 
37
-// These are global variables from main.c
38
-extern char buffer[11];
41
+char buffer[LINEBUFFSIZE];
42
+
43
+extern uint8_t refreshAnimationCount;
39
 
44
 
40
 void recieveAnimations(void) {
45
 void recieveAnimations(void) {
41
 	uint8_t animCount, a, frameCount, f, i, c;
46
 	uint8_t animCount, a, frameCount, f, i, c;
223
 				buffer[ptr] = '\0';
228
 				buffer[ptr] = '\0';
224
 				return (uint8_t *)buffer;
229
 				return (uint8_t *)buffer;
225
 			}
230
 			}
226
-			ptr++;
231
+			if (buffer[ptr] != '\r') {
232
+				// ignore carriage return (\r)
233
+				if (buffer[ptr] == 8) {
234
+					// handle backspace
235
+					ptr--;
236
+				} else {
237
+					ptr++;
238
+				}
239
+			}
227
 		}
240
 		}
228
-
229
 	}
241
 	}
230
 }
242
 }
231
 
243
 
256
 }
268
 }
257
 
269
 
258
 void simpleAnimationInput(void) {
270
 void simpleAnimationInput(void) {
259
-	uint8_t start, j, d;
260
-	int8_t i;
271
+	uint8_t start, i;
261
 	uint8_t data[8] = {0, 0, 0, 0, 0, 0, 0, 0};
272
 	uint8_t data[8] = {0, 0, 0, 0, 0, 0, 0, 0};
262
-	uint8_t *frame = (uint8_t *)malloc(65);
263
-	frame[64] = 2;
264
-
273
+	
265
 	serialWriteString(getString(36));
274
 	serialWriteString(getString(36));
266
 	start = readNumber(10);
275
 	start = readNumber(10);
267
 	serialWriteString(getString(37));
276
 	serialWriteString(getString(37));
271
 		data[i] = readNumber(16);
280
 		data[i] = readNumber(16);
272
 	}
281
 	}
273
 	serialWriteString(getString(38));
282
 	serialWriteString(getString(38));
274
-	for (i = 0; i < 8; i++) {
275
-		d = 0;
276
-		for (j = 0; j < 64; j++) {
277
-			if ((j < (8 * (i + 1))) && (j >= (8 * i))) {
278
-				frame[j] = data[d++];
279
-			} else {
280
-				frame[j] = 0;
281
-			}
282
-		}
283
-		setFrame(i + start, frame);
284
-	}
283
+	generateMovingAnimation(data, start, 2);
284
+	serialWriteString(getString(33)); // Done
285
+}
286
+
287
+void textRenderInput(void) {
288
+	readLine();
289
+	renderText(buffer, 0);
290
+	setAnimationCount((strlen(buffer) * 8) + 1); // Theres an empty frame at the end.
291
+	refreshAnimationCount = 1;
285
 	serialWriteString(getString(33)); // Done
292
 	serialWriteString(getString(33)); // Done
286
-	free(frame);
287
 }
293
 }

+ 0
- 13
CubeFirmware/visualizer.c View File

144
 	uint8_t *buff;
144
 	uint8_t *buff;
145
 
145
 
146
 	buff = buffNew();
146
 	buff = buffNew();
147
-	buffClearAllPixels(buff);
148
 
147
 
149
 	// setRow(0, 0, maxVal(average(data), 1), buff); // Show average
148
 	// setRow(0, 0, maxVal(average(data), 1), buff); // Show average
150
 	simpleVUMeter(data, buff, 7, 1, 0);
149
 	simpleVUMeter(data, buff, 7, 1, 0);
157
 	uint8_t *buff;
156
 	uint8_t *buff;
158
 	buff = buffNew();
157
 	buff = buffNew();
159
 
158
 
160
-	buffClearAllPixels(buff);
161
-
162
 	// setRow(0, 0, maxVal(average(data), 0), buff); // Show average
159
 	// setRow(0, 0, maxVal(average(data), 0), buff); // Show average
163
 	simpleVUMeter(data, buff, 7, 0, 0);
160
 	simpleVUMeter(data, buff, 7, 0, 0);
164
 
161
 
171
 	uint8_t i;
168
 	uint8_t i;
172
 	buff = buffNew();
169
 	buff = buffNew();
173
 
170
 
174
-	buffClearAllPixels(buff);
175
-
176
 	for (i = 2; i < 6; i++) {
171
 	for (i = 2; i < 6; i++) {
177
 		simpleVUMeter(data, buff, i, 0, 1);
172
 		simpleVUMeter(data, buff, i, 0, 1);
178
 	}
173
 	}
185
 	uint8_t *buff;
180
 	uint8_t *buff;
186
 	buff = buffNew();
181
 	buff = buffNew();
187
 
182
 
188
-	buffClearAllPixels(buff);
189
-
190
 	simpleVUMeter(data, buff, 2, 1, 0);
183
 	simpleVUMeter(data, buff, 2, 1, 0);
191
 	filterData(data, 0);
184
 	filterData(data, 0);
192
 	simpleVUMeter(data, buff, 5, 0, 0);
185
 	simpleVUMeter(data, buff, 5, 0, 0);
200
 	uint8_t i;
193
 	uint8_t i;
201
 	buff = buffNew();
194
 	buff = buffNew();
202
 
195
 
203
-	buffClearAllPixels(buff);
204
-
205
 	for (i = 0; i < 8; i++) {
196
 	for (i = 0; i < 8; i++) {
206
 		simpleVUMeter(data, buff, i, 1, 0);
197
 		simpleVUMeter(data, buff, i, 1, 0);
207
 	}
198
 	}
215
 	uint8_t i;
206
 	uint8_t i;
216
 	buff = buffNew();
207
 	buff = buffNew();
217
 
208
 
218
-	buffClearAllPixels(buff);
219
-
220
 	for (i = 0; i < 8; i++) {
209
 	for (i = 0; i < 8; i++) {
221
 		simpleVUMeter(data, buff, i, 0, 0);
210
 		simpleVUMeter(data, buff, i, 0, 0);
222
 	}
211
 	}
234
 
223
 
235
 void horribleWave(uint8_t *audioData) {
224
 void horribleWave(uint8_t *audioData) {
236
 	uint8_t *imageData = buffNew();
225
 	uint8_t *imageData = buffNew();
237
-	
238
-	buffClearAllPixels(imageData);
239
 
226
 
240
 	// Could not figure out a way to represent this easily in a loop
227
 	// Could not figure out a way to represent this easily in a loop
241
 	// without using a shitload of 'if's...
228
 	// without using a shitload of 'if's...

Loading…
Cancel
Save