From 2bae07c96a1b27bf4dc3cbe0082be5ae374fa0d9 Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Fri, 14 Jun 2013 11:08:42 -0700 Subject: [PATCH] Update mapping constants and tool for trip --- TestPatterns.pde | 74 ++++++++++++++++++++++++++++++++++++++++++++---- _Internals.pde | 2 +- _Mappings.pde | 28 ++++++++++++++---- _Overlay.pde | 38 +++++++++++++++++++++---- 4 files changed, 124 insertions(+), 18 deletions(-) diff --git a/TestPatterns.pde b/TestPatterns.pde index e7951e3..9b46531 100644 --- a/TestPatterns.pde +++ b/TestPatterns.pde @@ -138,8 +138,12 @@ class MappingTool extends SCPattern { private int cubeIndex = 0; private int stripIndex = 0; + private int channelIndex = 0; - public boolean mappingModeSingleCube = true; + public final int MAPPING_MODE_ALL = 0; + public final int MAPPING_MODE_CHANNEL = 1; + public final int MAPPING_MODE_SINGLE_CUBE = 2; + public int mappingMode = MAPPING_MODE_ALL; public final int CUBE_MODE_ALL = 0; public final int CUBE_MODE_SINGLE_STRIP = 1; @@ -150,8 +154,36 @@ class MappingTool extends SCPattern { public boolean channelModeGreen = false; public boolean channelModeBlue = false; - MappingTool(GLucose glucose) { + private final static int NUM_CHANNELS = 16; + + private final int[][] frontChannels; + private final int[][] rearChannels; + private int[] activeChannels; + + MappingTool(GLucose glucose, int[][]frontChannels, int[][]rearChannels) { super(glucose); + this.frontChannels = frontChannels; + this.rearChannels = rearChannels; + setChannel(); + } + + private void setChannel() { + if (channelIndex < frontChannels.length) { + activeChannels = frontChannels[channelIndex]; + } else { + activeChannels = rearChannels[channelIndex - frontChannels.length]; + } + } + + private int cubeInChannel(Cube c) { + int i = 1; + for (int index : activeChannels) { + if (c == model.getCubeByRawIndex(index)) { + return i; + } + ++i; + } + return 0; } private void printInfo() { @@ -182,8 +214,25 @@ class MappingTool extends SCPattern { int ci = 0; for (Cube cube : model.cubes) { - if (!mappingModeSingleCube || (cubeIndex == ci)) { - if (cubeMode == CUBE_MODE_STRIP_PATTERN) { + boolean cubeOn = false; + int channelIndex = cubeInChannel(cube); + switch (mappingMode) { + case MAPPING_MODE_ALL: cubeOn = true; break; + case MAPPING_MODE_SINGLE_CUBE: cubeOn = (cubeIndex == ci); break; + case MAPPING_MODE_CHANNEL: cubeOn = (channelIndex > 0); break; + } + if (cubeOn) { + if (mappingMode == MAPPING_MODE_CHANNEL) { + color cc = off; + switch (channelIndex) { + case 1: cc = r; break; + case 2: cc = r|g; break; + case 3: cc = g; break; + case 4: cc = b; break; + case 5: cc = r|b; break; + } + setColor(cube, cc); + } else if (cubeMode == CUBE_MODE_STRIP_PATTERN) { int si = 0; color sc = off; for (Strip strip : cube.strips) { @@ -224,6 +273,19 @@ class MappingTool extends SCPattern { cubeIndex += model.cubes.size(); } } + + public void incChannel() { + channelIndex = (channelIndex + 1) % NUM_CHANNELS; + setChannel(); + } + + public void decChannel() { + --channelIndex; + if (channelIndex < 0) { + channelIndex += NUM_CHANNELS; + } + setChannel(); + } public void incStrip() { int stripsPerCube = Cube.CLIPS_PER_CUBE * Clip.STRIPS_PER_CLIP; @@ -240,8 +302,8 @@ class MappingTool extends SCPattern { public void keyPressed() { switch (keyCode) { - case UP: incCube(); break; - case DOWN: decCube(); break; + case UP: if (mappingMode == MAPPING_MODE_CHANNEL) incChannel(); else incCube(); break; + case DOWN: if (mappingMode == MAPPING_MODE_CHANNEL) decChannel(); else decCube(); break; case LEFT: decStrip(); break; case RIGHT: incStrip(); break; } diff --git a/_Internals.pde b/_Internals.pde index 29b0dde..4ab6f76 100644 --- a/_Internals.pde +++ b/_Internals.pde @@ -68,7 +68,6 @@ void setup() { // Set the patterns glucose.lx.setPatterns(patterns = patterns(glucose)); - mappingTool = new MappingTool(glucose); logTime("Built patterns"); glucose.lx.addEffects(effects = effects(glucose)); logTime("Built effects"); @@ -79,6 +78,7 @@ void setup() { int[][] frontChannels = glucose.mapping.buildFrontChannelList(); int[][] rearChannels = glucose.mapping.buildRearChannelList(); int[][] flippedRGB = glucose.mapping.buildFlippedRGBList(); + mappingTool = new MappingTool(glucose, frontChannels, rearChannels); pandaFront = new PandaDriver(new NetAddress("192.168.1.28", 9001), glucose.model, frontChannels, flippedRGB); pandaRear = new PandaDriver(new NetAddress("192.168.1.29", 9001), glucose.model, rearChannels, flippedRGB); logTime("Build PandaDriver"); diff --git a/_Mappings.pde b/_Mappings.pde index fd581e5..52552b8 100644 --- a/_Mappings.pde +++ b/_Mappings.pde @@ -76,7 +76,7 @@ class SCMapping implements GLucose.Mapping { cubes[56] = new Cube(1, 53, 0, 40, 70, 70); cubes[57] = new Cube(-15, 24, 0, 15, 0, 0); //cubes[58] what the heck happened here? never noticed before 4/8/2013 - //cubes[59] what the heck happened here? never noticed before 4/8/2013 + cubes[59] = new Cube(40, 46, 100, 0, 0, 355, false, 2, 3); // copies from 75 cubes[60] = new Cube(40, 164, 120, 0, 0, 12.5, false, 4, 3); cubes[61] = new Cube(32, 148, 100, 0, 0, 3, false, 4, 2); cubes[62] = new Cube(30, 132, 90, 10, 350, 5); @@ -105,7 +105,7 @@ class SCMapping implements GLucose.Mapping { } , { - 30, 31, 32, 17, 3 // Pandaboard B, structural channel 2 + 31, 32, 17, 3, 0 // Pandaboard B, structural channel 2, normally 30, 31, 32, 17, 3 (disconnected 30) } , { @@ -113,7 +113,7 @@ class SCMapping implements GLucose.Mapping { } , { - 69, 75, 74, 76, 73 // Pandaboard D, structural channel 4 + 69, 75, 74, 76, 73 // Pandaboard D, structural channel 4, normally 64 first } , { @@ -157,7 +157,7 @@ class SCMapping implements GLucose.Mapping { } , { - 64, 75, 72, 49, 50 // Pandaboard F, structural channel 14, right top backside + 64, 59, 72, 49, 50 // Pandaboard F, structural channel 14, right top backside (second cube is missing from sim) } , { @@ -174,7 +174,7 @@ class SCMapping implements GLucose.Mapping { // syntax is {cube #, strip #, strip #, . . . } return new int[][] { { - 22, 4, 8 + 22, 4, 7 } , { @@ -218,7 +218,7 @@ class SCMapping implements GLucose.Mapping { } , { - 15, 6, 8 + 15, 6, 8, 9 } , { @@ -252,6 +252,22 @@ class SCMapping implements GLucose.Mapping { { 74, 6, 7 } + , + { + 21, 10 + } + , + { + 37, 11 + } + , + { + 61, 5 + } + , + { + 33, 12 + } }; } } diff --git a/_Overlay.pde b/_Overlay.pde index 244b891..06d106a 100644 --- a/_Overlay.pde +++ b/_Overlay.pde @@ -475,10 +475,13 @@ class MappingUI extends OverlayUI { private MappingTool mappingTool; private final String MAPPING_MODE_ALL = "All On"; + private final String MAPPING_MODE_CHANNEL = "Channel"; private final String MAPPING_MODE_SINGLE_CUBE = "Single Cube"; + private final String[] mappingModes = { MAPPING_MODE_ALL, - MAPPING_MODE_SINGLE_CUBE, + MAPPING_MODE_CHANNEL, + MAPPING_MODE_SINGLE_CUBE }; private final Method mappingModeStateMethod; @@ -505,11 +508,13 @@ class MappingUI extends OverlayUI { private int firstMappingY; private int firstCubeY; private int firstChannelY; + private int channelFieldY; private int cubeFieldY; private int stripFieldY; private boolean dragCube; private boolean dragStrip; + private boolean dragChannel; MappingUI(MappingTool mappingTool) { this.mappingTool = mappingTool; @@ -523,7 +528,14 @@ class MappingUI extends OverlayUI { } public int getMappingState(Object mappingMode) { - boolean active = (mappingMode == MAPPING_MODE_SINGLE_CUBE) == mappingTool.mappingModeSingleCube; + boolean active = false; + if (mappingMode == MAPPING_MODE_ALL) { + active = mappingTool.mappingMode == mappingTool.MAPPING_MODE_ALL; + } else if (mappingMode == MAPPING_MODE_CHANNEL) { + active = mappingTool.mappingMode == mappingTool.MAPPING_MODE_CHANNEL; + } else if (mappingMode == MAPPING_MODE_SINGLE_CUBE) { + active = mappingTool.mappingMode == mappingTool.MAPPING_MODE_SINGLE_CUBE; + } return active ? STATE_ACTIVE : STATE_DEFAULT; } @@ -565,6 +577,10 @@ class MappingUI extends OverlayUI { firstChannelY = yPos + lineHeight + 6; yPos = drawObjectList(yPos, "CHANNELS", channelModes, channelModes, channelModeStateMethod); yPos += sectionSpacing; + + channelFieldY = yPos + lineHeight + 6; + yPos = drawValueField(yPos, "CHANNEL ID", mappingTool.channelIndex + 1); + yPos += sectionSpacing; cubeFieldY = yPos + lineHeight + 6; yPos = drawValueField(yPos, "CUBE ID", glucose.model.getRawIndexForCube(mappingTool.cubeIndex)); @@ -598,7 +614,7 @@ class MappingUI extends OverlayUI { private int lastY; public void mousePressed() { - dragCube = dragStrip = false; + dragCube = dragStrip = dragChannel = false; lastY = mouseY; if (mouseY >= stripFieldY) { if (mouseY < stripFieldY + lineHeight) { @@ -608,6 +624,10 @@ class MappingUI extends OverlayUI { if (mouseY < cubeFieldY + lineHeight) { dragCube = true; } + } else if (mouseY >= channelFieldY) { + if (mouseY < channelFieldY + lineHeight) { + dragChannel = true; + } } else if (mouseY >= firstChannelY) { int index = objectClickIndex(firstChannelY); switch (index) { @@ -624,8 +644,10 @@ class MappingUI extends OverlayUI { } } else if (mouseY >= firstMappingY) { int index = objectClickIndex(firstMappingY); - if (index < 2) { - mappingTool.mappingModeSingleCube = (index > 0); + switch (index) { + case 0: mappingTool.mappingMode = mappingTool.MAPPING_MODE_ALL; break; + case 1: mappingTool.mappingMode = mappingTool.MAPPING_MODE_CHANNEL; break; + case 2: mappingTool.mappingMode = mappingTool.MAPPING_MODE_SINGLE_CUBE; break; } } } @@ -650,6 +672,12 @@ class MappingUI extends OverlayUI { } else { mappingTool.incStrip(); } + } else if (dragChannel) { + if (dy < 0) { + mappingTool.decChannel(); + } else { + mappingTool.incChannel(); + } } } -- 2.34.1