X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=_PandaDriver.pde;h=5e4776455e23f11f52a02c955e577c0ee1855d60;hb=79ae8245d084fe7901933b22a44b404f9d68b925;hp=7fd45c0acc8134d699e25a7293963c47e5129f4b;hpb=e73ef85d13e1f4787bbf2705d294791d268d95b1;p=SugarCubes.git diff --git a/_PandaDriver.pde b/_PandaDriver.pde index 7fd45c0..5e47764 100644 --- a/_PandaDriver.pde +++ b/_PandaDriver.pde @@ -16,34 +16,55 @@ import oscP5.*; */ public class PandaDriver { + // IP address + public final String ip; + // Address to send to private final NetAddress address; + // Whether board output is enabled + private boolean enabled = false; + // OSC message private final OscMessage message; // List of point indices on the board - private final List points; - - // Bit for flipped status of each point index - private final boolean[] flipped; + 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, int[][] flippedList) { - this.address = address; + public PandaDriver(String ip, Model model, int[][] channelList) { + this.ip = ip; + this.address = new NetAddress(ip, 9001); message = new OscMessage("/shady/pointbuffer"); - points = buildMappedList(model, channelList); - flipped = buildFlippedList(model, flippedList); + List pointList = buildMappedList(model, channelList); + points = new int[pointList.size()]; + int i = 0; + for (int value : pointList) { + points[i++] = value; + } } + + public void toggle() { + enabled = !enabled; + println("PandaBoard/" + ip + " Output: " + (enabled ? "ON" : "OFF")); + } private ArrayList buildMappedList(Model model, int[][] channelList) { ArrayList points = new ArrayList(); - 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.CLIPS_PER_CUBE*Clip.STRIPS_PER_CLIP*Strip.POINTS_PER_STRIP); ++i) { + for (int i = 0; i < Cube.POINTS_PER_CUBE; ++i) { points.add(0); } } else { @@ -51,8 +72,14 @@ public class PandaDriver { if (cube == null) { throw new RuntimeException("Non-zero, non-existing cube specified in channel mapping (" + cubeNumber + ")"); } - for (Point p : cube.points) { - points.add(p.index); + final int[] stripOrder = new int[] { + 2, 1, 0, 3, 13, 12, 15, 14, 4, 7, 6, 5, 11, 10, 9, 8 + }; + 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); + } } } } @@ -60,29 +87,10 @@ public class PandaDriver { return points; } - private boolean[] buildFlippedList(Model model, int[][] flippedRGBList) { - boolean[] flipped = new boolean[model.points.size()]; - for (int i = 0; i < flipped.length; ++i) { - flipped[i] = false; - } - for (int[] cubeInfo : flippedRGBList) { - int cubeNumber = cubeInfo[0]; - Cube cube = model.getCubeByRawIndex(cubeNumber); - if (cube == null) { - throw new RuntimeException("Non-existing cube specified in flipped RGB mapping (" + cubeNumber + ")"); - } else { - for (int i = 1; i < cubeInfo.length; ++i) { - int stripIndex = cubeInfo[i]; - for (Point p : cube.strips.get(stripIndex-1).points) { - flipped[p.index] = true; - } - } - } - } - return flipped; - } - public final void send(int[] colors) { + if (!enabled) { + return; + } int len = 0; int packetNum = 0; for (int index : points) { @@ -90,11 +98,6 @@ public class PandaDriver { byte r = (byte) ((c >> 16) & 0xFF); byte g = (byte) ((c >> 8) & 0xFF); byte b = (byte) ((c) & 0xFF); - if (flipped[index]) { - byte tmp = r; - r = g; - g = tmp; - } packet[len++] = 0; packet[len++] = r; packet[len++] = g; @@ -102,24 +105,24 @@ public class PandaDriver { // Flush once packet is full buffer size if (len >= packet.length) { - sendPacket(packetNum++, len); + sendPacket(packetNum++); len = 0; } } // Flush any remaining data if (len > 0) { - sendPacket(packetNum++, len); + sendPacket(packetNum++); } } - private void sendPacket(int packetNum, int len) { + private void sendPacket(int packetNum) { message.clearArguments(); message.add(packetNum); - message.add(len); + message.add(packet.length); message.add(packet); try { - OscP5.flush(message, address); + OscP5.flush(message, address); } catch (Exception x) { x.printStackTrace(); }