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));
}
}

View File

@@ -211,10 +211,16 @@ public class Puck extends DeviceBase {
}
Font getLabelFont() {
if (plotRect != null){
return new Font("Times New Roman", Font.BOLD, 18);
}
return new Font("Times New Roman", Font.BOLD, 12);
}
Font getIdFont() {
if (plotRect != null){
return new Font("Times New Roman", Font.PLAIN, 12);
}
return new Font("Times New Roman", Font.PLAIN, 9);
}

View File

@@ -57,7 +57,6 @@ public class PuckDetection extends DeviceBase{
watchDog.start();
}
void subscriberTask(){
try{
setState(State.Ready);
@@ -68,9 +67,9 @@ public class PuckDetection extends DeviceBase{
try{
while (!Thread.currentThread().isInterrupted()) {
String type = subscriber.recvStr();
System.out.println(type);
//System.out.println(type);
String contents = subscriber.recvStr();
System.out.println(contents);
//System.out.println(contents);
processMessage(contents);
if (MainPanel.getInstance()!=null){
MainPanel.getInstance().repaint();