Преглед изворни кода

Can render text.

Font is not pretty, but works :)
Thomas Buck пре 12 година
родитељ
комит
a533318567

+ 10
- 13
CubeFirmware/buffhelp.c Прегледај датотеку

@@ -25,17 +25,21 @@
25 25
 #include <serial.h>
26 26
 #include <strings.h>
27 27
 
28
-uint8_t *buffNew(void) {
28
+void buffClearAllPixels(uint8_t *buffer) {
29 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 37
 	if (tmp == NULL) {
32 38
 		serialWriteString(getString(24)); // Display warning, don't care for CubeControl
33 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 43
 	return tmp;
40 44
 }
41 45
 
@@ -47,13 +51,6 @@ void buffClearPixel(uint8_t *buffer, uint8_t x, uint8_t y, uint8_t z) {
47 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 54
 void buffFree(uint8_t *buffer) {
58 55
 	free(buffer);
59 56
 }

+ 0
- 4
CubeFirmware/cube.c Прегледај датотеку

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

+ 146
- 0
CubeFirmware/font.c Прегледај датотеку

@@ -0,0 +1,146 @@
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 Прегледај датотеку

@@ -0,0 +1,63 @@
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 Прегледај датотеку

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

+ 22
- 0
CubeFirmware/header/font.h Прегледај датотеку

@@ -0,0 +1,22 @@
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 Прегледај датотеку

@@ -0,0 +1,25 @@
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 Прегледај датотеку

@@ -19,6 +19,9 @@
19 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 25
 void recieveAnimations(void);
23 26
 void transmitAnimations(void);
24 27
 void sendAudioData(void);
@@ -28,4 +31,5 @@ uint8_t *readLine(void);
28 31
 uint8_t readNumber(uint8_t base);
29 32
 void writeNumber(uint8_t num, uint8_t base);
30 33
 uint8_t *readAFrame(void);
31
-void simpleAnimationInput(void);
34
+void simpleAnimationInput(void);
35
+void textRenderInput(void);

+ 37
- 23
CubeFirmware/main.c Прегледај датотеку

@@ -45,6 +45,8 @@
45 45
 #include "visualizer.h"
46 46
 #include "animations.h"
47 47
 #include "transmit.h"
48
+#include "font.h"
49
+#include "buffhelp.h"
48 50
 
49 51
 // Length of an idle animation frame, 24 -> 1 second
50 52
 #define IDLELENGTH 48
@@ -80,8 +82,6 @@ uint8_t disableAudioData = 0;
80 82
 uint8_t disableMemory = 0;
81 83
 uint8_t disableAnim = 0;
82 84
 
83
-char buffer[11];
84
-
85 85
 /* Not so powerful Debouncing Example
86 86
  * No Interrupt needed
87 87
  * Author: Peter Dannegger
@@ -156,6 +156,7 @@ int main(void) {
156 156
 		maxButtonState = numberOfVisualizations() + 1; // Number of toggle steps for button
157 157
 		lastButtonState = 1;
158 158
 
159
+	serialWriteString(getString(2));
159 160
 
160 161
 	while(1) { // Our Mainloop
161 162
 		if (!shouldRestart) { // A flag to trigger a watchdog reset
@@ -223,21 +224,9 @@ int main(void) {
223 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 232
 void init(void) {
@@ -325,7 +314,7 @@ void randomAnimation(void) {
325 314
 
326 315
 void serialHandler(char c) {
327 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 318
 	uint8_t i, y, z;
330 319
 	uint8_t *tmp;
331 320
 
@@ -435,6 +424,11 @@ void serialHandler(char c) {
435 424
 		serialWriteString(getString(33)); // Done
436 425
 		break;
437 426
 
427
+	case 'w': case 'W':
428
+		serialWriteString(getString(42)); // Text:
429
+		textRenderInput();
430
+		break;
431
+
438 432
 	case 'x': case 'X':
439 433
 		// Get byte, store as animation count
440 434
 		serialWriteString(getString(16)); // "New animation count: "
@@ -472,13 +466,8 @@ void serialHandler(char c) {
472 466
 		disableAnim = 1;
473 467
 		break;
474 468
 
475
-	case '3':
476
-		setImage(defaultImageCube);
477
-		disableAnim = 1;
478
-		break;
479
-
480 469
 	case '2':
481
-		fillBuffer(0);
470
+		buffClearAllPixels(defaultImageCube);
482 471
 		while(1) {
483 472
 			for (i = 0; i < 8; i++) {
484 473
 				for (y = 0; y < 8; y++) {
@@ -499,11 +488,36 @@ void serialHandler(char c) {
499 488
 			}
500 489
 		}
501 490
 		break;
502
-killMeForIt:
491
+	killMeForIt:
503 492
 		serialGet(); // Killed because we got a serial char. Remove it from buffer.
504 493
 		serialWriteString(getString(25));
505 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 521
 	case 'I': case 'i':
508 522
 		serialWriteString(ltoa(getTriggerCount(), buffer, 10));
509 523
 		serialWrite('\n');

+ 1410
- 1341
CubeFirmware/main.hex
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 2
- 0
CubeFirmware/makefile Прегледај датотеку

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

+ 16
- 8
CubeFirmware/strings.c Прегледај датотеку

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

+ 27
- 21
CubeFirmware/transmit.c Прегледај датотеку

@@ -23,19 +23,24 @@
23 23
 #include <stdint.h>
24 24
 #include <stdlib.h>
25 25
 #include <avr/wdt.h>
26
+#include <string.h>
26 27
 #include "memLayer.h"
27 28
 #include "serial.h"
28 29
 #include "time.h"
29 30
 #include "strings.h"
30 31
 #include "audio.h"
32
+#include "generator.h"
33
+
34
+#include "transmit.h"
31 35
 
32 36
 #define OK 0x42
33 37
 #define ERROR 0x23
34 38
 
35 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 45
 void recieveAnimations(void) {
41 46
 	uint8_t animCount, a, frameCount, f, i, c;
@@ -223,9 +228,16 @@ uint8_t *readLine(void) {
223 228
 				buffer[ptr] = '\0';
224 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,12 +268,9 @@ uint8_t *readAFrame(void) {
256 268
 }
257 269
 
258 270
 void simpleAnimationInput(void) {
259
-	uint8_t start, j, d;
260
-	int8_t i;
271
+	uint8_t start, i;
261 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 274
 	serialWriteString(getString(36));
266 275
 	start = readNumber(10);
267 276
 	serialWriteString(getString(37));
@@ -271,17 +280,14 @@ void simpleAnimationInput(void) {
271 280
 		data[i] = readNumber(16);
272 281
 	}
273 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 292
 	serialWriteString(getString(33)); // Done
286
-	free(frame);
287 293
 }

+ 0
- 13
CubeFirmware/visualizer.c Прегледај датотеку

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

Loading…
Откажи
Сачувај