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
 #define IDLELENGTH 48
52
 #define IDLELENGTH 48
53
 
53
 
54
 void init(void);
54
 void init(void);
55
-uint8_t audioModeSelected(void);
56
 uint8_t selfTest(void);
55
 uint8_t selfTest(void);
57
 void serialHandler(char c);
56
 void serialHandler(char c);
58
 
57
 
136
 	uint8_t i;
135
 	uint8_t i;
137
 	uint8_t imageIndex = 0, imageCount = 0;
136
 	uint8_t imageIndex = 0, imageCount = 0;
138
 	uint8_t idleIndex = 0, idleCount = 0;
137
 	uint8_t idleIndex = 0, idleCount = 0;
139
-	uint8_t lastButtonCheck;
140
-	// uint8_t fpsWasSent = 0;
141
-	// uint32_t temp;
142
 	uint8_t *imageData = NULL, *audioData = NULL;
138
 	uint8_t *imageData = NULL, *audioData = NULL;
143
 	uint8_t duration = 0;
139
 	uint8_t duration = 0;
144
 
140
 
155
 		disableMemory = 1;
151
 		disableMemory = 1;
156
 	serialWriteString(getString(0)); // Print Version
152
 	serialWriteString(getString(0)); // Print Version
157
 
153
 
158
-	audioModeSelected(); // Initial button state check
159
-	lastButtonCheck = getSystemTime(); // Time we checked
160
-
161
 	if (disableMemory == 0)
154
 	if (disableMemory == 0)
162
 		imageCount = getAnimationCount(); // Retrieve image count from memory
155
 		imageCount = getAnimationCount(); // Retrieve image count from memory
163
 	idleCount = numOfAnimations();
156
 	idleCount = numOfAnimations();
164
 	if (disableAudioData == 0)
157
 	if (disableAudioData == 0)
165
 		maxButtonState = numberOfVisualizations() + 1; // Number of toggle steps for button
158
 		maxButtonState = numberOfVisualizations() + 1; // Number of toggle steps for button
159
+		lastButtonState = 1;
160
+
166
 
161
 
167
 	while(1) { // Our Mainloop
162
 	while(1) { // Our Mainloop
168
 		if (!shouldRestart) { // A flag to trigger a watchdog reset
163
 		if (!shouldRestart) { // A flag to trigger a watchdog reset
179
 			serialHandler((char)(serialGet()));
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
 		if (lastButtonState == 0) {
185
 		if (lastButtonState == 0) {
188
 			// Display animations, stored or built-in
186
 			// Display animations, stored or built-in
259
 	setImage(defaultImageCube); // Display something
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
 uint8_t selfTest(void) {
260
 uint8_t selfTest(void) {
277
 	uint8_t result = NOERROR;
261
 	uint8_t result = NOERROR;
278
 	
262
 	
393
 		break;
377
 		break;
394
 
378
 
395
 	case 'm': case 'M':
379
 	case 'm': case 'M':
396
-		if (lastButtonState < (maxButtonState - 1)) {
397
-			lastButtonState++;
380
+		if (lastButtonState > 0) {
381
+			lastButtonState--;
398
 		} else {
382
 		} else {
399
-			lastButtonState = 0;
383
+			lastButtonState = maxButtonState - 1;
400
 		}
384
 		}
401
 		if (lastButtonState) {
385
 		if (lastButtonState) {
402
 			serialWriteString(getString(41));
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
  */
22
  */
23
 #include <avr/io.h>
23
 #include <avr/io.h>
24
 #include <stdint.h>
24
 #include <stdint.h>
25
+#include <stdlib.h>
25
 
26
 
26
 #include <visualizer.h>
27
 #include <visualizer.h>
27
 #include <cube.h>
28
 #include <cube.h>
36
 uint8_t maxVal(uint8_t data, uint8_t log);
37
 uint8_t maxVal(uint8_t data, uint8_t log);
37
 void setRow(uint8_t x, uint8_t z, uint8_t height, uint8_t *buf);
38
 void setRow(uint8_t x, uint8_t z, uint8_t height, uint8_t *buf);
38
 uint8_t average(uint8_t *data);
39
 uint8_t average(uint8_t *data);
40
+uint8_t maximum(uint8_t *data);
39
 void filterData(uint8_t *data, uint8_t log);
41
 void filterData(uint8_t *data, uint8_t log);
40
 void simpleVisualization(uint8_t *data);
42
 void simpleVisualization(uint8_t *data);
41
 void fullDepthVisualization(uint8_t *data);
43
 void fullDepthVisualization(uint8_t *data);
45
 void linLog(uint8_t *data);
47
 void linLog(uint8_t *data);
46
 
48
 
47
 #define NUMOFVISUALIZATIONS 6
49
 #define NUMOFVISUALIZATIONS 6
48
-void (*visualizations[NUMOFVISUALIZATIONS])(uint8_t *data) = { &simpleVisualization,
50
+void (*visualizations[NUMOFVISUALIZATIONS])(uint8_t *data) = { &linLog, &simpleVisualization,
49
 													&fullDepthVisualization, &horribleWave,
51
 													&fullDepthVisualization, &horribleWave,
50
-													&simpleLog, &fullDepthLog, &linLog };
52
+													&simpleLog, &fullDepthLog };
51
 uint8_t logScale[8] = { 2, 4, 8, 16, 31, 63, 125, 250 }; // --> ca. (1 << (led + 1));
53
 uint8_t logScale[8] = { 2, 4, 8, 16, 31, 63, 125, 250 }; // --> ca. (1 << (led + 1));
52
 
54
 
53
 uint8_t numberOfVisualizations(void) {
55
 uint8_t numberOfVisualizations(void) {
56
 
58
 
57
 void runVisualization(uint8_t *data, uint8_t id) {
59
 void runVisualization(uint8_t *data, uint8_t id) {
58
 	if (id < NUMOFVISUALIZATIONS) {
60
 	if (id < NUMOFVISUALIZATIONS) {
59
-		if ((id <= 5) && (id > 2)) {
61
+		if ((id == 0) || ((id > 3) && (id <= 5))) {
60
 			filterData(data, 1);
62
 			filterData(data, 1);
61
-			visualizations[id](data);
62
 		} else {
63
 		} else {
63
 			filterData(data, 0);
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
 uint8_t maxVal(uint8_t data, uint8_t log) {
80
 uint8_t maxVal(uint8_t data, uint8_t log) {
70
 	uint8_t max = 0;
81
 	uint8_t max = 0;
71
 	if (log) {
82
 	if (log) {
90
 void filterData(uint8_t *data, uint8_t log) {
101
 void filterData(uint8_t *data, uint8_t log) {
91
 	uint8_t i;
102
 	uint8_t i;
92
 	uint8_t max;
103
 	uint8_t max;
104
+
93
 	if (log) {
105
 	if (log) {
94
-		max = THRESHOLD / 2;
106
+		if (average(data) < THRESHOLD) {
107
+			max = THRESHOLD;
108
+		} else {
109
+			max = THRESHOLD / 2;
110
+		}
95
 	} else {
111
 	} else {
96
 		max = THRESHOLD;
112
 		max = THRESHOLD;
97
 	}
113
 	}

Loading…
Cancel
Save