This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
|
||||
*/
|
||||
|
||||
package ch.psi.mxsc;
|
||||
|
||||
import ch.psi.pshell.core.Context;
|
||||
import ch.psi.pshell.core.DevicePoolListener;
|
||||
import ch.psi.pshell.device.Device;
|
||||
import ch.psi.pshell.device.DeviceAdapter;
|
||||
@@ -13,85 +13,88 @@ import ch.psi.pshell.device.ProcessVariableBase;
|
||||
import ch.psi.pshell.device.ReadbackDevice;
|
||||
import ch.psi.pshell.ui.Panel;
|
||||
import ch.psi.utils.State;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class Controller {
|
||||
|
||||
static Controller instance;
|
||||
final BasePlate basePlate;
|
||||
final BasePlate basePlate;
|
||||
final Panel mainFrame;
|
||||
Device hexaposi;
|
||||
|
||||
public static Controller getInstance(){
|
||||
|
||||
public static Controller getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
static void createInstance(Panel mainFrame){
|
||||
|
||||
static void createInstance(Panel mainFrame) {
|
||||
instance = new Controller(mainFrame);
|
||||
}
|
||||
|
||||
enum PuckSensorAccess{
|
||||
|
||||
enum PuckSensorAccess {
|
||||
RaspberryPi,
|
||||
Esera;
|
||||
}
|
||||
|
||||
|
||||
|
||||
final PuckSensorAccess puckSensorAccess = PuckSensorAccess.RaspberryPi;
|
||||
|
||||
|
||||
static String PUCK_ESERA_DEVICE = "onewire";
|
||||
|
||||
public static final int NUMBER_OF_PUCKS = 30;
|
||||
|
||||
|
||||
private Controller(Panel mainFrame){
|
||||
public static final int NUMBER_OF_PUCKS = 30;
|
||||
|
||||
private Controller(Panel mainFrame) {
|
||||
basePlate = new BasePlate();
|
||||
puckState = new PuckState[NUMBER_OF_PUCKS];
|
||||
for (int i=0; i<NUMBER_OF_PUCKS; i++ ){
|
||||
puckState[i] = new PuckState(i+1);
|
||||
}
|
||||
this.mainFrame =mainFrame;
|
||||
for (int i = 0; i < NUMBER_OF_PUCKS; i++) {
|
||||
puckState[i] = new PuckState(i + 1);
|
||||
}
|
||||
this.mainFrame = mainFrame;
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public Panel getMainFrame(){
|
||||
}
|
||||
|
||||
public Panel getMainFrame() {
|
||||
return mainFrame;
|
||||
}
|
||||
|
||||
public void updateView(){
|
||||
}
|
||||
|
||||
public void updateView() {
|
||||
getMainFrame().repaint();
|
||||
}
|
||||
|
||||
|
||||
void onInitialize(int runCount) {
|
||||
GenericDevice former = getMainFrame().getDevice("BasePlate");
|
||||
if (former!=null){
|
||||
if (former != null) {
|
||||
getMainFrame().removeDevice(former);
|
||||
}
|
||||
getMainFrame().addDevice(basePlate);
|
||||
clearPuckStates();
|
||||
|
||||
if (puckSensorAccess == PuckSensorAccess.Esera){
|
||||
getMainFrame().addDevice(basePlate);
|
||||
clearPuckStates();
|
||||
|
||||
if (puckSensorAccess == PuckSensorAccess.Esera) {
|
||||
getMainFrame().getContext().getDevicePool().addListener(new DevicePoolListener() {
|
||||
@Override
|
||||
public void onDeviceAdded(GenericDevice dev) {
|
||||
if (dev.getName().equals(PUCK_ESERA_DEVICE)){
|
||||
if (dev.getName().equals(PUCK_ESERA_DEVICE)) {
|
||||
detection = new EseraDetection((Device) dev);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeviceRemoved(GenericDevice dev) {
|
||||
if (dev.getName().equals(PUCK_ESERA_DEVICE)){
|
||||
detection.close();
|
||||
public void onDeviceRemoved(GenericDevice dev) {
|
||||
if (dev.getName().equals(PUCK_ESERA_DEVICE)) {
|
||||
detection.close();
|
||||
detection = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (detection != null){
|
||||
});
|
||||
if (detection != null) {
|
||||
detection.close();
|
||||
detection = null;
|
||||
}
|
||||
if ((Device) getMainFrame().getDevice(PUCK_ESERA_DEVICE) != null){
|
||||
if ((Device) getMainFrame().getDevice(PUCK_ESERA_DEVICE) != null) {
|
||||
detection = new EseraDetection((Device) getMainFrame().getDevice(PUCK_ESERA_DEVICE));
|
||||
}
|
||||
}
|
||||
@@ -103,51 +106,79 @@ public class Controller {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
final PuckState[] puckState;
|
||||
public PuckState[] getPuckStates(){
|
||||
|
||||
public PuckState[] getPuckStates() {
|
||||
return puckState;
|
||||
}
|
||||
EseraDetection detection;
|
||||
|
||||
|
||||
//From 1 to PUCKS_NUMBER
|
||||
public PuckState getPuckState(int id) throws Exception{
|
||||
if ((id<=0) || (id>NUMBER_OF_PUCKS)){
|
||||
throw new Exception("invalid puck id: "+ id);
|
||||
public PuckState getPuckState(int id) throws Exception {
|
||||
if ((id <= 0) || (id > NUMBER_OF_PUCKS)) {
|
||||
throw new Exception("invalid puck id: " + id);
|
||||
}
|
||||
return getPuckStates()[id-1];
|
||||
}
|
||||
|
||||
public int getPuckIndex(int address) throws Exception{
|
||||
if ((address<=0) || (address>NUMBER_OF_PUCKS)){
|
||||
throw new Exception("invalid puck address: "+ address);
|
||||
}
|
||||
for (int i=0; i<Puck.ADDRESSES.length; i++){
|
||||
if (Puck.ADDRESSES[i] == address){
|
||||
return i+1;
|
||||
}
|
||||
return getPuckStates()[id - 1];
|
||||
}
|
||||
|
||||
public int getPuckIndex(int address) throws Exception {
|
||||
if ((address <= 0) || (address > NUMBER_OF_PUCKS)) {
|
||||
throw new Exception("invalid puck address: " + address);
|
||||
}
|
||||
for (int i = 0; i < Puck.ADDRESSES.length; i++) {
|
||||
if (Puck.ADDRESSES[i] == address) {
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void clearPuckStates(){
|
||||
for (PuckState puck:getPuckStates()){
|
||||
|
||||
public void clearPuckStates() {
|
||||
for (PuckState puck : getPuckStates()) {
|
||||
puck.clear();
|
||||
}
|
||||
updateView();
|
||||
}
|
||||
|
||||
|
||||
public String getHexiposiPosition(){
|
||||
return (String) ((ReadbackDevice)hexaposi).getReadback().take();
|
||||
public String getHexiposiPosition() {
|
||||
return (String) ((ReadbackDevice) hexaposi).getReadback().take();
|
||||
}
|
||||
|
||||
public Boolean isLedRoomTemp(){
|
||||
try{
|
||||
return ((ProcessVariableBase)getMainFrame().getDevice("led_ctrl_1")).getConfig().maxValue <= 0.50;
|
||||
} catch (Exception ex){
|
||||
|
||||
public Boolean isLedRoomTemp() {
|
||||
try {
|
||||
return ((ProcessVariableBase) getMainFrame().getDevice("led_ctrl_1")).getConfig().maxValue <= 0.50;
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void imageDetectPucks() throws Context.ContextStateException {
|
||||
imageDetectPucks(null, null, null);
|
||||
}
|
||||
|
||||
public void imageDetectPucks(JComponent plot, JComponent renderer, JComponent text) throws Context.ContextStateException {
|
||||
Map args = new HashMap();
|
||||
args.put("PLOT", plot);
|
||||
args.put("RENDERER", renderer);
|
||||
args.put("TEXT", text);
|
||||
getMainFrame().runAsync("imgproc/LedDetectionProc", args).handle((ret, ex) -> {
|
||||
if (ex == null) {
|
||||
Map<String, List<String>> map = (Map<String, List<String>>) ret;
|
||||
for (Puck.ImageDetection id : Puck.ImageDetection.values()) {
|
||||
for (String name : map.get(id.toString())) {
|
||||
Puck p = basePlate.getPuckByName(name);
|
||||
if (p != null) {
|
||||
p.setImageDetection(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
getMainFrame().showException((Exception)ex);
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
updateView();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user