浏览代码

Old wave visualization is back.

Finally, the moment you all long awaited :)
Thomas Buck 12 年前
父节点
当前提交
be09e27b10
共有 2 个文件被更改,包括 606 次插入409 次删除
  1. 503
    405
      CubeFirmware/main.hex
  2. 103
    4
      CubeFirmware/visualizer.c

+ 503
- 405
CubeFirmware/main.hex
文件差异内容过多而无法显示
查看文件


+ 103
- 4
CubeFirmware/visualizer.c 查看文件

@@ -27,13 +27,19 @@
27 27
 #include <cube.h>
28 28
 #include <buffhelp.h>
29 29
 
30
+#define FACTOR 31   // 8 LEDs, Max Val 255:
31
+					// 256 / 8 = 32 => Divide by 31 (FACTOR) to get num of leds to light
32
+					// 255 / FACTOR = 8,...
33
+					// 127 / FACTOR = 4,...
34
+
30 35
 void simpleVisualization(uint8_t *data);
31 36
 void fullDepthVisualization(uint8_t *data);
37
+void horribleWave(uint8_t *audioData);
32 38
 
33
-#define NUMOFVISUALIZATIONS 2
39
+#define NUMOFVISUALIZATIONS 3
34 40
 
35 41
 void (*visualizations[NUMOFVISUALIZATIONS])(uint8_t *data) = { &simpleVisualization,
36
-													&fullDepthVisualization };
42
+													&fullDepthVisualization, &horribleWave };
37 43
 
