From: Mark Slee Date: Sun, 11 Aug 2013 02:23:13 +0000 (-0700) Subject: Update panda output code to be a touch more sane X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=44b8de9cba6ddf1ed0e057fa5e53710e83d7a932;p=SugarCubes.git Update panda output code to be a touch more sane --- diff --git a/_Internals.pde b/_Internals.pde index 82feb2d..3d736ba 100644 --- a/_Internals.pde +++ b/_Internals.pde @@ -95,7 +95,7 @@ void setup() { pandaBoards = new PandaDriver[pandaMappings.length]; int pbi = 0; for (PandaMapping pm : pandaMappings) { - pandaBoards[pbi++] = new PandaDriver(pm.ip, glucose.model, pm.channelList); + pandaBoards[pbi++] = new PandaDriver(pm.ip, glucose.model, pm); } mappingTool = new MappingTool(glucose, pandaMappings); logTime("Built PandaDriver"); diff --git a/_Mappings.pde b/_Mappings.pde index 00e9b2c..56be1b1 100644 --- a/_Mappings.pde +++ b/_Mappings.pde @@ -168,6 +168,12 @@ class PandaMapping { // How many cubes per channel xc_PB is configured for public final static int CUBES_PER_CHANNEL = 4; + // How many total pixels on each channel + public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL; + + // How many total pixels on the whole board + public final static int PIXELS_PER_BOARD = PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD; + final String ip; final int[][] channelList = new int[CHANNELS_PER_BOARD][CUBES_PER_CHANNEL]; diff --git a/_PandaDriver.pde b/_PandaDriver.pde index c95f9b0..e62cfff 100644 --- a/_PandaDriver.pde +++ b/_PandaDriver.pde @@ -30,34 +30,44 @@ public class PandaDriver { // List of point indices on the board private final int[] points; - + // Packet data private final byte[] packet = new byte[4*352]; // TODO: de-magic-number, UDP related? - public PandaDriver(String ip, Model model, int[][] channelList) { + public PandaDriver(String ip) { this.ip = ip; this.address = new NetAddress(ip, 9001); message = new OscMessage("/shady/pointbuffer"); - List pointList = buildMappedList(model, channelList); - points = new int[pointList.size()]; - int i = 0; - for (int value : pointList) { - points[i++] = value; + points = new int[PandaMapping.PIXELS_PER_BOARD]; + for (int i = 0; i < points.length; ++i) { + points[i] = 0; + } + } + + public PandaDriver(String ip, int[] pointList) { + this(ip); + for (int i = 0; i < pointList.length && i < points.length; ++i) { + this.points[i] = pointList[i]; } } + + public PandaDriver(String ip, Model model, PandaMapping pm) { + this(ip); + buildPointList(model, pm); + } public void toggle() { enabled = !enabled; println("PandaBoard/" + ip + ": " + (enabled ? "ON" : "OFF")); } - private ArrayList buildMappedList(Model model, int[][] channelList) { - ArrayList points = new ArrayList(); - for (int[] channel : channelList) { + private void buildPointList(Model model, PandaMapping pm) { + int pi = 0; + for (int[] channel : pm.channelList) { for (int cubeNumber : channel) { - if (cubeNumber == 0) { + if (cubeNumber <= 0) { for (int i = 0; i < Cube.POINTS_PER_CUBE; ++i) { - points.add(0); + points[pi++] = 0; } } else { Cube cube = model.getCubeByRawIndex(cubeNumber); @@ -70,13 +80,12 @@ public class PandaDriver { for (int stripIndex : stripOrder) { Strip s = cube.strips.get(stripIndex); for (int j = s.points.size() - 1; j >= 0; --j) { - points.add(s.points.get(j).index); + points[pi++] = s.points.get(j).index; } } } } } - return points; } public final void send(int[] colors) {