Browse Source

Misc changes.

Reversed button scroll direction, removed cruft, linLog Visualization
is now started after boot. Revised filter for audio data.
Thomas Buck 12 years ago
parent
commit
941723235e
3 changed files with 1245 additions and 1245 deletions
  1. 12
    28
      CubeFirmware/main.c
  2. 1211
    1211
      CubeFirmware/main.hex
  3. 22
    6
      CubeFirmware/visualizer.c

+ 12
- 28
CubeFirmware/main.c View File

@@ -52,7 +52,6 @@
52 52
 #define IDLELENGTH 48
53 53
 
54 54
 void init(void);
55
-uint8_t audioModeSelected(void);
56 55
 uint8_t selfTest(void);
57 56
 void serialHandler(char c);
58 57
 
@@ -136,9 +135,6 @@ int main(void) {
136 135
 	uint8_t i;
137 136
 	uint8_t imageIndex = 0, imageCount = 0;
138 137
 	uint8_t idleIndex = 0, idleCount = 0;
139
-	uint8_t lastButtonCheck;
140
-	// uint8_t fpsWasSent = 0;
141
-	// uint32_t temp;
142 138
 	uint8_t *imageData = NULL, *audioData = NULL;
143 139
 	uint8_t duration = 0;
144 140
 
@@ -155,14 +151,13 @@ int main(void) {
155 151
 		disableMemory = 1;
156 152
 	serialWriteString(getString(0)); // Print Version
157 153
 
158
-	audioModeSelected(); // Initial button state check
159
-	lastButtonCheck = getSystemTime(); // Time we checked
160
-
161 154
 	if (disableMemory == 0)
162 155
 		imageCount = getAnimationCount(); // Retrieve image count from memory
163 156
 	idleCount = numOfAnimations();
164 157
 	if (disableAudioData == 0)
165 158
 		maxButtonState = numberOfVisualizations() + 1; // Number of toggle steps for button
159
+		lastButtonState = 1;
160
+
166 161
 
167 162
 	while(1) { // Our Mainloop
168 163
 		if (!shouldRestart) { // A flag to trigger a watchdog reset
@@ -179,10 +174,13 @@ int main(void) {
179 174
 			serialHandler((char)(serialGet()));
180 175
 		}
181 176
 
182
-		//if ((getSystemTime() - lastButtonCheck) >= 150) { // Check button state every 150ms
183
-			audioModeSelected();
184
-		//	lastButtonCheck = getSystemTime();
185
-		//}
177
+		if (debounce(PINB, PB0)) {
178
+			if (lastButtonState > 0) {
179
+				lastButtonState--;
180
+			} else {
181
+				lastButtonState = maxButtonState - 1;
182
+			}
183
+		}
186 184
 
187 185
 		if (lastButtonState == 0) {
188 186
 			// Display animations, stored or built-in
@@ -259,20 +257,6 @@ void init(void) {
259 257
 	setImage(defaultImageCube); // Display something
260 258
 }
261 259
 
262
-uint8_t audioModeSelected(void) {
263
-	// Pushbutton: PB0, Low active
264
-	if (debounce(PINB, PB0)) {
265
-		// Button pushed
266
-		if (lastButtonState < (maxButtonState - 1)) {
267
-			lastButtonState++;
268
-		} else {
269
-			lastButtonState = 0;
270
-		}
271
-
272
-	}
273
-	return lastButtonState;
274
-}
275
-
276 260
 uint8_t selfTest(void) {
277 261
 	uint8_t result = NOERROR;
278 262
 	
@@ -393,10 +377,10 @@ void serialHandler(char c) {
393 377
 		break;
394 378
 
395 379
 	case 'm': case 'M':
396
-		if (lastButtonState < (maxButtonState - 1)) {
397
-			lastButtonState++;
380
+		if (lastButtonState > 0) {
381
+			lastButtonState--;
398 382
 		} else {
399
-			lastButtonState = 0;
383
+			lastButtonState = maxButtonState - 1;
400 384
 		}
401 385
 		if (lastButtonState) {
402 386
 			serialWriteString(getString(41));

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


+ 22
- 6
CubeFirmware/visualizer.c View File

@@ -22,6 +22,7 @@
22 22
  */
23 23
 #include <avr/io.h>
24 24
 #include <stdint.h>
25
+#include <stdlib.h>
25 26
 
26 27
 #include <visualizer.h>
27 28
 #include <cube.h>
@@ -36,6 +37,7 @@
36 37
 uint8_t maxVal(uint8_t data, uint8_t log);
37 38
 void setRow(uint8_t x, uint8_t z, uint8_t height, uint8_t *buf);
38 39
 uint8_t average(uint8_t *data);
40
+uint8_t maximum(uint8_t *data);
39 41
 void filterData(uint8_t *data, uint8_t log);
40 42
 void simpleVisualization(uint8_t *data);
41 43
 void fullDepthVisualization(uint8_t *data);
@@ -45,9 +47,9 @@ void fullDepthLog(uint8_t *data);
45 47
 void linLog(uint8_t *data);
46 48
 
47 49
 #define NUMOFVISUALIZATIONS 6
48
-void (*visualizations[NUMOFVISUALIZATIONS])(uint8_t *data) = { &simpleVisualization,
50
+void (*visualizations[NUMOFVISUALIZATIONS])(uint8_t *data) = { &linLog, &simpleVisualization,
49 51
 													&fullDepthVisualization, &horribleWave,
50
-													&simpleLog, &fullDepthLog, &linLog };
52
+													&simpleLog, &fullDepthLog };
51 53
 uint8_t logScale[8] = { 2, 4, 8, 16, 31, 63, 125, 250 }; // --> ca. (1 << (led + 1));
52 54
 
53 55
 uint8_t numberOfVisualizations(void) {
@@ -56,16 +58,25 @@ uint8_t numberOfVisualizations(void) {
56 58
 
57 59
 void runVisualization(uint8_t *data, uint8_t id) {
58 60
 	if (id < NUMOFVISUALIZATIONS) {
59
-		if ((id <= 5) && (id > 2)) {
61
+		if ((id == 0) || ((id > 3) && (id <= 5))) {
60 62
 			filterData(data, 1);
61
-			visualizations[id](data);
62 63
 		} else {
63 64
 			filterData(data, 0);
64
-			visualizations[id](data);
65 65
 		}
66
+		visualizations[id](data);
66 67
 	}
67 68
 }
68 69
 
70
+uint8_t maximum(uint8_t *data) {
71
+	uint8_t i, max = 0;
72
+	for (i = 0; i < 7; i++) {
73
+		if (data[i] > max) {
74
+			max = data[i];
75
+		}
76
+	}
77
+	return max;
78
+}
79
+
69 80
 uint8_t maxVal(uint8_t data, uint8_t log) {
70 81
 	uint8_t max = 0;
71 82
 	if (log) {
@@ -90,8 +101,13 @@ uint8_t average(uint8_t *data) {
90 101
 void filterData(uint8_t *data, uint8_t log) {
91 102
 	uint8_t i;
92 103
 	uint8_t max;
104
+
93 105
 	if (log) {
94
-		max = THRESHOLD / 2;
106
+		if (average(data) < THRESHOLD) {
107
+			max = THRESHOLD;
108
+		} else {
109
+			max = THRESHOLD / 2;
110
+		}
95 111
 	} else {
96 112
 		max = THRESHOLD;
97 113
 	}

Loading…
Cancel
Save