38 44
 uint8_t numberOfVisualizations(void) {
39 45
 	return NUMOFVISUALIZATIONS;
@@ -47,7 +53,7 @@ void runVisualization(uint8_t *data, uint8_t id) {
47 53
 void simpleVUMeter(uint8_t *data, uint8_t *buff, uint8_t z) {
48 54
 	uint8_t i, h, max;
49 55
 	for(i = 0; i < 7; i++) {
50
-		max = data[i] / 31;
56
+		max = data[i] / FACTOR;
51 57
 		for (h = 0; h < max; h++) {
52 58
 			if (i == 0) {
53 59
 				buffSetPixel(buff, i, h / 2, z);
@@ -82,4 +88,97 @@ void fullDepthVisualization(uint8_t *data) {
82 88
 
83 89
 	setImage(buff);
84 90
 	buffFree(buff);
85
-}
91
+}
92
+
93
+void setPixelBuffer(uint8_t x, uint8_t y, uint8_t z, uint8_t *buf) {
94
+	buf[(8 * (7 - z)) + (7 - y)] |= (1 << x); // z is inverted for beauty reasons
95
+}
96
+
97
+void setRow(uint8_t x, uint8_t z, uint8_t height, uint8_t *buf) {
98
+	uint8_t i = 0;
99
+	for (; i < height; i++) {
100
+		setPixelBuffer(x, i, z, buf);
101
+	}
102
+}
103
+
104
+void horribleWave(uint8_t *audioData) {
105
+	uint8_t *imageData = buffNew();
106
+	
107
+	buffClearAllPixels(imageData);
108
+
109
+	// Could not figure out a way to represent this easily in a loop
110
+	// without using a shitload of 'if's...
111
+	setRow(0, 0, (audioData[0] / FACTOR), imageData);
112
+	setRow(0, 1, (audioData[0] / FACTOR), imageData);
113
+	setRow(1, 0, (audioData[0] / FACTOR), imageData);
114
+
115
+	setRow(0, 2, (audioData[1] / FACTOR), imageData);
116
+	setRow(0, 3, (audioData[1] / FACTOR), imageData);
117
+	setRow(1, 1, (audioData[1] / FACTOR), imageData);
118
+	setRow(1, 2, (audioData[1] / FACTOR), imageData);
119
+	setRow(2, 0, (audioData[1] / FACTOR), imageData);
120
+	setRow(2, 1, (audioData[1] / FACTOR), imageData);
121
+
122
+	setRow(0, 4, (audioData[2] / FACTOR), imageData);
123
+	setRow(0, 5, (audioData[2] / FACTOR), imageData);
124
+	setRow(1, 3, (audioData[2] / FACTOR), imageData);
125
+	setRow(1, 4, (audioData[2] / FACTOR), imageData);
126
+	setRow(2, 2, (audioData[2] / FACTOR), imageData);
127
+	setRow(2, 3, (audioData[2] / FACTOR), imageData);
128
+	setRow(3, 0, (audioData[2] / FACTOR), imageData);
129
+	setRow(3, 1, (audioData[2] / FACTOR), imageData);
130
+	setRow(3, 2, (audioData[2] / FACTOR), imageData);
131
+	setRow(4, 0, (audioData[2] / FACTOR), imageData);
132
+	setRow(4, 1, (audioData[2] / FACTOR), imageData);
133
+
134
+	setRow(0, 6, (audioData[3] / FACTOR), imageData);
135
+	setRow(0, 7, (audioData[3] / FACTOR), imageData);
136
+	setRow(1, 5, (audioData[3] / FACTOR), imageData);
137
+	setRow(1, 6, (audioData[3] / FACTOR), imageData);
138
+	setRow(2, 4, (audioData[3] / FACTOR), imageData);
139
+	setRow(2, 5, (audioData[3] / FACTOR), imageData);
140
+	setRow(3, 3, (audioData[3] / FACTOR), imageData);
141
+	setRow(3, 4, (audioData[3] / FACTOR), imageData);
142
+	setRow(4, 2, (audioData[3] / FACTOR), imageData);
143
+	setRow(4, 3, (audioData[3] / FACTOR), imageData);
144
+	setRow(5, 0, (audioData[3] / FACTOR), imageData);
145
+	setRow(5, 1, (audioData[3] / FACTOR), imageData);
146
+	setRow(5, 2, (audioData[3] / FACTOR), imageData);
147
+	setRow(6, 0, (audioData[3] / FACTOR), imageData);
148
+	setRow(6, 1, (audioData[3] / FACTOR), imageData);
149
+
150
+	setRow(1, 7, (audioData[4] / FACTOR), imageData);
151
+	setRow(2, 6, (audioData[4] / FACTOR), imageData);
152
+	setRow(2, 7, (audioData[4] / FACTOR), imageData);
153
+	setRow(3, 5, (audioData[4] / FACTOR), imageData);
154
+	setRow(3, 6, (audioData[4] / FACTOR), imageData);
155
+	setRow(4, 4, (audioData[4] / FACTOR), imageData);
156
+	setRow(4, 5, (audioData[4] / FACTOR), imageData);
157
+	setRow(5, 3, (audioData[4] / FACTOR), imageData);
158
+	setRow(5, 4, (audioData[4] / FACTOR), imageData);
159
+	setRow(6, 2, (audioData[4] / FACTOR), imageData);
160
+	setRow(6, 3, (audioData[4] / FACTOR), imageData);
161
+	setRow(7, 0, (audioData[4] / FACTOR), imageData);
162
+	setRow(7, 1, (audioData[4] / FACTOR), imageData);
163
+
164
+	setRow(3, 7, (audioData[5] / FACTOR), imageData);
165
+	setRow(4, 6, (audioData[5] / FACTOR), imageData);
166
+	setRow(4, 7, (audioData[5] / FACTOR), imageData);
167
+	setRow(5, 5, (audioData[5] / FACTOR), imageData);
168
+	setRow(5, 6, (audioData[5] / FACTOR), imageData);
169
+	setRow(6, 4, (audioData[5] / FACTOR), imageData);
170
+	setRow(6, 5, (audioData[5] / FACTOR), imageData);
171
+	setRow(7, 2, (audioData[5] / FACTOR), imageData);
172
+	setRow(7, 3, (audioData[5] / FACTOR), imageData);
173
+	setRow(7, 4, (audioData[5] / FACTOR), imageData);
174
+
175
+	setRow(5, 7, (audioData[6] / FACTOR), imageData);
176
+	setRow(6, 6, (audioData[6] / FACTOR), imageData);
177
+	setRow(6, 7, (audioData[6] / FACTOR), imageData);
178
+	setRow(7, 5, (audioData[6] / FACTOR), imageData);
179
+	setRow(7, 6, (audioData[6] / FACTOR), imageData);
180
+	setRow(7, 7, (audioData[6] / FACTOR), imageData);
181
+
182
+	setImage(imageData);
183
+	buffFree(imageData);
184
+}

正在加载...
取消
保存