This commit is contained in:
2018-04-19 17:35:54 +02:00
parent 1e2fee44d0
commit 109e81aecb
12 changed files with 315 additions and 181 deletions

View File

@@ -6,8 +6,11 @@ package ch.psi.mxsc;
import ch.psi.pshell.core.DevicePoolListener;
import ch.psi.pshell.device.Device;
import ch.psi.pshell.device.DeviceAdapter;
import ch.psi.pshell.device.DeviceListener;
import ch.psi.pshell.device.GenericDevice;
import ch.psi.pshell.ui.Panel;
import ch.psi.utils.State;
/**
*
@@ -16,6 +19,7 @@ public class Controller {
static Controller instance;
final BasePlate basePlate;
final Panel mainFrame;
Device hexaposi;
public static Controller getInstance(){
return instance;
@@ -26,9 +30,9 @@ public class Controller {
}
enum PuckSensorAccess{
RaspberryPi,
Esera;
}
RaspberryPi,
Esera;
}
final PuckSensorAccess puckSensorAccess = PuckSensorAccess.RaspberryPi;
@@ -36,6 +40,7 @@ public class Controller {
static String PUCK_ESERA_DEVICE = "onewire";
public static final int NUMBER_OF_PUCKS = 30;
private Controller(Panel mainFrame){
basePlate = new BasePlate();
@@ -50,6 +55,10 @@ public class Controller {
public Panel getMainFrame(){
return mainFrame;
}
public void updateView(){
getMainFrame().repaint();
}
void onInitialize(int runCount) {
GenericDevice former = getMainFrame().getDevice("BasePlate");
@@ -83,7 +92,13 @@ public class Controller {
detection = new EseraDetection((Device) getMainFrame().getDevice(PUCK_ESERA_DEVICE));
}
}
hexaposi = (Device) getMainFrame().getDevice("hexiposi");
hexaposi.addListener(new DeviceAdapter() {
@Override
public void onValueChanged(Device device, Object value, Object former) {
updateView();
}
});
}
final PuckState[] puckState;
@@ -100,11 +115,27 @@ public class Controller {
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()){
puck.clear();
}
getMainFrame().repaint();
updateView();
}
public String getHexaposiPosition(){
return (String) hexaposi.take();
}
}