Commit | Line | Data |
---|---|---|
1ecdb44a MS |
1 | /** |
2 | * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND | |
3 | * | |
4 | * //\\ //\\ //\\ //\\ | |
5 | * ///\\\ ///\\\ ///\\\ ///\\\ | |
6 | * \\\/// \\\/// \\\/// \\\/// | |
7 | * \\// \\// \\// \\// | |
8 | * | |
9 | * EXPERTS ONLY!! EXPERTS ONLY!! | |
10 | * | |
186bc4d3 | 11 | * This file implements the mapping functions needed to lay out the physical |
1ecdb44a MS |
12 | * cubes and the output ports on the panda board. It should only be modified |
13 | * when physical changes or tuning is being done to the structure. | |
14 | */ | |
45f43cc2 | 15 | |
cc9e8c8b BM |
16 | import java.util.Arrays; |
17 | ||
270a8b44 MS |
18 | final int MaxCubeHeight = 6; |
19 | final int NumBackTowers = 16; | |
20 | ||
f0cc0ba5 MS |
21 | public Model buildModel() { |
22 | ||
f0cc0ba5 MS |
23 | // Shorthand helpers for specifying wiring more quickly |
24 | final Cube.Wiring WFL = Cube.Wiring.FRONT_LEFT; | |
25 | final Cube.Wiring WFR = Cube.Wiring.FRONT_RIGHT; | |
26 | final Cube.Wiring WRL = Cube.Wiring.REAR_LEFT; | |
27 | final Cube.Wiring WRR = Cube.Wiring.REAR_RIGHT; | |
95c50032 | 28 | |
a3ccf23a | 29 | // Utility value if you need the height of a cube shorthand |
95c50032 | 30 | final float CH = Cube.EDGE_HEIGHT; |
73687629 | 31 | final float CW = Cube.EDGE_WIDTH ; |
ae579223 | 32 | |
a3ccf23a | 33 | // Positions for the bass box |
ae579223 MS |
34 | final float BBY = BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH; |
35 | final float BBX = 56; | |
36 | final float BBZ = 2; | |
37 | ||
46fc29d4 MS |
38 | // The model is represented as an array of towers. The cubes in the tower |
39 | // are represenented relatively. Each tower has an x, y, z reference position, | |
40 | // which is typically the base cube's bottom left corner. | |
41 | // | |
42 | // Following that is an array of floats. A 2-d array contains an x-offset | |
f0cc0ba5 MS |
43 | // and a z-offset from the previous reference position. Typically the first cube |
44 | // will just be {0, 0}. Each successive cube uses the position of the previous | |
45 | // cube as its reference. | |
46fc29d4 MS |
46 | // |
47 | // A 3-d array contains an x-offset, a z-offset, and a rotation about the | |
48 | // y-axis. | |
49 | // | |
50 | // The cubes automatically increment their y-position by Cube.EDGE_HEIGHT. | |
e27a8652 | 51 | |
73687629 | 52 | // To-Do: (Mark Slee, Alex Green, or Ben Morrow): The Cube # is determined by the order in this list. |
53 | // "raw object index" is serialized by running through towermapping and then individual cube mapping below. | |
54 | // We can do better than this. The raw object index should be obvious from the code-- looking through the | |
55 | // rendered simulation and counting through cubes in mapping mode is grossly inefficient. | |
e28f168c | 56 | |
73687629 | 57 | TowerMapping[] towerCubes = new TowerMapping[] {}; |
f0cc0ba5 MS |
58 | |
59 | // Single cubes can be constructed directly here if you need them | |
60 | Cube[] singleCubes = new Cube[] { | |
bf1fe2d4 | 61 | // new Cube(15, int( Cube.EDGE_HEIGHT), 39, 0, 10, 0, WRL), // Back left channel behind speaker |
f1370a0b | 62 | //new Cube(x, y, z, rx, ry, rz, wiring), |
bf1fe2d4 | 63 | //new Cube(0,0,0,0,225,0, WRR), |
f0cc0ba5 MS |
64 | }; |
65 | ||
66 | // The bass box! | |
73687629 | 67 | // BassBox bassBox = BassBox.unlitBassBox(BBX, 0, BBZ); // frame exists, no lights |
68 | BassBox bassBox = BassBox.noBassBox(); // no bass box at all | |
e89eda9f | 69 | // BassBox bassBox = new BassBox(BBX, 0, BBZ); // bass box with lights |
e28f168c | 70 | |
f0cc0ba5 | 71 | // The speakers! |
3b2e0b4a MS |
72 | List<Speaker> speakers = Arrays.asList(new Speaker[] { |
73 | // Each speaker parameter is x, y, z, rotation, the left speaker comes first | |
73687629 | 74 | // new Speaker(TRAILER_WIDTH - Speaker.EDGE_WIDTH + 8, 6, 3, -15) |
3b2e0b4a | 75 | }); |
f0cc0ba5 | 76 | |
bf1fe2d4 MS |
77 | |
78 | //////////////////////////////////////////////////////////////////////// | |
79 | // dan's proposed lattice | |
80 | ArrayList<StaggeredTower> scubes = new ArrayList<StaggeredTower>(); | |
3fa45e9e AG |
81 | //if (NumBackTowers != 25) exit(); |
82 | for (int i=0; i<NumBackTowers/2; i++) scubes.add(new StaggeredTower( | |
83 | (i+1)*CW, // x | |
84 | (i % 2 == 0) ? 0 : CH * 2./3. , // y | |
270a8b44 MS |
85 | - ((i % 2 == 0) ? 11 : 0) + 80 , // z |
86 | -45, (i % 2 == 0) ? MaxCubeHeight : MaxCubeHeight) ); // num cubes | |
bf1fe2d4 | 87 | |
270a8b44 MS |
88 | // for (int i=0; i<NumBackTowers/2; i++) scubes.add(new StaggeredTower( |
89 | // (i+1)*CW, // x | |
90 | // (i % 2 == 0) ? 0 : CH * 2./3. , // y | |
91 | // - ((i % 2 == 0) ? 0 : 11) + 80 - pow(CH*CH + CW*CW, .5), // z | |
92 | // 225, (i % 2 == 0) ? MaxCubeHeight : MaxCubeHeight-1) ); | |
e0cfbe20 AG |
93 | |
94 | // for (int i=0; i<2 ; i++) scubes.add(new StaggeredTower( | |
95 | // (i+1)*CW, // x | |
96 | // 0 , // y | |
97 | // - 0 + 97 - 2*pow(CH*CH + CW*CW, .5), // z | |
98 | // 225, MaxCubeHeight ) ); | |
99 | ||
bf1fe2d4 MS |
100 | ArrayList<Cube> dcubes = new ArrayList<Cube>(); |
101 | // for (int i=1; i<6; i++) { | |
102 | // if (i>1) dcubes.add(new Cube(-6+CW*4/3*i , 0, 0, 0, 0, 0, WRR)); | |
103 | // dcubes.add(new Cube(-6+CW*4/3*i+CW*2/3., CH*.5, 0, 0, 0, 0, WRR)); | |
104 | // } | |
105 | ||
a981ea46 | 106 | float current_x_position = 0; |
3fa45e9e AG |
107 | // scubes.add(new StaggeredTower(//tower 1 |
108 | // current_x_position, // x | |
109 | // 15 , // y | |
110 | // 0 , // z | |
111 | // 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) ); | |
112 | // current_x_position += 25.25; | |
113 | // scubes.add(new StaggeredTower(// tower 2 | |
114 | // current_x_position, // x | |
115 | // 0 , // y | |
116 | // -10.5 , // z | |
117 | // 45, 6, new Cube.Wiring[] { WFR, WFL, WRR, WRR, WFL, WRR}) ); | |
118 | // current_x_position += 25.25; | |
119 | // scubes.add(new StaggeredTower(//tower 3 | |
120 | // current_x_position, // x | |
121 | // 15 , // y | |
122 | // 0, // z | |
123 | // 45, 6, new Cube.Wiring[] { WRR, WFL, WRR, WRR, WFL, WRR}) ); | |
124 | // current_x_position += 25.25; | |
125 | // scubes.add(new StaggeredTower(//tower 4 | |
126 | // current_x_position, // x | |
127 | // 0, // y | |
128 | // -10.5 , // z | |
129 | // 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) ); | |
130 | // current_x_position += 28; | |
131 | // scubes.add(new StaggeredTower(//tower 5 | |
132 | // current_x_position, // x | |
133 | // 15 , // y | |
134 | // -4.5 , // z | |
135 | // 45, 6, new Cube.Wiring[] { WRR, WFL, WRR, WFL, WRR, WFL}) ); | |
136 | // current_x_position += 28; | |
137 | // scubes.add(new StaggeredTower(//tower 6 | |
138 | // current_x_position, // x | |
139 | // 0 , // y | |
140 | // -10.5, // z | |
141 | // 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) ); | |
142 | // current_x_position += 25.25; | |
143 | // scubes.add(new StaggeredTower(// tower 7 | |
144 | // current_x_position, // x | |
145 | // 15 , // y | |
146 | // 0, // z | |
147 | // 45, 6, new Cube.Wiring[] { WRR, WFL, WRR, WFL, WRR, WFL}) ); | |
148 | // current_x_position += 25.25; | |
149 | // scubes.add(new StaggeredTower(//tower 8 | |
150 | // current_x_position, // x | |
151 | // 0 , // y | |
152 | // -10.5 , // z | |
153 | // 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) ); | |
154 | // current_x_position += 25.25; | |
155 | // scubes.add(new StaggeredTower(//tower 9 | |
156 | // current_x_position, // x | |
157 | // 15 , // y | |
158 | // 0, // z | |
159 | // 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) ); | |
160 | // current_x_position += 25.25; | |
161 | ||
162 | // //TOWERS ON DANCE FLOOR | |
163 | // scubes.add(new StaggeredTower(//tower 10 | |
164 | // 83.75+39+43-124.5, // x | |
165 | // 0, // y | |
166 | // -47.5-43, // z | |
167 | // 45, 4, new Cube.Wiring[]{ WRR, WFL, WFL, WRR}) ); | |
168 | // scubes.add(new StaggeredTower(//tower 11 | |
169 | // 83.75, // x | |
170 | // 0, // y | |
171 | // -47.5, // z | |
172 | // 45, 4, new Cube.Wiring[]{ WFL, WRR, WRR, WFL}) ); | |
173 | // scubes.add(new StaggeredTower(//tower 12 | |
174 | // 83.75+39, // x | |
175 | // 0, // y | |
176 | // -47.5, // z | |
177 | // 45, 4, new Cube.Wiring[]{ WRR, WFL, WFL, WRR}) ); | |
178 | // scubes.add(new StaggeredTower(//tower 13 | |
179 | // 83.75+39+43, // x | |
180 | // 0, // y | |
181 | // -47.5-43, // z | |
182 | // 45, 4, new Cube.Wiring[]{ WFL, WRR, WFL, WRR}) ); | |
d93dc84a | 183 | |
a981ea46 AK |
184 | // scubes.add(new StaggeredTower(// Single cube on top of tower 4 |
185 | // 42, // x | |
186 | // 112 , // y | |
187 | // 72, // z | |
188 | // -10, 1, new Cube.Wiring[]{ WRL}) ); | |
bf1fe2d4 MS |
189 | |
190 | ||
191 | ||
192 | ||
193 | ||
194 | ||
195 | ||
a3ccf23a MS |
196 | ////////////////////////////////////////////////////////////////////// |
197 | // BENEATH HERE SHOULD NOT REQUIRE ANY MODIFICATION!!!! // | |
198 | ////////////////////////////////////////////////////////////////////// | |
199 | ||
f0cc0ba5 | 200 | // These guts just convert the shorthand mappings into usable objects |
46fc29d4 MS |
201 | ArrayList<Tower> towerList = new ArrayList<Tower>(); |
202 | ArrayList<Cube> tower; | |
3fa45e9e | 203 | Cube[] cubes = new Cube[200]; |
46fc29d4 | 204 | int cubeIndex = 1; |
f0cc0ba5 MS |
205 | float px, pz, ny; |
206 | for (TowerMapping tm : towerCubes) { | |
207 | px = tm.x; | |
208 | ny = tm.y; | |
209 | pz = tm.z; | |
46fc29d4 | 210 | tower = new ArrayList<Cube>(); |
f0cc0ba5 MS |
211 | for (CubeMapping cm : tm.cubeMappings) { |
212 | tower.add(cubes[cubeIndex++] = new Cube(px = px + cm.dx, ny, pz = pz + cm.dz, 0, cm.ry, 0, cm.wiring)); | |
213 | ny += Cube.EDGE_HEIGHT; | |
46fc29d4 MS |
214 | } |
215 | towerList.add(new Tower(tower)); | |
216 | } | |
73687629 | 217 | |
f1370a0b | 218 | |
cd1c3313 MS |
219 | for (Cube cube : singleCubes) { |
220 | cubes[cubeIndex++] = cube; | |
221 | } | |
222 | for (Cube cube : dcubes) { | |
223 | cubes[cubeIndex++] = cube; | |
224 | } | |
270a8b44 | 225 | for (StaggeredTower st : scubes) { |
73687629 | 226 | tower = new ArrayList<Cube>(); |
bf1fe2d4 MS |
227 | for (int i=0; i < st.n; i++) { |
228 | Cube.Wiring w = (i < st.wiring.length) ? st.wiring[i] : WRR; | |
229 | tower.add(cubes[cubeIndex++] = new Cube(st.x, st.y + CH* 4/3.*i, st.z, 0, st.r, 0, w)); | |
230 | } | |
73687629 | 231 | towerList.add(new Tower(tower)); |
2bb56822 | 232 | } |
e76480d4 | 233 | |
7dceead9 | 234 | return new Model(towerList, cubes, bassBox, speakers); |
186bc4d3 | 235 | } |
e73ef85d | 236 | |
a3ccf23a MS |
237 | /** |
238 | * This function maps the panda boards. We have an array of them, each has | |
239 | * an IP address and a list of channels. | |
240 | */ | |
186bc4d3 | 241 | public PandaMapping[] buildPandaList() { |
1d75c8a9 MS |
242 | final int LEFT_SPEAKER = 0; |
243 | final int RIGHT_SPEAKER = 1; | |
244 | ||
3b2e0b4a | 245 | // 8 channels map to: 3, 4, 7, 8, 13, 14, 15, 16. |
186bc4d3 | 246 | return new PandaMapping[] { |
bf1fe2d4 MS |
247 | new PandaMapping( |
248 | "10.200.1.28", new ChannelMapping[] { | |
270a8b44 MS |
249 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37, 38, 39 }), |
250 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
251 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 43, 44, 45 }), | |
252 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 46, 47, 48 }), | |
253 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // new front thing | |
254 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // new back thing | |
255 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 13, 14, 15 }), // new back thing | |
bf1fe2d4 | 256 | }), |
df18145f AG |
257 | new PandaMapping( |
258 | "10.200.1.29", new ChannelMapping[] { | |
270a8b44 MS |
259 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 19, 20, 21 }), |
260 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
261 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3 }), | |
262 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4, 5, 6 }), | |
263 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7, 8, 9 }), | |
cd1c3313 | 264 | |
270a8b44 MS |
265 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 10, 11, 12 }), |
266 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 16, 17, 18 }), | |
267 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 34, 35, 36}), | |
268 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
269 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 19, 20, 21}), | |
270 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 22, 23, 24}), | |
271 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 25, 26, 27}), | |
272 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 28, 29, 30}), | |
273 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 31, 32, 33}), | |
274 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
df18145f AG |
275 | }), |
276 | new PandaMapping( | |
277 | "10.200.1.30", new ChannelMapping[] { | |
270a8b44 MS |
278 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 40, 41, 42 }), |
279 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
280 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 22, 23, 24 }), | |
281 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 25, 26, 27 }), | |
282 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 28, 29, 30 }), | |
283 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 31, 32, 33 }), | |
284 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 34, 35, 36 }), | |
285 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1,1}), // 30 J3 * | |
286 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1,1}), // 30 J4 //ORIG * | |
287 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37, 38, 39}), // 30 J7 * | |
288 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 40, 41, 42}), // 30 J8 * | |
289 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 43, 44, 45}), // 30 J13 (not working) | |
290 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 46, 47, 48}), // 30 J14 (unplugged) | |
291 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 49, 50, 51}), // 30 J15 (unplugged) | |
292 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 52, 53, 54}), // 30 J16 | |
df18145f | 293 | }), |
270a8b44 MS |
294 | // new PandaMapping( |
295 | // "10.200.1.31", new ChannelMapping[] { | |
296 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 65, 66}), // J3 | |
297 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1}), // J4 | |
298 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 55, 56}), // 30 J7 | |
299 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 57, 58}), // J8 | |
300 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 59, 60}), // J13 | |
301 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 61, 62}), // 30 J14 | |
302 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 63, 64}), // J15 | |
303 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1}), // J16 | |
304 | // }), | |
305 | ||
1a92d73a AG |
306 | // new PandaMapping( |
307 | // "10.200.1.32", new ChannelMapping[] { | |
308 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J3 | |
309 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J4 | |
310 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 67, 68}), // 30 J7 | |
311 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 69, 70}), // J8 | |
312 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J13 | |
313 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J14 | |
314 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J15 | |
315 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J16 | |
316 | // }), | |
3b2e0b4a | 317 | }; |
45f43cc2 | 318 | } |
e73ef85d | 319 | |
f0cc0ba5 MS |
320 | class TowerMapping { |
321 | public final float x, y, z; | |
322 | public final CubeMapping[] cubeMappings; | |
323 | ||
324 | TowerMapping(float x, float y, float z, CubeMapping[] cubeMappings) { | |
325 | this.x = x; | |
326 | this.y = y; | |
327 | this.z = z; | |
328 | this.cubeMappings = cubeMappings; | |
329 | } | |
330 | } | |
331 | ||
332 | class CubeMapping { | |
333 | public final float dx, dz, ry; | |
334 | public final Cube.Wiring wiring; | |
335 | ||
336 | CubeMapping(float dx, float dz, Cube.Wiring wiring) { | |
73687629 | 337 | this(dx, dz, 0., wiring); |
f0cc0ba5 | 338 | } |
f0cc0ba5 MS |
339 | CubeMapping(float dx, float dz, float ry) { |
340 | this(dz, dz, ry, Cube.Wiring.FRONT_LEFT); | |
341 | } | |
342 | ||
343 | CubeMapping(float dx, float dz, float ry, Cube.Wiring wiring) { | |
344 | this.dx = dx; | |
345 | this.dz = dz; | |
346 | this.ry = ry; | |
347 | this.wiring = wiring; | |
348 | } | |
349 | } | |
350 | ||
73687629 | 351 | class StaggeredTower { |
352 | public final float x, y, z, r; | |
353 | public final int n; | |
bf1fe2d4 MS |
354 | public final Cube.Wiring[] wiring; |
355 | StaggeredTower(float _x, float _y, float _z, float _r, int _n) { this(_x, _y, _z, _r, _n, new Cube.Wiring[]{}); } | |
356 | StaggeredTower(float _x, float _y, float _z, float _r, int _n, Cube.Wiring[] _wiring) { x=_x; y=_y; z=_z; r=_r; n=_n; wiring=_wiring;} | |
73687629 | 357 | } |
358 | ||
a922e963 MS |
359 | /** |
360 | * Each panda board has an IP address and a fixed number of channels. The channels | |
361 | * each have a fixed number of pixels on them. Whether or not that many physical | |
362 | * pixels are connected to the channel, we still send it that much data. | |
363 | */ | |
45f43cc2 MS |
364 | class PandaMapping { |
365 | ||
045b432d | 366 | // How many channels are on the panda board |
e28f168c | 367 | public final static int CHANNELS_PER_BOARD = 8; |
045b432d | 368 | |
44b8de9c | 369 | // How many total pixels on the whole board |
84086fa3 | 370 | public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD; |
44b8de9c | 371 | |
45f43cc2 | 372 | final String ip; |
84086fa3 | 373 | final ChannelMapping[] channelList = new ChannelMapping[CHANNELS_PER_BOARD]; |
45f43cc2 | 374 | |
84086fa3 | 375 | PandaMapping(String ip, ChannelMapping[] rawChannelList) { |
45f43cc2 | 376 | this.ip = ip; |
a922e963 MS |
377 | |
378 | // Ensure our array is the right length and has all valid items in it | |
84086fa3 MS |
379 | for (int i = 0; i < channelList.length; ++i) { |
380 | channelList[i] = (i < rawChannelList.length) ? rawChannelList[i] : new ChannelMapping(); | |
a922e963 MS |
381 | if (channelList[i] == null) { |
382 | channelList[i] = new ChannelMapping(); | |
383 | } | |
045b432d | 384 | } |
e73ef85d | 385 | } |
1ecdb44a MS |
386 | } |
387 | ||
a922e963 | 388 | /** |
e27a8652 | 389 | * Each channel on a pandaboard can be mapped in a number of modes. The typical is |
a922e963 MS |
390 | * to a series of connected cubes, but we also have special mappings for the bass box, |
391 | * the speaker enclosures, and the DJ booth floor. | |
392 | * | |
393 | * This class is just the mapping meta-data. It sanitizes the input to make sure | |
394 | * that the cubes and objects being referenced actually exist in the model. | |
395 | * | |
396 | * The logic for how to encode the pixels is contained in the PandaDriver. | |
397 | */ | |
84086fa3 MS |
398 | class ChannelMapping { |
399 | ||
400 | // How many cubes per channel xc_PB is configured for | |
401 | public final static int CUBES_PER_CHANNEL = 4; | |
45f43cc2 | 402 | |
84086fa3 MS |
403 | // How many total pixels on each channel |
404 | public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL; | |
405 | ||
406 | public static final int MODE_NULL = 0; | |
407 | public static final int MODE_CUBES = 1; | |
408 | public static final int MODE_BASS = 2; | |
409 | public static final int MODE_SPEAKER = 3; | |
1d75c8a9 | 410 | public static final int MODE_STRUTS_AND_FLOOR = 4; |
84086fa3 MS |
411 | public static final int MODE_INVALID = 5; |
412 | ||
413 | public static final int NO_OBJECT = -1; | |
414 | ||
415 | final int mode; | |
416 | final int[] objectIndices = new int[CUBES_PER_CHANNEL]; | |
417 | ||
418 | ChannelMapping() { | |
419 | this(MODE_NULL); | |
420 | } | |
421 | ||
422 | ChannelMapping(int mode) { | |
423 | this(mode, new int[]{}); | |
424 | } | |
425 | ||
426 | ChannelMapping(int mode, int rawObjectIndex) { | |
427 | this(mode, new int[]{ rawObjectIndex }); | |
428 | } | |
429 | ||
430 | ChannelMapping(int mode, int[] rawObjectIndices) { | |
431 | if (mode < 0 || mode >= MODE_INVALID) { | |
432 | throw new RuntimeException("Invalid channel mapping mode: " + mode); | |
433 | } | |
434 | if (mode == MODE_SPEAKER) { | |
435 | if (rawObjectIndices.length != 1) { | |
436 | throw new RuntimeException("Speaker channel mapping mode must specify one speaker index"); | |
437 | } | |
438 | int speakerIndex = rawObjectIndices[0]; | |
439 | if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) { | |
3b2e0b4a | 440 | throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex); |
84086fa3 | 441 | } |
1d75c8a9 | 442 | } else if ((mode == MODE_STRUTS_AND_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) { |
84086fa3 | 443 | if (rawObjectIndices.length > 0) { |
3b2e0b4a | 444 | throw new RuntimeException("Bass/floor/null mappings cannot specify object indices"); |
84086fa3 MS |
445 | } |
446 | } else if (mode == MODE_CUBES) { | |
447 | for (int rawCubeIndex : rawObjectIndices) { | |
448 | if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) { | |
449 | throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex); | |
450 | } | |
451 | } | |
452 | } | |
453 | ||
454 | this.mode = mode; | |
455 | for (int i = 0; i < objectIndices.length; ++i) { | |
456 | objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT; | |
457 | } | |
458 | } | |
2bb56822 | 459 | } |