This commit is contained in:
gac-S_Changer
2018-06-08 16:27:07 +02:00
parent 01528ae2b1
commit eb45f26d1c
6 changed files with 703 additions and 164 deletions

View File

@@ -0,0 +1,230 @@
package ch.psi.mxsc;
import ch.psi.pshell.device.Device;
import ch.psi.pshell.device.DeviceAdapter;
import ch.psi.pshell.device.GenericDevice;
import ch.psi.pshell.imaging.Data;
import ch.psi.pshell.imaging.ImageListener;
import ch.psi.pshell.swing.Led;
import ch.psi.utils.State;
import java.awt.Color;
import java.awt.image.BufferedImage;
/**
*
*/
public class DevicesPanel extends javax.swing.JPanel {
GenericDevice robot;
GenericDevice hexiposi;
GenericDevice microscan;
GenericDevice wago;
GenericDevice laser;
GenericDevice puck_detection;
GenericDevice img;
/**
* Creates new form DevicesPanel
*/
public DevicesPanel() {
initComponents();
}
GenericDevice[] getDevices(){
return new GenericDevice[]{robot, hexiposi, microscan, wago, laser, puck_detection};
}
final DeviceAdapter deviceListener = new DeviceAdapter() {
@Override
public void onStateChanged(Device device, State state, State former) {
update();
}
};
void initialize(){
for (GenericDevice dev : getDevices()){
if (dev!=null){
dev.removeListener(deviceListener);
}
}
robot = Controller.getInstance().getDevice("robot");
hexiposi = Controller.getInstance().getDevice("hexiposi");
microscan = Controller.getInstance().getDevice("microscan");
wago = Controller.getInstance().getDevice("wago");
laser = Controller.getInstance().getDevice("ue");
puck_detection = Controller.getInstance().getDevice("puck_detection");
img = Controller.getInstance().getDevice("img");
update();
for (GenericDevice dev : getDevices()){
if (dev!=null){
dev.addListener(deviceListener);
}
}
}
void update(){
setLedState(ledBarcodeReader, microscan);
setLedState(ledCamera, img);
setLedState(ledHexiposi, hexiposi);
setLedState(ledLaser, laser);
setLedState(ledPuckDetection, puck_detection);
setLedState(ledRobot, robot);
setLedState(ledWago, wago);
}
void setLedState(Led led, GenericDevice dev){
if ((dev==null) || (dev.getState()==null)){
led.setColor(Color.black);
} else {
switch (dev.getState()){
case Ready:
led.setColor(Color.green);
break;
case Initializing:
case Paused:
case Busy:
case Disabled:
led.setColor(Color.orange);
break;
case Invalid:
case Closing:
case Fault:
case Offline:
led.setColor(Color.red);
break;
default:
led.setColor(Color.darkGray);
break;
}
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel24 = new javax.swing.JLabel();
ledRobot = new ch.psi.pshell.swing.Led();
ledWago = new ch.psi.pshell.swing.Led();
jLabel25 = new javax.swing.JLabel();
jLabel26 = new javax.swing.JLabel();
ledLaser = new ch.psi.pshell.swing.Led();
jLabel27 = new javax.swing.JLabel();
ledCamera = new ch.psi.pshell.swing.Led();
jLabel28 = new javax.swing.JLabel();
ledHexiposi = new ch.psi.pshell.swing.Led();
jLabel29 = new javax.swing.JLabel();
ledBarcodeReader = new ch.psi.pshell.swing.Led();
jLabel30 = new javax.swing.JLabel();
ledPuckDetection = new ch.psi.pshell.swing.Led();
jLabel24.setText("Robot");
jLabel25.setText("Wago");
jLabel26.setText("Laser");
jLabel27.setText("Camera");
jLabel28.setText("Hexiposi");
jLabel29.setText("Barcode Reader");
jLabel30.setText("Puck Detection");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(ledRobot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel24))
.addGroup(layout.createSequentialGroup()
.addComponent(ledWago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel25))
.addGroup(layout.createSequentialGroup()
.addComponent(ledLaser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel26))
.addGroup(layout.createSequentialGroup()
.addComponent(ledCamera, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel27))
.addGroup(layout.createSequentialGroup()
.addComponent(ledHexiposi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel28))
.addGroup(layout.createSequentialGroup()
.addComponent(ledBarcodeReader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel29))
.addGroup(layout.createSequentialGroup()
.addComponent(ledPuckDetection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel30)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ledRobot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel24))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ledWago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel25))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ledLaser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel26))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ledCamera, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel27))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ledHexiposi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel28))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ledBarcodeReader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel29))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ledPuckDetection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel30))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel24;
private javax.swing.JLabel jLabel25;
private javax.swing.JLabel jLabel26;
private javax.swing.JLabel jLabel27;
private javax.swing.JLabel jLabel28;
private javax.swing.JLabel jLabel29;
private javax.swing.JLabel jLabel30;
private ch.psi.pshell.swing.Led ledBarcodeReader;
private ch.psi.pshell.swing.Led ledCamera;
private ch.psi.pshell.swing.Led ledHexiposi;
private ch.psi.pshell.swing.Led ledLaser;
private ch.psi.pshell.swing.Led ledPuckDetection;
private ch.psi.pshell.swing.Led ledRobot;
private ch.psi.pshell.swing.Led ledWago;
// End of variables declaration//GEN-END:variables
}