Browse Source

Fixed button.

Thanks to Peter Dannegger. Also added another visualization, linear and
logarithmic together.
Thomas Buck 12 years ago
parent
commit
0619f4b121
3 changed files with 1286 additions and 1230 deletions
  1. 41
    5
      CubeFirmware/main.c
  2. 1212
    1218
      CubeFirmware/main.hex
  3. 33
    7
      CubeFirmware/visualizer.c

+ 41
- 5
CubeFirmware/main.c View File

@@ -85,6 +85,43 @@ uint8_t disableAnim = 0;
85 85
 
86 86
 char buffer[11];
87 87
 
88
+/* Not so powerful Debouncing Example
89
+ * No Interrupt needed
90
+ * Author: Peter Dannegger
91
+ */
92
+#define debounce(port, pin) ({													\
93
+	static uint8_t flag = 0;			/* new variable on every macro usage */ \
94
+	uint8_t i = 0;																\
95
+	if (flag) {							/* check for key release: */ 			\
96
+		for(;;) {						/* loop ... */							\
97
+			if(!(port & 1 << pin)) {	/* ... until key pressed or ... */		\
98
+				i = 0;															\
99
+				break;															\
100
+			}																	\
101
+			_delay_us(98);				/* * 256 = 25ms */						\
102
+			if(--i == 0) {				/* ... until key >25ms released */		\
103
+				flag = 0;				/* clear press flag */					\
104
+				i = 0;					/* 0 = key release debounced */			\
105
+				break;															\
106
+			}																	\
107
+		}																		\
108
+	} else {							/* else check for key press: */			\
109
+		for(;;) {						/* loop ... */							\
110
+			if ((port & 1<<pin)) {		/* ... until key released or ... */		\
111
+				i = 0;															\
112
+				break;															\
113
+			}																	\
114
+			_delay_us( 98 );			/* * 256 = 25ms */						\
115
+			if (--i == 0) {				/* ... until key >25ms pressed */		\
116
+				flag = 1;				/* set press flag */					\
117
+				i = 1;					/* 1 = key press debounced */			\
118
+				break;															\
119
+			}																	\
120
+		}																		\
121
+	}																			\
122
+	i;									/* return value of Macro */				\
123
+})
124
+
88 125
 int main(void) {
89 126
 	/*
90 127
 		Quick Summary of the jobs main has to do:
@@ -142,10 +179,10 @@ int main(void) {
142 179
 			serialHandler((char)(serialGet()));
143 180
 		}
144 181
 
145
-		if ((getSystemTime() - lastButtonCheck) >= 150) { // Check button state every 150ms
182
+		//if ((getSystemTime() - lastButtonCheck) >= 150) { // Check button state every 150ms
146 183
 			audioModeSelected();
147
-			lastButtonCheck = getSystemTime();
148
-		}
184
+		//	lastButtonCheck = getSystemTime();
185
+		//}
149 186
 
150 187
 		if (lastButtonState == 0) {
151 188
 			// Display animations, stored or built-in
@@ -224,8 +261,7 @@ void init(void) {
224 261
 
225 262
 uint8_t audioModeSelected(void) {
226 263
 	// Pushbutton: PB0, Low active
227
-
228
-	if (!(PINB & (1 << PB0))) {
264
+	if (debounce(PINB, PB0)) {
229 265
 		// Button pushed
230 266
 		if (lastButtonState < (maxButtonState - 1)) {
231 267
 			lastButtonState++;

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


+ 33
- 7
CubeFirmware/visualizer.c View File

@@ -36,17 +36,18 @@
36 36
 uint8_t maxVal(uint8_t data, uint8_t log);
37 37
 void setRow(uint8_t x, uint8_t z, uint8_t height, uint8_t *buf);
38 38
 uint8_t average(uint8_t *data);
39
-void filterData(uint8_t *data);
39
+void filterData(uint8_t *data, uint8_t log);
40 40
 void simpleVisualization(uint8_t *data);
41 41
 void fullDepthVisualization(uint8_t *data);
42 42
 void horribleWave(uint8_t *audioData);
43 43
 void simpleLog(uint8_t *data);
44 44
 void fullDepthLog(uint8_t *data);
45
+void linLog(uint8_t *data);
45 46
 
46
-#define NUMOFVISUALIZATIONS 5
47
+#define NUMOFVISUALIZATIONS 6
47 48
 void (*visualizations[NUMOFVISUALIZATIONS])(uint8_t *data) = { &simpleVisualization,
48 49
 													&fullDepthVisualization, &horribleWave,
49
-													&simpleLog, &fullDepthLog };
50
+													&simpleLog, &fullDepthLog, &linLog };
50 51
 uint8_t logScale[8] = { 2, 4, 8, 16, 31, 63, 125, 250 }; // --> ca. (1 << (led + 1));
51 52
 
52 53
 uint8_t numberOfVisualizations(void) {
@@ -55,8 +56,13 @@ uint8_t numberOfVisualizations(void) {
55 56
 
56 57
 void runVisualization(uint8_t *data, uint8_t id) {
57 58
 	if (id < NUMOFVISUALIZATIONS) {
58
-		filterData(data);
59
-		visualizations[id](data);
59
+		if ((id <= 5) && (id > 2)) {
60
+			filterData(data, 1);
61
+			visualizations[id](data);
62
+		} else {
63
+			filterData(data, 0);
64
+			visualizations[id](data);
65
+		}
60 66
 	}
61 67
 }
62 68
 
@@ -81,9 +87,15 @@ uint8_t average(uint8_t *data) {
81 87
 	return (uint8_t)sum;
82 88
 }
83 89
 
84
-void filterData(uint8_t *data) {
90
+void filterData(uint8_t *data, uint8_t log) {
85 91
 	uint8_t i;
86
-	if (average(data) < THRESHOLD) {
92
+	uint8_t max;
93
+	if (log) {
94
+		max = THRESHOLD / 2;
95
+	} else {
96
+		max = THRESHOLD;
97
+	}
98
+	if (average(data) < max) {
87 99
 		for (i = 0; i < 7; i++) {
88 100
 			data[i] = 0;
89 101
 		}
@@ -129,6 +141,20 @@ void simpleVisualization(uint8_t *data) {
129 141
 	buffFree(buff);
130 142
 }
131 143
 
144
+void linLog(uint8_t *data) {
145
+	uint8_t *buff;
146
+	buff = buffNew();
147
+
148
+	buffClearAllPixels(buff);
149
+
150
+	simpleVUMeter(data, buff, 2, 1);
151
+	filterData(data, 0);
152
+	simpleVUMeter(data, buff, 5, 0);
153
+
154
+	setImage(buff);
155
+	buffFree(buff);
156
+}
157
+
132 158
 void fullDepthLog(uint8_t *data) {
133 159
 	uint8_t *buff;
134 160
 	uint8_t i;

Loading…
Cancel
Save