diff --git a/src/main/java/ch/psi/mxsc/Controller.java b/src/main/java/ch/psi/mxsc/Controller.java index dd867b6..442b272 100644 --- a/src/main/java/ch/psi/mxsc/Controller.java +++ b/src/main/java/ch/psi/mxsc/Controller.java @@ -105,6 +105,7 @@ public class Controller { public static final int NUMBER_OF_PUCKS = 30; private Controller(Panel mainFrame) { + System.setProperty(GenericDevice.PROPERTY_CONFIG_PATH, Context.getInstance().getSetup().getDevicesPath()); basePlate = new BasePlate(); puckState = new PuckState[NUMBER_OF_PUCKS]; for (int i = 0; i < NUMBER_OF_PUCKS; i++) { diff --git a/src/main/java/ch/psi/mxsc/Puck.java b/src/main/java/ch/psi/mxsc/Puck.java index d5e9fb5..28c7e9a 100644 --- a/src/main/java/ch/psi/mxsc/Puck.java +++ b/src/main/java/ch/psi/mxsc/Puck.java @@ -5,8 +5,11 @@ package ch.psi.mxsc; import ch.psi.pshell.device.Device; import ch.psi.pshell.device.DeviceBase; +import ch.psi.pshell.device.DeviceConfig; import ch.psi.pshell.imaging.DimensionDouble; import ch.psi.pshell.imaging.PointDouble; +import ch.psi.pshell.swing.DevicePanel; +import java.io.IOException; import java.util.ArrayList; /** @@ -153,10 +156,21 @@ public class Puck extends DeviceBase { final int address; final int number; final double angle; + + public static enum PuckDetectionMode{ + Inductive, + Mechanical, + Both + } + + public static class PuckConfig extends DeviceConfig{ + public boolean disabled; + public PuckDetectionMode detection = PuckDetectionMode.Both; + } Puck(BasePlate basePlate, int index) { //super(String.valueOf(index+1)); - super(SEGMENTS[index] + "" + NUMBERS[index]); + super(SEGMENTS[index] + "" + NUMBERS[index], new PuckConfig()); this.setParent(basePlate); this.index = index; this.segment = SEGMENTS[index]; @@ -168,6 +182,19 @@ public class Puck extends DeviceBase { } } + @Override + public PuckConfig getConfig(){ + return (PuckConfig) super.getConfig(); + } + + public boolean isDisabled(){ + return getConfig().disabled; + } + + public PuckDetectionMode getDetectionMode(){ + return getConfig().detection == null ? PuckDetectionMode.Both: getConfig().detection; + } + public BasePlate getBasePlate() { return (BasePlate) getParent(); } diff --git a/src/main/java/ch/psi/mxsc/PuckGraphics.java b/src/main/java/ch/psi/mxsc/PuckGraphics.java index 9b29494..3122248 100644 --- a/src/main/java/ch/psi/mxsc/PuckGraphics.java +++ b/src/main/java/ch/psi/mxsc/PuckGraphics.java @@ -101,6 +101,9 @@ public class PuckGraphics { Color getColor() { Color ret = Color.LIGHT_GRAY; + if (puck.isDisabled()){ + return basePlateGraphics.getColor(); + } switch (puck.detection) { case Empty: //ret = isHighlithted() ? new Color(224, 224, 224) : Color.LIGHT_GRAY; @@ -177,6 +180,9 @@ public class PuckGraphics { } Color getLabelColor(boolean drawBackground) { + if (puck.isDisabled()){ + return Color.RED; + } return drawBackground ? (isHighlithted() ? Color.BLACK : new Color(92, 92, 92)) : (isHighlithted() ? new Color(0, 255, 0) : new Color(0, 162, 0)); } @@ -203,6 +209,9 @@ public class PuckGraphics { Color getBorderColor(boolean drawBackground) { if (drawBackground) { + if (puck.isDisabled()){ + return Color.RED; + } /*if (!isEnabled()){ return Color.GRAY; } else */ @@ -231,6 +240,9 @@ public class PuckGraphics { void draw(Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawId, boolean drawBackground) { this.plotRect = plotRect; + if (puck.isDisabled()){ + drawSamples=false; + } Point position = getDrawPosition(); int size = getDrawSize(); if (drawBackground) { diff --git a/src/main/java/ch/psi/mxsc/PuckState.java b/src/main/java/ch/psi/mxsc/PuckState.java index ace6683..8eb36cf 100644 --- a/src/main/java/ch/psi/mxsc/PuckState.java +++ b/src/main/java/ch/psi/mxsc/PuckState.java @@ -51,15 +51,36 @@ public class PuckState { online = true; //TODO: Handle -1 value: error this.mecSwitch = SwitchState.fromInt(mecSwitch); - this.indSwitch = SwitchState.fromInt(indSwitch); - BasePlate basePlate = getBasePlate(); + this.indSwitch = SwitchState.fromInt(indSwitch); + BasePlate basePlate = getBasePlate(); if (basePlate != null) { - if ((this.mecSwitch != this.indSwitch) ||(this.mecSwitch == SwitchState.Error) ||(this.mecSwitch == SwitchState.Error)) { - basePlate.getPucks()[id - 1].detection = Puck.Detection.Error; - } else if (this.mecSwitch ==SwitchState.On ) { - basePlate.getPucks()[id - 1].detection = Puck.Detection.Present; - } else { - basePlate.getPucks()[id - 1].detection = Puck.Detection.Empty; + Puck puck = basePlate.getPucks()[id - 1]; + switch(puck.getDetectionMode()){ + case Mechanical: + if (this.mecSwitch ==SwitchState.On ) { + basePlate.getPucks()[id - 1].detection = Puck.Detection.Present; + } else { + basePlate.getPucks()[id - 1].detection = Puck.Detection.Empty; + } + break; + + case Inductive: + if (this.indSwitch ==SwitchState.On ) { + basePlate.getPucks()[id - 1].detection = Puck.Detection.Present; + } else { + basePlate.getPucks()[id - 1].detection = Puck.Detection.Empty; + } + break; + + case Both: + if ((this.mecSwitch != this.indSwitch) ||(this.mecSwitch == SwitchState.Error) ||(this.mecSwitch == SwitchState.Error)) { + basePlate.getPucks()[id - 1].detection = Puck.Detection.Error; + } else if (this.mecSwitch ==SwitchState.On ) { + basePlate.getPucks()[id - 1].detection = Puck.Detection.Present; + } else { + basePlate.getPucks()[id - 1].detection = Puck.Detection.Empty; + } + break; } } }