This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user