From 95bb544a483938707877d99cf8078cba673df174 Mon Sep 17 00:00:00 2001 From: gac-S_Changer Date: Wed, 26 Sep 2018 16:49:11 +0200 Subject: [PATCH] Hiding puck detection errors from users. --- src/main/java/ch/psi/mxsc/PuckState.java | 29 +++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main/java/ch/psi/mxsc/PuckState.java b/src/main/java/ch/psi/mxsc/PuckState.java index 96229c7..ace6683 100644 --- a/src/main/java/ch/psi/mxsc/PuckState.java +++ b/src/main/java/ch/psi/mxsc/PuckState.java @@ -10,8 +10,21 @@ public class PuckState { public final int id; public boolean online; - public boolean mecSwitch; - public boolean indSwitch; + public SwitchState mecSwitch; + public SwitchState indSwitch; + + public enum SwitchState{ + On, + Off, + Error; + static SwitchState fromInt(int value){ + switch (value){ + case 1: return SwitchState.On; + case 0: return SwitchState.Off; + default: return SwitchState.Error; + } + } + } PuckState(int id) { this.id = id; @@ -26,8 +39,8 @@ public class PuckState { void clear() { online = false; - mecSwitch = false; - indSwitch = false; + mecSwitch = SwitchState.Off; + indSwitch = SwitchState.Off; BasePlate basePlate = getBasePlate(); if (basePlate != null) { basePlate.getPucks()[id - 1].detection = Puck.Detection.Empty; @@ -37,13 +50,13 @@ public class PuckState { void set(int mecSwitch, int indSwitch) { online = true; //TODO: Handle -1 value: error - this.mecSwitch = (mecSwitch ==1); - this.indSwitch = (indSwitch ==1); + this.mecSwitch = SwitchState.fromInt(mecSwitch); + this.indSwitch = SwitchState.fromInt(indSwitch); BasePlate basePlate = getBasePlate(); if (basePlate != null) { - if (this.mecSwitch != this.indSwitch) { + 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) { + } else if (this.mecSwitch ==SwitchState.On ) { basePlate.getPucks()[id - 1].detection = Puck.Detection.Present; } else { basePlate.getPucks()[id - 1].detection = Puck.Detection.Empty;