Aded puck detection using Esera

This commit is contained in:
gac-S_Changer
2018-01-09 10:52:06 +01:00
parent ff1bfbe15c
commit c4ce826ae8
4 changed files with 91 additions and 76 deletions

View File

@@ -18,7 +18,15 @@ public class MainPanel extends Panel {
BasePlate basePlate;
/** Creates new form Panel */
static MainPanel instance;
static String PUCK_DETECTION_DEVICE = "onewire";
enum PuckSensorAccess{
RaspberryPi,
Esera;
}
final PuckSensorAccess puckSensorAccess = PuckSensorAccess.RaspberryPi;
static String PUCK_ESERA_DEVICE = "onewire";
public static final int NUMBER_OF_PUCKS = 30;
@@ -71,27 +79,29 @@ public class MainPanel extends Panel {
addDevice(basePlate);
clearPuckStates();
getContext().getDevicePool().addListener(new DevicePoolListener() {
@Override
public void onDeviceAdded(GenericDevice dev) {
if (dev.getName().equals(PUCK_DETECTION_DEVICE)){
detection = new EseraDetection((Device) dev);
if (puckSensorAccess == PuckSensorAccess.Esera){
getContext().getDevicePool().addListener(new DevicePoolListener() {
@Override
public void onDeviceAdded(GenericDevice dev) {
if (dev.getName().equals(PUCK_ESERA_DEVICE)){
detection = new EseraDetection((Device) dev);
}
}
}
@Override
public void onDeviceRemoved(GenericDevice dev) {
if (dev.getName().equals(PUCK_DETECTION_DEVICE)){
detection.close();
detection = null;
@Override
public void onDeviceRemoved(GenericDevice dev) {
if (dev.getName().equals(PUCK_ESERA_DEVICE)){
detection.close();
detection = null;
}
}
});
if (detection != null){
detection.close();
detection = null;
}
if ((Device) getDevice(PUCK_ESERA_DEVICE) != null){
detection = new EseraDetection((Device) getDevice(PUCK_ESERA_DEVICE));
}
});
if (detection != null){
detection.close();
detection = null;
}
if ((Device) getDevice(PUCK_DETECTION_DEVICE) != null){
detection = new EseraDetection((Device) getDevice(PUCK_DETECTION_DEVICE));
}
}