This commit is contained in:
@@ -197,9 +197,10 @@ public class BasePlate extends DeviceBase {
|
||||
if (puck!=null){
|
||||
//setCache(puck.getName());
|
||||
setCache(new Object[]{puck.segment, puck.number, null});
|
||||
} else {
|
||||
setCache(null);
|
||||
}
|
||||
}
|
||||
setCache(null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ import ch.psi.pshell.device.DeviceListener;
|
||||
import ch.psi.pshell.device.GenericDevice;
|
||||
import ch.psi.pshell.device.ReadbackDevice;
|
||||
import ch.psi.pshell.ui.Panel;
|
||||
import ch.psi.utils.State;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -31,6 +33,9 @@ public class Controller {
|
||||
final BasePlate basePlate;
|
||||
final /*Panel*/ MainPanel mainFrame;
|
||||
Device hexiposi;
|
||||
Device barcode_reader;
|
||||
Device puck_detection;
|
||||
|
||||
|
||||
public static Controller getInstance() {
|
||||
return instance;
|
||||
@@ -91,7 +96,7 @@ public class Controller {
|
||||
this.mainFrame = (MainPanel) mainFrame;
|
||||
instance = this;
|
||||
clearPuckStates();
|
||||
|
||||
|
||||
basePlate.addListener(new DeviceAdapter() {
|
||||
@Override
|
||||
public void onValueChanged(Device device, Object value, Object former) {
|
||||
@@ -140,12 +145,19 @@ public class Controller {
|
||||
}
|
||||
|
||||
void onInitialize(int runCount) {
|
||||
GenericDevice former = getDevice("BasePlate");
|
||||
if (former != null) {
|
||||
getMainFrame().removeDevice(former);
|
||||
}
|
||||
//GenericDevice former = getDevice("BasePlate");
|
||||
//if (former != null) {
|
||||
//getMainFrame().removeDevice(former);
|
||||
// if (basePlate.getState() == State.Closing){
|
||||
// try {
|
||||
// basePlate.initialize();
|
||||
// } catch (Exception ex) {
|
||||
// Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
getMainFrame().addDevice(basePlate);
|
||||
|
||||
System.out.println(basePlate.getState());
|
||||
|
||||
|
||||
if (puckSensorAccess == PuckSensorAccess.Esera) {
|
||||
@@ -174,7 +186,7 @@ public class Controller {
|
||||
}
|
||||
}
|
||||
|
||||
Controller.getInstance().getDevicePool().addListener(new DevicePoolListener() {
|
||||
getDevicePool().addListener(new DevicePoolListener() {
|
||||
@Override
|
||||
public void onDeviceAdded(GenericDevice dev) {
|
||||
updateDevices();
|
||||
@@ -188,6 +200,14 @@ public class Controller {
|
||||
|
||||
}
|
||||
|
||||
void onTimer(){
|
||||
try {
|
||||
Controller.getInstance().setPuckLoading(Controller.getInstance().isPuckLoading());
|
||||
} catch (Exception ex) {
|
||||
Controller.getInstance().setPuckLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
final DeviceListener hexiposiListener = new DeviceAdapter() {
|
||||
@Override
|
||||
public void onValueChanged(Device device, Object value, Object former) {
|
||||
@@ -195,17 +215,58 @@ public class Controller {
|
||||
}
|
||||
};
|
||||
|
||||
final DeviceListener barcodeReaderListener = 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 && isBarcodeReaderScanPucks()){
|
||||
onPuckBarcode(valStr);
|
||||
} else {
|
||||
getMainFrame().setSampleDatamatrix(valStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
final DeviceListener puckDetectionListener = new DeviceAdapter() {
|
||||
@Override
|
||||
public void onValueChanged(Device device, Object value, Object former) {
|
||||
if (value!=null){ //Keep last value
|
||||
onPuckDetectionChanged();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void updateDevices(){
|
||||
if (hexiposi!=null){
|
||||
hexiposi.removeListener(hexiposiListener);
|
||||
}
|
||||
if (barcode_reader!=null){
|
||||
hexiposi.removeListener(barcodeReaderListener);
|
||||
}
|
||||
if (puck_detection!=null){
|
||||
hexiposi.removeListener(puckDetectionListener);
|
||||
}
|
||||
hexiposi = (Device) getMainFrame().getDevice("hexiposi");
|
||||
if (hexiposi != null) {
|
||||
hexiposi.addListener(hexiposiListener);
|
||||
} else {
|
||||
Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, "No hexiposi detected.");
|
||||
}
|
||||
mainFrame.hexiposiPanel.setDevice(hexiposi);
|
||||
mainFrame.hexiposiPanel.setDevice(hexiposi);
|
||||
barcode_reader = (Device) getDevice("barcode_reader");
|
||||
if (barcode_reader!=null){
|
||||
barcode_reader.addListener(barcodeReaderListener);
|
||||
} else {
|
||||
Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, "No barcode_reader detected.");
|
||||
}
|
||||
puck_detection = (Device) getDevice("puck_detection");
|
||||
if (puck_detection!=null){
|
||||
puck_detection.addListener(puckDetectionListener);
|
||||
} else {
|
||||
Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, "No puck_detection detected.");
|
||||
}
|
||||
}
|
||||
|
||||
final PuckState[] puckState;
|
||||
@@ -254,6 +315,21 @@ public class Controller {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSelectedPuck(Puck puck){
|
||||
return ("" + puck.getSegment()).equalsIgnoreCase(getHexiposiPosition());
|
||||
}
|
||||
|
||||
public List<Puck> getSelectedPucks(){
|
||||
List<Puck> ret = new ArrayList<>();
|
||||
for (int i=0; i< NUMBER_OF_PUCKS; i++){
|
||||
if (isSelectedPuck(basePlate.getPucks()[i])){
|
||||
ret.add(basePlate.getPucks()[i]);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public Boolean isLedRoomTemp() {
|
||||
try {
|
||||
@@ -405,6 +481,11 @@ public class Controller {
|
||||
Context getContext(){
|
||||
return getMainFrame().getContext();
|
||||
}
|
||||
|
||||
State getState(){
|
||||
return getMainFrame().getState();
|
||||
}
|
||||
|
||||
|
||||
void execute(String statement){
|
||||
getMainFrame().execute(statement);
|
||||
@@ -417,4 +498,72 @@ public class Controller {
|
||||
void execute(String statement, boolean background, boolean showReturn){
|
||||
getMainFrame().execute(statement, background, showReturn);
|
||||
}
|
||||
|
||||
|
||||
////////////////////// Puck Loading /////////////////////////////////
|
||||
Boolean puckLoading;
|
||||
Puck.Detection[] currentDetection;
|
||||
void setPuckLoading(Boolean value){
|
||||
if (value==null){
|
||||
value = false;
|
||||
}
|
||||
if (value != puckLoading){
|
||||
puckLoading = value;
|
||||
getMainFrame().setPuckDatamatrix(null);
|
||||
if (isBarcodeReaderScanPucks()){
|
||||
if (puckLoading){
|
||||
execute("barcode_reader.enable()", true);
|
||||
execute("barcode_reader.polling = 100", true);
|
||||
currentDetection = basePlate.getDetection();
|
||||
} else if (getState().isInitialized()){
|
||||
execute("barcode_reader.polling = 0", true);
|
||||
execute("barcode_reader.disable()", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void onPuckBarcode(String datamatrix){
|
||||
if (puckLoading){
|
||||
getMainFrame().setPuckDatamatrix(datamatrix);
|
||||
System.out.println(datamatrix);
|
||||
}
|
||||
}
|
||||
|
||||
void onPuckDetectionChanged(){
|
||||
if (puckLoading){
|
||||
String datamatrix = getMainFrame().getPuckDatamatrix();
|
||||
Puck.Detection[] detection = basePlate.getDetection();
|
||||
for (int i=0; i< Controller.NUMBER_OF_PUCKS; i++){
|
||||
Puck puck = basePlate.getPucks()[i];
|
||||
if (isSelectedPuck(puck)){
|
||||
boolean detectedPuckInserted = (currentDetection[i] != Puck.Detection.Present) && (detection[i] == Puck.Detection.Present);
|
||||
boolean detectedPuckRemoved = (currentDetection[i] != Puck.Detection.Empty) && (detection[i] == Puck.Detection.Empty);
|
||||
if (detectedPuckInserted){
|
||||
System.out.println("Detected puck at position: " + puck.getName() + " - Datamatrix: " + (datamatrix.isEmpty() ? null : datamatrix));
|
||||
if (!datamatrix.isEmpty()){
|
||||
getMainFrame().setPuckDatamatrix(null);
|
||||
setPuckDatamatrix(puck, datamatrix);
|
||||
}
|
||||
} else if (detectedPuckRemoved){
|
||||
System.out.println("Removed puck from position " + puck.getName() + " - Datamatrix: " + puck.getId());
|
||||
setPuckDatamatrix(puck, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentDetection = detection;
|
||||
}
|
||||
}
|
||||
|
||||
void setPuckDatamatrix(Puck puck, String datamatrix){
|
||||
if ( ((puck.getId()==null) && (datamatrix!=null)) ||
|
||||
(puck.getId()!=null) && (!puck.getId().equals(datamatrix))){
|
||||
System.out.println("Setting to: " + puck.getName() + " datamatrix: " + datamatrix);
|
||||
|
||||
puck.setId(datamatrix);
|
||||
getMainFrame().refresh();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -171,24 +171,23 @@ public class PuckGraphics {
|
||||
}
|
||||
|
||||
Font getLabelFont() {
|
||||
|
||||
if (basePlateGraphics!=null) {
|
||||
return new Font("Segoe UI", Font.BOLD, 12);
|
||||
}
|
||||
return new Font("Segoe UI", Font.BOLD, 18);
|
||||
}
|
||||
return new Font("Segoe UI", Font.BOLD, 14);
|
||||
}
|
||||
|
||||
Font getIdFont() {
|
||||
if (basePlateGraphics!=null) {
|
||||
return new Font("Times New Roman", Font.PLAIN, 9);
|
||||
return new Font("Segoe UI", Font.PLAIN, 9);
|
||||
}
|
||||
return new Font("Times New Roman", Font.PLAIN, 12);
|
||||
return new Font("Segoe UI", Font.PLAIN, 9);
|
||||
}
|
||||
|
||||
Point getLabelDrawPosition(String text, Graphics g, boolean drawBackground) {
|
||||
Point getLabelDrawPosition(String text, Graphics g, boolean drawBackground, boolean hasId) {
|
||||
Point pos = drawBackground ? getDrawPosition() : getDrawPosition(labelPositionWithImage);
|
||||
Dimension textSize = SwingUtils.getTextSize(text, g.getFontMetrics());
|
||||
return new Point(pos.x - textSize.width / 2 , pos.y + (g.getFontMetrics().getAscent() / 2));
|
||||
return new Point(pos.x - textSize.width / 2 , pos.y + (g.getFontMetrics().getAscent() / 2) - (hasId ? 5: 0));
|
||||
}
|
||||
|
||||
Color getBorderColor(boolean drawBackground) {
|
||||
@@ -200,7 +199,7 @@ public class PuckGraphics {
|
||||
return new Color(0, 0, 0);
|
||||
}
|
||||
return Color.GRAY;
|
||||
}
|
||||
}
|
||||
return isHighlithted() ? new Color(0, 208, 0) : new Color(0, 128, 0);
|
||||
}
|
||||
|
||||
@@ -266,19 +265,17 @@ public class PuckGraphics {
|
||||
}
|
||||
|
||||
//Draw text
|
||||
String id = puck.getId();
|
||||
boolean hasId = drawId && (id!= null);
|
||||
String text = puck.getName(); //String.valueOf(getIndex() + 1);
|
||||
g.setColor(getLabelColor(drawBackground));
|
||||
g.setFont(getLabelFont());
|
||||
Point labelPosition = getLabelDrawPosition(text, g, drawBackground);
|
||||
Point labelPosition = getLabelDrawPosition(text, g, drawBackground, hasId);
|
||||
g.drawString(text, labelPosition.x, labelPosition.y);
|
||||
if (drawId) {
|
||||
String id = puck.getId();
|
||||
if (id != null) {
|
||||
labelPosition.setLocation(labelPosition.x, labelPosition.y - 6);
|
||||
g.setFont(getIdFont());
|
||||
Dimension textSize = SwingUtils.getTextSize(id, g.getFontMetrics());
|
||||
g.drawString(id, getDrawPosition().x - textSize.width/2 , getDrawPosition().y + 10 );
|
||||
}
|
||||
if (hasId) {
|
||||
g.setFont(getIdFont());
|
||||
Dimension textSize = SwingUtils.getTextSize(id, g.getFontMetrics());
|
||||
g.drawString(id, getDrawPosition().x - textSize.width/2 , getDrawPosition().y + 14);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user