Fix mapping output to use correct number of channels/cubes no matter what is in mappi...
[SugarCubes.git] / _PandaDriver.pde
index 01b7169c345f49c5ac8aee12b4c27d370fa9050c..5e37ccb6528612bce0d90b560e041a20825bab5a 100644 (file)
@@ -24,9 +24,15 @@ public class PandaDriver {
 
   // List of point indices on the board
   private final int[] points;
+  
+  // How many channels are on the panda board
+  private final static int CHANNELS_PER_BOARD = 8;
+  
+  // How many cubes per channel xc_PB is configured for
+  private final static int CUBES_PER_CHANNEL = 4;
 
   // Packet data
-  private final byte[] packet = new byte[4*352]; // TODO: de-magic-number
+  private final byte[] packet = new byte[4*352]; // TODO: de-magic-number, UDP related?
 
   public PandaDriver(NetAddress address, Model model, int[][] channelList) {
     this.address = address;
@@ -41,8 +47,10 @@ public class PandaDriver {
 
   private ArrayList<Integer> buildMappedList(Model model, int[][] channelList) {
     ArrayList<Integer> points = new ArrayList<Integer>();
-    for (int[] channel : channelList) {
-      for (int cubeNumber : channel) {
+    for (int chi = 0; chi < CHANNELS_PER_BOARD; ++chi) {
+      int[] channel = (chi < channelList.length) ? channelList[chi] : new int[]{};
+      for (int ci = 0; ci < CUBES_PER_CHANNEL; ++ci) {
+        int cubeNumber = (ci < channel.length) ? channel[ci] : 0;
         if (cubeNumber == 0) {
           for (int i = 0; i < (Cube.FACES_PER_CUBE*Face.STRIPS_PER_FACE*Strip.POINTS_PER_STRIP); ++i) {
             points.add(0);