This commit is contained in:
gac-S_Changer
2018-09-04 13:31:11 +02:00
parent 45498381d3
commit 61ca6a6bc4
4 changed files with 87 additions and 8 deletions

View File

@@ -4,6 +4,7 @@
package ch.psi.mxsc;
import ch.psi.mxsc.BasePlatePanel.SelectionMode;
import ch.psi.mxsc.Puck.Detection;
import ch.psi.pshell.core.Context;
import ch.psi.pshell.core.JsonSerializer;
import ch.psi.pshell.core.Plugin;
@@ -12,7 +13,6 @@ import ch.psi.pshell.device.DeviceAdapter;
import ch.psi.pshell.imaging.Renderer;
import ch.psi.pshell.imaging.RendererMode;
import ch.psi.pshell.imaging.Source;
import ch.psi.pshell.scripting.ViewPreference;
import ch.psi.pshell.ui.App;
import ch.psi.pshell.ui.Panel;
import ch.psi.utils.State;
@@ -26,13 +26,11 @@ import java.awt.GridBagLayout;
import java.awt.Image;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
@@ -162,12 +160,27 @@ public class MainPanel extends Panel {
@Override
public void onValueChanged(Device device, Object value, Object former) {
if (value!=null){ //Keep last value
textSampleDatamatrix.setText((value==null) ? "" : value.toString());
String valStr = value.toString().trim();
if (puckLoading && Controller.getInstance().isBarcodeReaderScanPucks()){
onPuckBarcode(valStr);
} else {
textSampleDatamatrix.setText(valStr);
}
}
}
});
textPuckDatamatrix.setText("");
textSampleDatamatrix.setText("");
((Device) getDevice("puck_detection")).addListener(new DeviceAdapter() {
@Override
public void onValueChanged(Device device, Object value, Object former) {
if (value!=null){ //Keep last value
onPuckDetectionChanged();
}
}
});
} catch (Exception ex) {
this.getLogger().log(Level.SEVERE, null, ex);
}
@@ -203,9 +216,9 @@ public class MainPanel extends Panel {
}
try {
puckLoading = Controller.getInstance().isPuckLoading();
setPuckLoading(Controller.getInstance().isPuckLoading());
} catch (Exception ex) {
puckLoading = null;
setPuckLoading(false);
}
if (getState()==State.Ready){
if (Boolean.TRUE.equals(puckLoading)){
@@ -496,6 +509,53 @@ public class MainPanel extends Panel {
}
}
////////////////////// Puck Loading /////////////////////////////////
Detection[] currentDetection;
void setPuckLoading(Boolean value){
if (value==null){
value = false;
}
if (value != puckLoading){
puckLoading = value;
textPuckDatamatrix.setText("");
if (Controller.getInstance().isBarcodeReaderScanPucks()){
if (puckLoading){
execute("barcode_reader.enable()", true);
execute("barcode_reader.polling = 100", true);
currentDetection = Controller.getInstance().basePlate.getDetection();
} else if (getState().isInitialized()){
execute("barcode_reader.polling = 0", true);
execute("barcode_reader.disable()", true);
}
}
}
}
void onPuckBarcode(String datamatrix){
if (puckLoading){
textPuckDatamatrix.setText(datamatrix);
System.out.println(datamatrix);
}
}
void onPuckDetectionChanged(){
if (puckLoading){
String datamatrix = textPuckDatamatrix.getText().trim();
Detection[] detection = Controller.getInstance().basePlate.getDetection();
if (!datamatrix.isEmpty()){
for (int i=0; i< Controller.NUMBER_OF_PUCKS; i++){
if ((currentDetection[i] != Detection.Present) && (detection[i] == Detection.Present)){
System.out.println("Detected puck " + datamatrix + " at position " + Controller.getInstance().basePlate.getPucks()[i].getName());
textPuckDatamatrix.setText("");
}
}
}
currentDetection = detection;
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always