Browse Source

Fixed frame counter width.

Only used 8bit vars, while 16bit were required.
Thomas Buck 11 years ago
parent
commit
121b72537c

+ 13
- 4
AudioFirmware/eq.c View File

@@ -75,7 +75,7 @@ uint8_t *equalizerGet(void) {
75 75
 
76 76
 	filterNoise(result); // Filter lower values
77 77
 	heightenTreble(result); // Heighten higher frequencies, cause they seem damped
78
-	// calcMultiplicator(result); // Multiply with Poti Position
78
+	calcMultiplicator(result); // Multiply with Poti Position
79 79
 	filterNoise(result); // Filter lower values
80 80
 
81 81
 	return result;
@@ -83,10 +83,19 @@ uint8_t *equalizerGet(void) {
83 83
 
84 84
 void calcMultiplicator(uint8_t *d) {
85 85
 	uint8_t i;
86
-	uint16_t multiplicator = ((uint16_t)getOffset() + 100) / 10;
86
+	uint16_t multiplicator = ((uint16_t)getOffset() + 100) / 10; // From 10 to 36
87
+	uint16_t temp;
87 88
 
88 89
 	for (i = 0; i < 7; i++) {
89
-		d[i] = (d[i] * multiplicator) / 10;
90
+		// Had some problems with 8bit and 16bit arithmetic, cutting some numbers.
91
+		// Thats why it is a bit more verbose than really necessary...
92
+		temp = d[i];
93
+		temp = temp * multiplicator / 10; // From 0 to 918
94
+		if (temp > 255) {
95
+			d[i] = 255;
96
+		} else {
97
+			d[i] = (uint8_t)temp;
98
+		}
90 99
 	}
91 100
 }
92 101
 
@@ -97,7 +106,7 @@ void heightenTreble(uint8_t *d) {
97 106
 void filterNoise(uint8_t *data) {
98 107
 	uint8_t i;
99 108
 	for (i = 0; i < 7; i++) {
100
-		if (data[i] < 60) {
109
+		if (data[i] < 30) {
101 110
 			data[i] = data[i] * 10 / 15; // / 1.5
102 111
 		}
103 112
 	}

+ 42
- 41
AudioFirmware/main.hex View File

@@ -1,53 +1,54 @@
1 1
 :1000000012C02CC02BC02AC029C028C027C026C0BF
2 2
 :1000100025C024C023C022C021C020C01FC01EC0D4
3
-:100020001DC0E6C01BC011241FBECFE5D4E0DEBF5B
4
-:10003000CDBF10E0A0E6B0E0E6E2F3E002C005903C
3
+:100020001DC0F3C01BC011241FBECFE5D4E0DEBF4E
4
+:10003000CDBF10E0A0E6B0E0E0E4F3E002C0059040
5 5
 :100040000D92AE36B107D9F710E0AEE6B0E001C0D0
6
-:100050001D92A037B107E1F702D063C1D1CFCF9392
6
+:100050001D92A037B107E1F702D070C1D1CFCF9385
7 7
 :1000600014BE88E10FB6F89481BD11BC0FBE86E0C6
8
-:1000700087BB8CE084BB11BA82E40ED12ED03DD078
8
+:1000700087BB8CE084BB11BA82E41BD12ED03DD06B
9 9
 :1000800078942DE088E190E00FB6F894A89581BDB2
10
-:100090000FBE21BD80E690E008D1C4E014D18823D2
11
-:1000A00029F088B38C2788BB4CD0FFD0A895F6CF19
10
+:100090000FBE21BD80E690E015D1C4E021D18823B8
11
+:1000A00029F088B38C2788BB80D00CD1A895F6CFD7
12 12
 :1000B00097B1907F97B997B18F70892B87B9369A8E
13 13
 :1000C000089581E0369980E00895FBDF8823E9F305
14 14
 :1000D000369824B135B1C901089517B83E9A86B152
15 15
 :1000E000856086B9379A80E0E3DFEFDF0895EDDFC2
16 16
 :1000F00096958795969587950895AB9AAA980895B1
17 17
 :10010000FC0195818AE0989FC00111246FE070E0A6
18
-:10011000F5D066830895CF93E82FF92F40E0CAE029
19
-:100120002FE030E080818C3330F48C9FC0011124AB
20
-:10013000B901E4D060834F5F3196473099F7CF9192
21
-:100140000895CF93DF93AB988FE191E00197F1F79A
22
-:1001500000C00000C0E6D0E0AA9A95E69A95F1F7B3
23
-:100160000000AA9880EC8A95F1F780E0A1DFBFDF5C
24
-:10017000899390E0C736D90779F7AB9A0000000061
25
-:10018000CE010797C8DFCE010797BADFCE010797E8
26
-:10019000C2DFCE010797DF91CF91089581E088DF1C
27
-:1001A000A6DF08951F93CF93DF93D82FC92FF6DFD3
28
-:1001B00090E08C599F4F6AE070E08CD09B01CE019B
29
-:1001C000E92FF82F10E0CAE0D0E0408150E0249FF2
30
-:1001D000C001259F900D349F900D1124BE017AD04F
31
-:1001E00061931F5F173089F7DF91CF911F910895B9
32
-:1001F0001F920F920FB60F9211248F939F93EF933C
33
-:10020000FF9381B190E0887F883B9105C1F0893BE5
34
-:1002100091053CF4883A910559F0803B910581F5B0
35
-:1002200007C0803C910531F1883C910549F522C019
36
-:1002300081E080936F008091670083B915C0809141
37
-:100240006F00863040F010926F0080916D0083B98E
38
-:1002500086B78F7B11C0E82FF0E0E959FF4F9081FE
39
-:1002600093B98F5F80936F0086B7806486BF1092CA
40
-:100270006E0006C086B7806486BF81E080936E0002
41
-:1002800086B7806886BFFF91EF919F918F910F9005
42
-:100290000FBE0F901F901895882311F481E001C0C4
43
-:1002A0008E7F82B985E486BF0895282F392FD90122
44
-:1002B000E7E6F0E08D91819380E0EE36F807D1F724
45
-:1002C00010926E00089581E090916E00992309F4D8
46
-:1002D00080E00895AA1BBB1B51E107C0AA1FBB1FEA
47
-:1002E000A617B70710F0A61BB70B881F991F5A95C2
48
-:1002F000A9F780959095BC01CD01089597FB092E33
49
-:1003000007260AD077FD04D0E5DF06D000201AF4D6
50
-:10031000709561957F4F0895F6F7909581959F4F61
51
-:060320000895F894FFCFE0
52
-:0E03260080808080808080424242424242427B
18
+:1001100002D166830895CF93E82FF92F40E0CAE01B
19
+:100120002FE030E080818E3130F48C9FC0011124AB
20
+:10013000B901F1D060834F5F3196473099F7CF9185
21
+:10014000089581E0B5DFD3DF08950F931F93CF9318
22
+:10015000DF93D82FC92FF5DF90E08C599F4F6AE0CD
23
+:1001600070E0C5D09B01CE01E92FF82F10E0CAE066
24
+:10017000D0E00FEF408150E0249FC001259F900DFB
25
+:10018000349F900D1124BE01B2D06F3F710519F05C
26
+:1001900010F0008301C060831F5F3196173051F764
27
+:1001A000DF91CF911F910F910895CF93DF93AB987B
28
+:1001B0008FE191E00197F1F700C00000C0E6D0E0C8
29
+:1001C000AA9A95E69A95F1F70000AA9880EC8A958C
30
+:1001D000F1F780E06DDF8BDF899390E0C736D907B8
31
+:1001E00079F7AB9A00000000CE01079794DFCE01AB
32
+:1001F000079786DFCE010797A8DFCE0107978BDF31
33
+:10020000CE010797DF91CF9108951F920F920FB6FD
34
+:100210000F9211248F939F93EF93FF9381B190E0FE
35
+:10022000887F883B9105C1F0893B91053CF4883A71
36
+:10023000910559F0803B910581F507C0803C9105FF
37
+:1002400031F1883C910549F522C081E080936F002F
38
+:100250008091670083B915C080916F00863040F0AF
39
+:1002600010926F0080916D0083B986B78F7B11C0AB
40
+:10027000E82FF0E0E959FF4F908193B98F5F8093A9
41
+:100280006F0086B7806486BF10926E0006C086B786
42
+:10029000806486BF81E080936E0086B7806886BFE9
43
+:1002A000FF91EF919F918F910F900FBE0F901F9034
44
+:1002B0001895882311F481E001C08E7F82B985E40E
45
+:1002C00086BF0895282F392FD901E7E6F0E08D91F8
46
+:1002D000819380E0EE36F807D1F710926E00089512
47
+:1002E00081E090916E00992309F480E00895AA1BA3
48
+:1002F000BB1B51E107C0AA1FBB1FA617B70710F011
49
+:10030000A61BB70B881F991F5A95A9F78095909542
50
+:10031000BC01CD01089597FB092E07260AD077FD71
51
+:1003200004D0E5DF06D000201AF4709561957F4F68
52
+:100330000895F6F7909581959F4F0895F894FFCF13
53
+:0E034000808080808080804242424242424261
53 54
 :00000001FF

+ 3
- 3
CubeFirmware/generator.c View File

@@ -28,7 +28,7 @@
28 28
 
29 29
 // Generate 8 frames, store them from index start.
30 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) {
31
+void generateMovingAnimation(uint8_t *data, uint16_t start, uint8_t duration) {
32 32
 	uint8_t i, j, d;
33 33
 	uint8_t *frame = (uint8_t *)malloc(65);
34 34
 	frame[64] = duration;
@@ -47,7 +47,7 @@ void generateMovingAnimation(uint8_t *data, uint8_t start, uint8_t duration) {
47 47
 	free(frame);
48 48
 }
49 49
 
50
-void renderText(char *text, uint8_t start) {
50
+void renderText(char *text, uint16_t start) {
51 51
 	uint8_t *buf;
52 52
 
53 53
 	while(text[0] != '\0') {
@@ -57,7 +57,7 @@ void renderText(char *text, uint8_t start) {
57 57
 	}
58 58
 
59 59
 	buf = buffNew();
60
-	buf[64] = 10; // half second pause...
60
+	buf[64] = 12; // half second empty frame at end of text
61 61
 	setFrame(start, buf);
62 62
 	free(buf);
63 63
 }

+ 2
- 2
CubeFirmware/header/generator.h View File

@@ -21,5 +21,5 @@
21 21
 
22 22
 // Generate 8 frames, store them from index start.
23 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);
24
+void generateMovingAnimation(uint8_t *data, uint16_t start, uint8_t duration);
25
+void renderText(char *text, uint16_t start);

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

@@ -28,7 +28,7 @@ void sendAudioData(void);
28 28
 void printTime(void);
29 29
 void dumpFrame(uint8_t *f);
30 30
 uint8_t *readLine(void);
31
-uint8_t readNumber(uint8_t base);
31
+uint16_t readNumber(uint8_t base);
32 32
 void writeNumber(uint8_t num, uint8_t base);
33 33
 uint8_t *readAFrame(void);
34 34
 void simpleAnimationInput(void);

+ 23
- 14
CubeFirmware/main.c View File

@@ -131,7 +131,7 @@ int main(void) {
131 131
 	*/
132 132
 
133 133
 	uint8_t i;
134
-	uint8_t imageIndex = 0, imageCount = 0;
134
+	uint16_t imageIndex = 0, imageCount = 0;
135 135
 	uint8_t idleIndex = 0, idleCount = 0;
136 136
 	uint8_t *imageData = NULL, *audioData = NULL;
137 137
 	uint8_t duration = 0;
@@ -149,12 +149,21 @@ int main(void) {
149 149
 		disableMemory = 1;
150 150
 	serialWriteString(getString(0)); // Print Version
151 151
 
152
-	if (disableMemory == 0)
152
+	if (disableMemory == 0) {
153 153
 		imageCount = getAnimationCount(); // Retrieve image count from memory
154
-	idleCount = numOfAnimations();
155
-	if (disableAudioData == 0)
156
-		maxButtonState = numberOfVisualizations() + 1; // Number of toggle steps for button
154
+		lastButtonState = 0;
155
+	} else {
157 156
 		lastButtonState = 1;
157
+	}
158
+	if (disableAudioData == 0) {
159
+		maxButtonState = numberOfVisualizations() + 1; // Number of toggle steps for button
160
+	} else {
161
+		lastButtonState = 0;
162
+		maxButtonState = 1;
163
+		// If both memory and audio are not working, we have nothing to do anyways...
164
+	}
165
+
166
+	idleCount = numOfAnimations();
158 167
 
159 168
 	serialWriteString(getString(2));
160 169
 
@@ -174,10 +183,10 @@ int main(void) {
174 183
 		}
175 184
 
176 185
 		if (debounce(PINB, PB0)) {
177
-			if (lastButtonState > 0) {
178
-				lastButtonState--;
186
+			if (lastButtonState < (maxButtonState - 1)) {
187
+				lastButtonState++;
179 188
 			} else {
180
-				lastButtonState = maxButtonState - 1;
189
+				lastButtonState = 0;
181 190
 			}
182 191
 		}
183 192
 
@@ -365,10 +374,10 @@ void serialHandler(char c) {
365 374
 		break;
366 375
 
367 376
 	case 'm': case 'M':
368
-		if (lastButtonState > 0) {
369
-			lastButtonState--;
377
+		if (lastButtonState < (maxButtonState - 1)) {
378
+			lastButtonState++;
370 379
 		} else {
371
-			lastButtonState = maxButtonState - 1;
380
+			lastButtonState = 0;
372 381
 		}
373 382
 		if (lastButtonState) {
374 383
 			writeNumber(lastButtonState, 10);
@@ -495,13 +504,13 @@ void serialHandler(char c) {
495 504
 
496 505
 	case '3':
497 506
 		buffClearAllPixels(defaultImageCube);
498
-		y = 0;
507
+		y = 0x20;
499 508
 		while(1) {
500 509
 			tmp = getFont(y);
501
-			if (y < 255) {
510
+			if (y < 0x7E) {
502 511
 				y++;
503 512
 			} else {
504
-				y = 0;
513
+				y = 0x20;
505 514
 			}
506 515
 			for (i = 0; i < 8; i++) {
507 516
 				defaultImageCube[i] = tmp[i];

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


+ 2
- 2
CubeFirmware/transmit.c View File

@@ -241,9 +241,9 @@ uint8_t *readLine(void) {
241 241
 	}
242 242
 }
243 243
 
244
-uint8_t readNumber(uint8_t base) {
244
+uint16_t readNumber(uint8_t base) {
245 245
 	uint8_t *s = readLine();
246
-	uint8_t val = (uint8_t)strtoul((char *)s, NULL, base);
246
+	uint16_t val = (uint16_t)strtoul((char *)s, NULL, base);
247 247
 	return val;
248 248
 }
249 249
 

+ 16
- 8
CubeFirmware/visualizer.c View File

@@ -45,10 +45,15 @@ void simpleLog(uint8_t *data);
45 45
 void fullDepthLog(uint8_t *data);
46 46
 void linLog(uint8_t *data);
47 47
 
48
-#define NUMOFVISUALIZATIONS 7
49
-void (*visualizations[NUMOFVISUALIZATIONS])(uint8_t *data) = { &linLog, &simpleVisualization,
50
-													&fullDepthVisualization, &horribleWave,
51
-													&simpleLog, &fullDepthLog, &simpleSwitch };
48
+#define LINEARVISUALS 4
49
+void (*linear[LINEARVISUALS])(uint8_t *data) = { &simpleVisualization, &fullDepthVisualization,
50
+											&simpleSwitch, &horribleWave };
51
+
52
+#define LOGARITHMICVISUALS 3
53
+void (*logarithmic[LOGARITHMICVISUALS])(uint8_t *data) = { &linLog, &simpleLog, &fullDepthLog };
54
+
55
+#define NUMOFVISUALIZATIONS (LINEARVISUALS + LOGARITHMICVISUALS)
56
+
52 57
 uint8_t logScale[8] = { 2, 4, 8, 16, 31, 63, 125, 250 }; // --> ca. (1 << (led + 1));
53 58
 
54 59
 uint8_t numberOfVisualizations(void) {
@@ -57,12 +62,15 @@ uint8_t numberOfVisualizations(void) {
57 62
 
58 63
 void runVisualization(uint8_t *data, uint8_t id) {
59 64
 	if (id < NUMOFVISUALIZATIONS) {
60
-		if ((id == 0) || ((id > 3) && (id <= 5))) {
61
-			filterData(data, 1);
65
+		if (id < LINEARVISUALS) {
66
+			filterData(data, 0); // Linear filter
67
+			linear[id](data); // run it
68
+		} else if ((id - LINEARVISUALS) < LOGARITHMICVISUALS) {
69
+			filterData(data, 1); // Logarithmic filter
70
+			logarithmic[id - LINEARVISUALS](data); // run it
62 71
 		} else {
63
-			filterData(data, 0);
72
+			// Invalid, do nothing!
64 73
 		}
65
-		visualizations[id](data);
66 74
 	}
67 75
 }
68 76
 

Loading…
Cancel
Save