Aded puck detection using Esera

This commit is contained in:
gac-S_Changer
2017-03-16 16:18:09 +01:00
parent 4d0b19d801
commit ff1bfbe15c
4 changed files with 188 additions and 100 deletions

View File

@@ -4,6 +4,8 @@
package ch.psi.mxsc;
import ch.psi.pshell.core.DevicePoolListener;
import ch.psi.pshell.device.Device;
import ch.psi.pshell.device.GenericDevice;
import ch.psi.pshell.ui.Panel;
import ch.psi.utils.swing.SwingUtils;
@@ -16,7 +18,32 @@ public class MainPanel extends Panel {
BasePlate basePlate;
/** Creates new form Panel */
static MainPanel instance;
static String PUCK_DETECTION_DEVICE = "onewire";
public static final int NUMBER_OF_PUCKS = 30;
final PuckState[] puckState;
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);
}
return getPuckStates()[id-1];
}
public void clearPuckStates(){
for (PuckState puck:getPuckStates()){
puck.clear();
}
repaint();
}
public static MainPanel getInstance(){
return instance;
}
@@ -26,20 +53,46 @@ public class MainPanel extends Panel {
basePlate = new BasePlate();
SwingUtils.setEnumCombo(comboMode, BasePlatePanel.Mode.class);
comboMode.setSelectedItem(basePlatePanel.getMode());
this.setPersistedComponents(new Component[]{comboMode});
this.setPersistedComponents(new Component[]{comboMode});
puckState = new PuckState[NUMBER_OF_PUCKS];
for (int i=0; i<NUMBER_OF_PUCKS; i++ ){
puckState[i] = new PuckState(i+1);
}
}
@Override
public void onInitialize(int runCount) {
basePlatePanel.setDevice(basePlate);
//basePlatePanel.setShowSamples(true);
//puckPanel.setDevice(basePlate.getPucks()[0]);
GenericDevice former = getDevice("BasePlate");
if (former!=null){
removeDevice(former);
}
addDevice(basePlate);
addDevice(basePlate);
clearPuckStates();
getContext().getDevicePool().addListener(new DevicePoolListener() {
@Override
public void onDeviceAdded(GenericDevice dev) {
if (dev.getName().equals(PUCK_DETECTION_DEVICE)){
detection = new EseraDetection((Device) dev);
}
}
@Override
public void onDeviceRemoved(GenericDevice dev) {
if (dev.getName().equals(PUCK_DETECTION_DEVICE)){
detection.close();
detection = null;
}
}
});
if (detection != null){
detection.close();
detection = null;
}
if ((Device) getDevice(PUCK_DETECTION_DEVICE) != null){
detection = new EseraDetection((Device) getDevice(PUCK_DETECTION_DEVICE));
}
}