Hiding puck detection errors from users.

This commit is contained in:
gac-S_Changer
2018-09-26 16:49:11 +02:00
parent 90292bbba2
commit 95bb544a48

View File

@@ -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;