397 lines
19 KiB
Java
397 lines
19 KiB
Java
import ch.psi.mxsc.Puck;
|
|
import ch.psi.mxsc.PuckDetection;
|
|
import ch.psi.mxsc.PuckState;
|
|
import ch.psi.mxsc.PuckState.SwitchState;
|
|
import ch.psi.pshell.framework.Context;
|
|
import ch.psi.pshell.swing.DevicePanel;
|
|
import ch.psi.pshell.swing.SwingUtils;
|
|
import java.awt.Color;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public class PuckDetectionPanel extends DevicePanel {
|
|
|
|
public PuckDetectionPanel() {
|
|
initComponents();
|
|
int row = 0;
|
|
for (String segment : new String[]{"A", "B", "C", "D", "E", "F"}){
|
|
for (int puck=1; puck<=5; puck++){
|
|
table.getModel().setValueAt(segment+puck, row++, 0);
|
|
}
|
|
}
|
|
this.startTimer(100);
|
|
}
|
|
|
|
@Override
|
|
public PuckDetection getDevice(){
|
|
return (PuckDetection) super.getDevice();
|
|
}
|
|
|
|
@Override
|
|
public void onTimer(){
|
|
if ((getDevice()!=null) && getDevice().getState().isInitialized()){
|
|
ledEnabled.setColor(getDevice().isEnabled() ? Color.GREEN : Color.DARK_GRAY);
|
|
} else {
|
|
ledEnabled.setColor(Color.BLACK);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void onDeviceCacheChanged(Object value, Object former, long timestamp, boolean arg3) {
|
|
for (int row=0; row< 30; row++){
|
|
String name = table.getModel().getValueAt(row, 0).toString();
|
|
//int id = row+1;
|
|
try {
|
|
Puck puck = getDevice().getPuck(name);
|
|
int id = puck.getIndex() + 1;
|
|
PuckState state = getDevice().getPuckState(id);
|
|
table.getModel().setValueAt(state.online, row, 1);
|
|
table.getModel().setValueAt((SwitchState.Off == state.mecSwitch) ? "" : String.valueOf(state.mecSwitch), row, 2);
|
|
table.getModel().setValueAt((SwitchState.Off == state.indSwitch) ? "" : String.valueOf(state.indSwitch), row, 3);
|
|
table.getModel().setValueAt(puck.getDetection() == null ? "" : puck.getDetection(), row, 4);
|
|
table.getModel().setValueAt(puck.getPuckType() == null ? "" : puck.getPuckType(), row, 5);
|
|
} catch (Exception ex) {
|
|
ex.printStackTrace();
|
|
table.getModel().setValueAt(false, row, 1);
|
|
table.getModel().setValueAt(false, row, 2);
|
|
table.getModel().setValueAt(false, row, 3);
|
|
table.getModel().setValueAt("", row, 4);
|
|
table.getModel().setValueAt("", row, 5);
|
|
}
|
|
}
|
|
}
|
|
|
|
void execute(String statement, boolean showReturn){
|
|
try {
|
|
Context.getInterpreter().evalLineBackgroundAsync(statement).handle((ret, ex) -> {
|
|
if (ex != null){
|
|
showException((Exception)ex);
|
|
} else if (showReturn){
|
|
SwingUtils.showMessage(this, "Return", String.valueOf(ret));
|
|
}
|
|
return ret;
|
|
});
|
|
} catch (Exception ex) {
|
|
showException(ex);
|
|
}
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
|
private void initComponents() {
|
|
|
|
jPanel3 = new javax.swing.JPanel();
|
|
buttonPuckDetCheck = new javax.swing.JButton();
|
|
buttonPuckDetStop = new javax.swing.JButton();
|
|
buttonPuckDetStart = new javax.swing.JButton();
|
|
jPanel1 = new javax.swing.JPanel();
|
|
jScrollPane1 = new javax.swing.JScrollPane();
|
|
table = new javax.swing.JTable();
|
|
buttonConfigure = new javax.swing.JButton();
|
|
deviceStatePanel1 = new ch.psi.pshell.swing.DeviceStatePanel();
|
|
jPanel2 = new javax.swing.JPanel();
|
|
ledEnabled = new ch.psi.pshell.swing.Led();
|
|
jLabel1 = new javax.swing.JLabel();
|
|
panelPowerCtr = new javax.swing.JPanel();
|
|
buttonDisable = new javax.swing.JButton();
|
|
buttonEnable = new javax.swing.JButton();
|
|
|
|
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Raspberry Pi "));
|
|
|
|
buttonPuckDetCheck.setText("Check");
|
|
buttonPuckDetCheck.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonPuckDetCheckActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
buttonPuckDetStop.setText("Stop");
|
|
buttonPuckDetStop.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonPuckDetStopActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
buttonPuckDetStart.setText("Start");
|
|
buttonPuckDetStart.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonPuckDetStartActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
|
|
jPanel3.setLayout(jPanel3Layout);
|
|
jPanel3Layout.setHorizontalGroup(
|
|
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(jPanel3Layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addComponent(buttonPuckDetCheck)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 107, Short.MAX_VALUE)
|
|
.addComponent(buttonPuckDetStop)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 108, Short.MAX_VALUE)
|
|
.addComponent(buttonPuckDetStart)
|
|
.addContainerGap())
|
|
);
|
|
|
|
jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonPuckDetCheck, buttonPuckDetStart, buttonPuckDetStop});
|
|
|
|
jPanel3Layout.setVerticalGroup(
|
|
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(jPanel3Layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
|
.addComponent(buttonPuckDetCheck)
|
|
.addComponent(buttonPuckDetStop)
|
|
.addComponent(buttonPuckDetStart))
|
|
.addContainerGap())
|
|
);
|
|
|
|
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Detection"));
|
|
|
|
table.setModel(new javax.swing.table.DefaultTableModel(
|
|
new Object [][] {
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null},
|
|
{null, null, null, null, null, null}
|
|
},
|
|
new String [] {
|
|
"Puck", "Online", "Mechanical", "Inductive", "Detection", "Image"
|
|
}
|
|
) {
|
|
Class[] types = new Class [] {
|
|
java.lang.String.class, java.lang.Boolean.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
|
|
};
|
|
boolean[] canEdit = new boolean [] {
|
|
false, false, false, false, false, false
|
|
};
|
|
|
|
public Class getColumnClass(int columnIndex) {
|
|
return types [columnIndex];
|
|
}
|
|
|
|
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
|
return canEdit [columnIndex];
|
|
}
|
|
});
|
|
jScrollPane1.setViewportView(table);
|
|
|
|
buttonConfigure.setText("Configure");
|
|
buttonConfigure.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonConfigureActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
|
|
jPanel1.setLayout(jPanel1Layout);
|
|
jPanel1Layout.setHorizontalGroup(
|
|
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(jPanel1Layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
|
|
.addGroup(jPanel1Layout.createSequentialGroup()
|
|
.addGap(0, 0, Short.MAX_VALUE)
|
|
.addComponent(buttonConfigure)
|
|
.addGap(0, 0, Short.MAX_VALUE)))
|
|
.addContainerGap())
|
|
);
|
|
jPanel1Layout.setVerticalGroup(
|
|
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(jPanel1Layout.createSequentialGroup()
|
|
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addComponent(buttonConfigure)
|
|
.addContainerGap())
|
|
);
|
|
|
|
deviceStatePanel1.setDeviceName("puck_detection");
|
|
|
|
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Enabling"));
|
|
|
|
ledEnabled.setFont(new java.awt.Font("SansSerif", 0, 18)); // NOI18N
|
|
|
|
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
|
|
jLabel1.setText("Enabled");
|
|
|
|
buttonDisable.setText("Disable");
|
|
buttonDisable.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonDisableActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
buttonEnable.setText("Enable");
|
|
buttonEnable.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonEnableActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
javax.swing.GroupLayout panelPowerCtrLayout = new javax.swing.GroupLayout(panelPowerCtr);
|
|
panelPowerCtr.setLayout(panelPowerCtrLayout);
|
|
panelPowerCtrLayout.setHorizontalGroup(
|
|
panelPowerCtrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(panelPowerCtrLayout.createSequentialGroup()
|
|
.addGap(0, 0, 0)
|
|
.addComponent(buttonEnable)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
|
|
.addComponent(buttonDisable))
|
|
);
|
|
panelPowerCtrLayout.setVerticalGroup(
|
|
panelPowerCtrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(panelPowerCtrLayout.createSequentialGroup()
|
|
.addGap(0, 0, 0)
|
|
.addGroup(panelPowerCtrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
|
|
.addComponent(buttonDisable, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addComponent(buttonEnable))
|
|
.addGap(0, 0, 0))
|
|
);
|
|
|
|
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
|
|
jPanel2.setLayout(jPanel2Layout);
|
|
jPanel2Layout.setHorizontalGroup(
|
|
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(jPanel2Layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addComponent(ledEnabled, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
|
.addComponent(panelPowerCtr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
|
);
|
|
jPanel2Layout.setVerticalGroup(
|
|
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(jPanel2Layout.createSequentialGroup()
|
|
.addGap(4, 4, 4)
|
|
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
|
|
.addComponent(jLabel1)
|
|
.addComponent(ledEnabled, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addComponent(panelPowerCtr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
.addGap(2, 2, 2))
|
|
);
|
|
|
|
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
|
this.setLayout(layout);
|
|
layout.setHorizontalGroup(
|
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addComponent(deviceStatePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addGap(0, 0, 0)
|
|
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addGap(0, 0, 0))
|
|
);
|
|
layout.setVerticalGroup(
|
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addGap(0, 0, 0)
|
|
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addGap(0, 0, 0)
|
|
.addComponent(deviceStatePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addGap(0, 0, 0))
|
|
);
|
|
}// </editor-fold>//GEN-END:initComponents
|
|
|
|
private void buttonPuckDetCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPuckDetCheckActionPerformed
|
|
execute("check_puck_detection()", true);
|
|
}//GEN-LAST:event_buttonPuckDetCheckActionPerformed
|
|
|
|
private void buttonPuckDetStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPuckDetStopActionPerformed
|
|
execute("stop_puck_detection()", false);
|
|
}//GEN-LAST:event_buttonPuckDetStopActionPerformed
|
|
|
|
private void buttonPuckDetStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPuckDetStartActionPerformed
|
|
execute("start_puck_detection()", false);
|
|
}//GEN-LAST:event_buttonPuckDetStartActionPerformed
|
|
|
|
private void buttonConfigureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigureActionPerformed
|
|
try {
|
|
if (table.getSelectedRow()<0){
|
|
throw new Exception("Select a puck");
|
|
}
|
|
String name = table.getModel().getValueAt(table.getSelectedRow(), 0).toString();
|
|
Puck puck = getDevice().getPuck(name);
|
|
DevicePanel.showConfigEditor(this, puck, true, false);
|
|
} catch (Exception ex) {
|
|
showException(ex);
|
|
}
|
|
|
|
}//GEN-LAST:event_buttonConfigureActionPerformed
|
|
|
|
private void buttonDisableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDisableActionPerformed
|
|
try{
|
|
getDevice().setEnabled(false);
|
|
} catch (Exception ex){
|
|
this.showException(ex);
|
|
}
|
|
}//GEN-LAST:event_buttonDisableActionPerformed
|
|
|
|
private void buttonEnableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonEnableActionPerformed
|
|
try{
|
|
getDevice().setEnabled(true);
|
|
} catch (Exception ex){
|
|
this.showException(ex);
|
|
}
|
|
}//GEN-LAST:event_buttonEnableActionPerformed
|
|
|
|
|
|
|
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
|
private javax.swing.JButton buttonConfigure;
|
|
private javax.swing.JButton buttonDisable;
|
|
private javax.swing.JButton buttonDisable2;
|
|
private javax.swing.JButton buttonEnable;
|
|
private javax.swing.JButton buttonEnable2;
|
|
private javax.swing.JButton buttonPuckDetCheck;
|
|
private javax.swing.JButton buttonPuckDetStart;
|
|
private javax.swing.JButton buttonPuckDetStop;
|
|
private ch.psi.pshell.swing.DeviceStatePanel deviceStatePanel1;
|
|
private javax.swing.JLabel jLabel1;
|
|
private javax.swing.JLabel jLabel3;
|
|
private javax.swing.JPanel jPanel1;
|
|
private javax.swing.JPanel jPanel2;
|
|
private javax.swing.JPanel jPanel3;
|
|
private javax.swing.JPanel jPanel5;
|
|
private javax.swing.JScrollPane jScrollPane1;
|
|
private ch.psi.pshell.swing.Led ledEnabled;
|
|
private ch.psi.pshell.swing.Led ledPowered2;
|
|
private javax.swing.JPanel panelPowerCtr;
|
|
private javax.swing.JPanel panelPowerCtr2;
|
|
private javax.swing.JTable table;
|
|
// End of variables declaration//GEN-END:variables
|
|
}
|