This commit is contained in:
gac-S_Changer
2018-12-03 12:17:40 +01:00
commit bdf5049f96
204 changed files with 18029 additions and 0 deletions

View File

@@ -0,0 +1,251 @@
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.core.Context;
import ch.psi.pshell.swing.DevicePanel;
import ch.psi.utils.swing.SwingUtils;
/**
*
*/
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);
}
}
}
@Override
public PuckDetection getDevice(){
return (PuckDetection) super.getDevice();
}
@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.getInstance().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();
deviceStatePanel1 = new ch.psi.pshell.swing.DeviceStatePanel();
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Raspberry Pi "));
buttonPuckDetCheck.setText("Ckeck");
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);
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()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)
.addContainerGap())
);
deviceStatePanel1.setDeviceName("puck_detection");
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)
);
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(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
// Variables declaration - do not modify//GEN-BEGIN:variables
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.JPanel jPanel1;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable table;
// End of variables declaration//GEN-END:variables
}