/* * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. */ package ch.psi.mxsc; /** * */ public class PuckState { public final int id; public boolean online; public boolean mecSwitch; public boolean indSwitch; PuckState(int id) { this.id = id; } BasePlate getBasePlate() { if (Controller.getInstance() == null) { return null; } return Controller.getInstance().basePlate; } void clear() { online = false; mecSwitch = false; indSwitch = false; BasePlate basePlate = getBasePlate(); if (basePlate != null) { basePlate.getPucks()[id - 1].detection = Puck.Detection.Offline; } } void set(int mecSwitch, int indSwitch) { online = true; //TODO: Hanfle -1 value: error this.mecSwitch = mecSwitch ==1; this.indSwitch = mecSwitch ==1; BasePlate basePlate = getBasePlate(); if (basePlate != null) { if (this.mecSwitch != this.indSwitch) { basePlate.getPucks()[id - 1].detection = Puck.Detection.Error; } else if (this.mecSwitch) { basePlate.getPucks()[id - 1].detection = Puck.Detection.Present; } else { basePlate.getPucks()[id - 1].detection = Puck.Detection.Empty; } } } @Override public String toString() { return "Online = " + online + "\ns1 = " + mecSwitch + "\ns2 = " + indSwitch; } }