This commit is contained in:
gac-S_Changer
2018-09-06 12:10:05 +02:00
parent 61ca6a6bc4
commit 9053e14c41
4 changed files with 195 additions and 106 deletions

View File

@@ -4,7 +4,6 @@
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;
@@ -154,36 +153,12 @@ public class MainPanel extends Panel {
}
}
});
updateMode(((Device) getDevice("robot")).take());
((Device) getDevice("barcode_reader")).addListener(new DeviceAdapter() {
@Override
public void onValueChanged(Device device, Object value, Object former) {
if (value!=null){ //Keep last value
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();
}
}
});
updateMode(((Device) getDevice("robot")).take());
} catch (Exception ex) {
this.getLogger().log(Level.SEVERE, null, ex);
}
setPuckDatamatrix(null);
setSampleDatamatrix(null);
Controller.getInstance().updatePuckTypes();
startTimer(3000, 1000);
updateCameraView();
@@ -210,16 +185,11 @@ public class MainPanel extends Panel {
ledHeaterOk.setColor(Color.BLACK);
}
} catch (Exception ex) {
roomTemperature = null;
roomTemperature = null;
ledRoomTemperature.setColor(Color.BLACK);
labelRoomTemperature.setText("Room Temperature");
}
try {
setPuckLoading(Controller.getInstance().isPuckLoading());
} catch (Exception ex) {
setPuckLoading(false);
}
Controller.getInstance().onTimer();
if (getState()==State.Ready){
if (Boolean.TRUE.equals(puckLoading)){
getView().getStatusBar().setStatusMessage(PUCK_LOADING_STATUS);
@@ -509,52 +479,24 @@ 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);
}
}
}
public void setPuckDatamatrix(String datamatrix){
textPuckDatamatrix.setText((datamatrix==null) ? "" : String.valueOf(datamatrix));
}
void onPuckBarcode(String datamatrix){
if (puckLoading){
textPuckDatamatrix.setText(datamatrix);
System.out.println(datamatrix);
}
public void setSampleDatamatrix(String datamatrix){
textSampleDatamatrix.setText((datamatrix==null) ? "" : String.valueOf(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;
}
}
public String getPuckDatamatrix(){
String ret = textPuckDatamatrix.getText();
return (ret != null) ? ret.trim() : "";
}
public String getSampleDatamatrix(){
String ret = textSampleDatamatrix.getText();
return (ret != null) ? ret.trim() : "";
}
/**
* This method is called from within the constructor to initialize the form.