From 79ae8245d084fe7901933b22a44b404f9d68b925 Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Sat, 10 Aug 2013 18:22:39 -0700 Subject: [PATCH] Make panda board output togglable from UI --- _Internals.pde | 32 +++++++++++++------------------- _Overlay.pde | 41 ++++++++++++++++++++++++++++++++++++----- _PandaDriver.pde | 19 +++++++++++++++++-- 3 files changed, 66 insertions(+), 26 deletions(-) diff --git a/_Internals.pde b/_Internals.pde index d51463c..e2c343a 100644 --- a/_Internals.pde +++ b/_Internals.pde @@ -56,12 +56,8 @@ LXEffect[] effects; OverlayUI ui; ControlUI controlUI; MappingUI mappingUI; -PandaDriver pandaFront; -PandaDriver pandaRear; +PandaDriver[] pandaBoards; boolean mappingMode = false; - -boolean pandaBoardsEnabled = false; - boolean debugMode = false; DebugUI debugUI; @@ -96,8 +92,10 @@ void setup() { int[][] frontChannels = glucose.mapping.buildFrontChannelList(); int[][] rearChannels = glucose.mapping.buildRearChannelList(); mappingTool = new MappingTool(glucose, frontChannels, rearChannels); - pandaFront = new PandaDriver(new NetAddress("10.200.1.28", 9001), glucose.model, frontChannels); - pandaRear = new PandaDriver(new NetAddress("10.200.1.29", 9001), glucose.model, rearChannels); + pandaBoards = new PandaDriver[] { + new PandaDriver("10.200.1.28", glucose.model, frontChannels), + new PandaDriver("10.200.1.29", glucose.model, rearChannels), + }; logTime("Build PandaDriver"); // Build overlay UI @@ -212,9 +210,8 @@ void draw() { } // TODO(mcslee): move into GLucose engine - if (pandaBoardsEnabled) { - // pandaFront.send(colors); - pandaRear.send(colors); + for (PandaDriver p : pandaBoards) { + p.send(colors); } } @@ -303,8 +300,9 @@ void keyPressed() { } break; case 'p': - pandaBoardsEnabled = !pandaBoardsEnabled; - println("PandaBoard Output: " + (pandaBoardsEnabled ? "ON" : "OFF")); + for (PandaDriver p : pandaBoards) { + p.toggle(); + } break; case 'u': uiOn = !uiOn; @@ -313,11 +311,9 @@ void keyPressed() { } int mx, my; - void mousePressed() { - if (mouseX > ui.leftPos) { - ui.mousePressed(); - } else { + ui.mousePressed(); + if (mouseX < ui.leftPos) { if (debugMode) { debugUI.mousePressed(); } @@ -342,9 +338,7 @@ void mouseDragged() { } void mouseReleased() { - if (mouseX > ui.leftPos) { - ui.mouseReleased(); - } + ui.mouseReleased(); } void mouseWheel(int delta) { diff --git a/_Overlay.pde b/_Overlay.pde index 2ff364d..971ffde 100644 --- a/_Overlay.pde +++ b/_Overlay.pde @@ -40,6 +40,11 @@ abstract class OverlayUI { protected final int STATE_ACTIVE = 1; protected final int STATE_PENDING = 2; + protected int[] pandaLeft = new int[pandaBoards.length]; + protected final int pandaWidth = 56; + protected final int pandaHeight = 13; + protected final int pandaTop = height-16; + protected OverlayUI() { leftPos = width - w; leftTextPos = leftPos + 4; @@ -74,14 +79,20 @@ abstract class OverlayUI { text("FPS: " + (((int)(frameRate * 10)) / 10.), 4, height-6); text("Target (-/+):", 50, height-6); fill(#000000); - rect(104, height-16, 20, 12); + rect(104, height-16, 20, 13); fill(#666666); text("" + targetFramerate, 108, height-6); text("PandaOutput (p):", 134, height-6); - fill(#000000); - rect(214, height-16, 26, 12); - fill(#666666); - text(pandaBoardsEnabled ? "ON" : "OFF", 218, height-6); + int lPos = 214; + int pi = 0; + for (PandaDriver p : pandaBoards) { + pandaLeft[pi++] = lPos; + fill(p.enabled ? #666666 : #000000); + rect(lPos, pandaTop, pandaWidth, pandaHeight); + fill(p.enabled ? #000000 : #666666); + text(p.ip, lPos + 4, height-6); + lPos += 60; + } } @@ -370,6 +381,21 @@ class ControlUI extends OverlayUI { patternKnobIndex = transitionKnobIndex = effectKnobIndex = -1; releaseEffect = -1; patternScrolling = false; + + for (int p = 0; p < pandaLeft.length; ++p) { + int xp = pandaLeft[p]; + if ((mouseX >= xp) && + (mouseX < xp + pandaWidth) && + (mouseY >= pandaTop) && + (mouseY < pandaTop + pandaHeight)) { + pandaBoards[p].toggle(); + } + } + + if (mouseX < leftPos) { + return; + } + if (mouseY > tempoY) { if (mouseY - tempoY < tempoHeight) { lx.tempo.tap(); @@ -600,6 +626,11 @@ class MappingUI extends OverlayUI { public void mousePressed() { dragCube = dragStrip = dragChannel = false; lastY = mouseY; + + if (mouseX < leftPos) { + return; + } + if (mouseY >= stripFieldY) { if (mouseY < stripFieldY + lineHeight) { dragStrip = true; diff --git a/_PandaDriver.pde b/_PandaDriver.pde index 2350928..5e47764 100644 --- a/_PandaDriver.pde +++ b/_PandaDriver.pde @@ -16,9 +16,15 @@ 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; @@ -34,8 +40,9 @@ public class PandaDriver { // Packet data 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; + public PandaDriver(String ip, Model model, int[][] channelList) { + this.ip = ip; + this.address = new NetAddress(ip, 9001); message = new OscMessage("/shady/pointbuffer"); List pointList = buildMappedList(model, channelList); points = new int[pointList.size()]; @@ -44,6 +51,11 @@ public class PandaDriver { 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(); @@ -76,6 +88,9 @@ public class PandaDriver { } public final void send(int[] colors) { + if (!enabled) { + return; + } int len = 0; int packetNum = 0; for (int index : points) { -- 2.34.1