From 045b432d2b2bb8accd36080f3e501be60ff32782 Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Sat, 10 Aug 2013 19:01:48 -0700 Subject: [PATCH] Make panda mappings a bit safer --- _Mappings.pde | 17 ++++++++++++++--- _PandaDriver.pde | 14 +++----------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/_Mappings.pde b/_Mappings.pde index 3959846..00e9b2c 100644 --- a/_Mappings.pde +++ b/_Mappings.pde @@ -162,12 +162,23 @@ class SCMapping implements GLucose.Mapping { class PandaMapping { + // How many channels are on the panda board + public final static int CHANNELS_PER_BOARD = 8; + + // How many cubes per channel xc_PB is configured for + public final static int CUBES_PER_CHANNEL = 4; + final String ip; - final int[][] channelList; + final int[][] channelList = new int[CHANNELS_PER_BOARD][CUBES_PER_CHANNEL]; - PandaMapping(String ip, int[][] channelList) { + PandaMapping(String ip, int[][] rawChannelList) { this.ip = ip; - this.channelList = channelList; + for (int chi = 0; chi < CHANNELS_PER_BOARD; ++chi) { + int[] cubes = (chi < rawChannelList.length) ? rawChannelList[chi] : new int[]{}; + for (int cui = 0; cui < CUBES_PER_CHANNEL; ++cui) { + channelList[chi][cui] = (cui < cubes.length) ? cubes[cui] : 0; + } + } } } diff --git a/_PandaDriver.pde b/_PandaDriver.pde index d90613e..c95f9b0 100644 --- a/_PandaDriver.pde +++ b/_PandaDriver.pde @@ -31,12 +31,6 @@ 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, UDP related? @@ -54,15 +48,13 @@ public class PandaDriver { public void toggle() { enabled = !enabled; - println("PandaBoard Output/" + ip + ": " + (enabled ? "ON" : "OFF")); + println("PandaBoard/" + ip + ": " + (enabled ? "ON" : "OFF")); } private ArrayList buildMappedList(Model model, int[][] channelList) { ArrayList points = new ArrayList(); - 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; + for (int[] channel : channelList) { + for (int cubeNumber : channel) { if (cubeNumber == 0) { for (int i = 0; i < Cube.POINTS_PER_CUBE; ++i) { points.add(0); -- 2.34.1