From 9b4179478b2c031e2881e449c960c96a021f1f6f Mon Sep 17 00:00:00 2001 From: gac-S_Changer Date: Fri, 8 Aug 2025 13:17:25 +0200 Subject: [PATCH] Puck detetion mode - during loading only --- src/main/java/ch/psi/mxsc/Controller.java | 35 +++++++++++++++----- src/main/java/ch/psi/mxsc/PuckDetection.java | 24 ++++++++++---- 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/main/java/ch/psi/mxsc/Controller.java b/src/main/java/ch/psi/mxsc/Controller.java index d7b954f..1192152 100644 --- a/src/main/java/ch/psi/mxsc/Controller.java +++ b/src/main/java/ch/psi/mxsc/Controller.java @@ -62,7 +62,7 @@ public class Controller { static /*Panel*/ MainPanel mainFrame; Device barcode_reader; Device barcode_reader_puck; - Device puck_detection; + PuckDetection puck_detection; JDialog dialogAskPuckDatamatrix; String currentMountedSample; PuckLoadingDialog dialogPuckLoading; @@ -140,7 +140,7 @@ public class Controller { puckState = new PuckState[NUMBER_OF_PUCKS]; for (int i = 0; i < NUMBER_OF_PUCKS; i++) { puckState[i] = new PuckState(i + 1); - } + } } private Controller(Panel mainFrame) { @@ -149,8 +149,7 @@ public class Controller { clearPuckStates(); basePlate.addListener(basePlateListener); - roomTemperatureBasePlate = new RoomTemperatureBasePlate(); - + roomTemperatureBasePlate = new RoomTemperatureBasePlate(); } final DeviceListener basePlateListener = new DeviceListener() { @@ -242,12 +241,11 @@ public class Controller { @Override public void onDeviceRemoved(GenericDevice dev) { } - }); + }); updateDevices(); updatePuckTypes(); clearSamplesTable(); - refreshSamplesTable(); - + refreshSamplesTable(); } public Sample getMountedSample() throws Exception{ @@ -354,12 +352,13 @@ public class Controller { } else { Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, "No barcode_reader_puck detected."); } - puck_detection = (Device) getDevice("puck_detection"); + puck_detection = (PuckDetection) getDevice("puck_detection"); if (puck_detection != null) { puck_detection.addListener(puckDetectionListener); } else { Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, "No puck_detection detected."); } + checkEnablePuckDetection(); } PuckState[] puckState; @@ -960,6 +959,18 @@ public class Controller { } } + + public void checkEnablePuckDetection(){ + try{ + if ("loading".equals(Context.getSetting("puck_detection"))){ + boolean loading = (dialogPuckLoading != null) && (dialogPuckLoading.isShowing()); + puck_detection.setEnabled(loading); + } + } catch (Exception ex) { + Logger.getLogger(Controller.class.getName()).log(Level.WARNING, null, ex); + } + } + void showDialogPuckLoading(boolean load) { if ((dialogPuckLoading != null) && (dialogPuckLoading.isVisible())) { @@ -968,6 +979,7 @@ public class Controller { dialogPuckLoading = new PuckLoadingDialog(mainFrame.getTopLevel(), load, false); dialogPuckLoading.setLocationRelativeTo(mainFrame); dialogPuckLoading.setVisible(true); + checkEnablePuckDetection(); dialogPuckLoading.addWindowListener(new WindowAdapter() { @Override @@ -976,8 +988,13 @@ public class Controller { setPuckLoading(null); } catch (Exception ex) { Logger.getLogger(Controller.class.getName()).log(Level.WARNING, null, ex); - } + } } + @Override + public void windowClosed(WindowEvent e) { + checkEnablePuckDetection(); + } + }); } diff --git a/src/main/java/ch/psi/mxsc/PuckDetection.java b/src/main/java/ch/psi/mxsc/PuckDetection.java index 9167a1c..b6d3461 100644 --- a/src/main/java/ch/psi/mxsc/PuckDetection.java +++ b/src/main/java/ch/psi/mxsc/PuckDetection.java @@ -17,6 +17,7 @@ public class PuckDetection extends DeviceBase { public volatile Chrono chrono; boolean debug; public static final int TIMEOUT = 10000; + boolean enabled = true; public PuckDetection(String name, String server) { super(name); @@ -128,11 +129,15 @@ public class PuckDetection extends DeviceBase { if (debug) { System.out.println(contents); } - processMessage(contents); - - if (Controller.getInstance() != null) { - Controller.getInstance().updateView(); + + setCache(contents); + if (isEnabled() || (take() == null)){ + processMessage(contents); + if (Controller.getInstance() != null) { + Controller.getInstance().updateView(); + } } + setState(State.Ready); if (chrono != null){ updateTime.update(chrono.getEllapsed()); @@ -176,8 +181,7 @@ public class PuckDetection extends DeviceBase { } address++; } - } - setCache(str); + } } catch (Exception ex) { getLogger().log(Level.INFO, null, ex); } @@ -215,6 +219,14 @@ public class PuckDetection extends DeviceBase { thread = null; } } + + public void setEnabled(boolean value){ + enabled = value; + } + + public boolean isEnabled(){ + return enabled; + } public static void main(String[] args) throws IOException, InterruptedException { //PuckDetection pd = new PuckDetection("PD", "129.129.110.99:5556");