|
|
|
@@ -4,6 +4,7 @@ import ch.spherICIT.communication.ConnectionState; |
|
|
|
import ch.spherICIT.communication.ConnectionStateInfo; |
|
|
|
import ch.spherICIT.communication.IConnectionState; |
|
|
|
import ch.spherICIT.communication.SerialCommHandler; |
|
|
|
import ch.spherICIT.communication.StatusLoopWorker; |
|
|
|
import ch.spherICIT.components.led.Led; |
|
|
|
import ch.spherICIT.components.switchbtn.EventSwitchSelected; |
|
|
|
import ch.spherICIT.components.switchbtn.SwitchButton; |
|
|
|
@@ -19,7 +20,11 @@ import javax.swing.JComboBox; |
|
|
|
import javax.swing.JComponent; |
|
|
|
import javax.swing.JLabel; |
|
|
|
import javax.swing.JPanel; |
|
|
|
import javax.swing.JSlider; |
|
|
|
import javax.swing.JTextField; |
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
import javax.swing.event.ChangeEvent; |
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
import javax.swing.plaf.FontUIResource; |
|
|
|
import javax.swing.text.StyleContext; |
|
|
|
import java.awt.Color; |
|
|
|
@@ -48,6 +53,7 @@ import static ch.spherICIT.main.LogWindow.SendDirection.OUT; |
|
|
|
public class MainPanel { |
|
|
|
|
|
|
|
public static final long COMM_TIMEOUT = 3000L; |
|
|
|
public static final String MIN_ARDUINO_VERSION = "V1.3.0"; |
|
|
|
|
|
|
|
private JPanel mainPanel; |
|
|
|
private JLabel serPortLbl; |
|
|
|
@@ -61,6 +67,9 @@ public class MainPanel { |
|
|
|
private Led relaisPwrLed; |
|
|
|
private Led camStepperPwrLed; |
|
|
|
private JButton logWindowBtn; |
|
|
|
private JSlider rotationSlider; |
|
|
|
private JTextField rotationValTxtFld; |
|
|
|
private JButton rotateBtn; |
|
|
|
private final LogWindow logWindow; |
|
|
|
|
|
|
|
private Set<IConnectionState> connectionStateListeners; |
|
|
|
@@ -69,6 +78,7 @@ public class MainPanel { |
|
|
|
private SerialPort selectedSerialPort; |
|
|
|
private FSSerialPortMessageListener serialPortMessageListener; |
|
|
|
private Timer timer; |
|
|
|
private StatusLoopWorker statusLoopWorker; |
|
|
|
|
|
|
|
/** |
|
|
|
* Konstruktor. |
|
|
|
@@ -115,6 +125,10 @@ public class MainPanel { |
|
|
|
camVelocityModeBtn.setEnabled(false); |
|
|
|
camVelocityModeBtn.setSelected(false); |
|
|
|
|
|
|
|
if (statusLoopWorker != null) { |
|
|
|
statusLoopWorker.cancel(true); |
|
|
|
} |
|
|
|
|
|
|
|
for (IConnectionState listener : connectionStateListeners) { |
|
|
|
listener.connectionStateChanged(new ConnectionStateInfo(ConnectionState.READY, null, null)); |
|
|
|
} |
|
|
|
@@ -126,6 +140,8 @@ public class MainPanel { |
|
|
|
@Override |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
logWindow.addLogEntry(SerialCommHandler.sendCamZeroCommand(selectedSerialPort), OUT); |
|
|
|
rotationSlider.setValue(0); |
|
|
|
rotationValTxtFld.setText("0°"); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
@@ -138,25 +154,38 @@ public class MainPanel { |
|
|
|
|
|
|
|
this.relaisPwrBtn.addEventSelected(new EventSwitchSelected() { |
|
|
|
@Override |
|
|
|
public void onSelected(boolean selected) { |
|
|
|
public void onSwitchSelected(boolean selected) { |
|
|
|
logWindow.addLogEntry(SerialCommHandler.sendRelaisPwrCommand(selectedSerialPort, selected ? Message.CMD_VAL_ON : Message.CMD_VAL_OFF), OUT); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
this.camStepperPwrBtn.addEventSelected(new EventSwitchSelected() { |
|
|
|
@Override |
|
|
|
public void onSelected(boolean selected) { |
|
|
|
public void onSwitchSelected(boolean selected) { |
|
|
|
logWindow.addLogEntry(SerialCommHandler.sendCamPwrCommand(selectedSerialPort, selected ? Message.CMD_VAL_ON : Message.CMD_VAL_OFF), OUT); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
this.camVelocityModeBtn.addEventSelected(new EventSwitchSelected() { |
|
|
|
@Override |
|
|
|
public void onSelected(boolean selected) { |
|
|
|
public void onSwitchSelected(boolean selected) { |
|
|
|
logWindow.addLogEntry(SerialCommHandler.sendCamVelocityCommand(selectedSerialPort, selected ? Message.CMD_VELOCITY_FAST : Message.CMD_VELOCITY_SLOW), OUT); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
this.rotationSlider.addChangeListener(new ChangeListener() { |
|
|
|
@Override |
|
|
|
public void stateChanged(ChangeEvent e) { |
|
|
|
rotationValTxtFld.setText(Integer.toString(rotationSlider.getValue()) + "°"); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
this.rotateBtn.addActionListener(new ActionListener() { |
|
|
|
@Override |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
logWindow.addLogEntry(SerialCommHandler.sendRotateCommand(selectedSerialPort, Integer.toString(rotationSlider.getValue())), OUT); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public void registerConnectionStateListener(IConnectionState connectionStateListener) { |
|
|
|
@@ -326,22 +355,52 @@ public class MainPanel { |
|
|
|
if (deserializedMsg.getSender().equals(Message.CMD_SENDER_AN) && deserializedMsg.getCmd().equals(Message.CMD_VER)) { |
|
|
|
// connected |
|
|
|
timer.cancel(); |
|
|
|
SwingUtilities.invokeLater(() -> { |
|
|
|
for (IConnectionState listener : connectionStateListeners) { |
|
|
|
listener.connectionStateChanged(new ConnectionStateInfo(ConnectionState.CONNECTED, selectedSerialPort.getSystemPortName(), deserializedMsg.getVal())); |
|
|
|
if (deserializedMsg.getVal().equals(MIN_ARDUINO_VERSION)) { |
|
|
|
SwingUtilities.invokeLater(() -> { |
|
|
|
for (IConnectionState listener : connectionStateListeners) { |
|
|
|
listener.connectionStateChanged(new ConnectionStateInfo(ConnectionState.CONNECTED, selectedSerialPort.getSystemPortName(), deserializedMsg.getVal())); |
|
|
|
} |
|
|
|
}); |
|
|
|
relaisPwrBtn.setEnabled(true); |
|
|
|
camStepperPwrBtn.setEnabled(true); |
|
|
|
camVelocityModeBtn.setEnabled(true); |
|
|
|
if (statusLoopWorker != null) { |
|
|
|
statusLoopWorker.cancel(true); |
|
|
|
} |
|
|
|
}); |
|
|
|
relaisPwrBtn.setEnabled(true); |
|
|
|
camStepperPwrBtn.setEnabled(true); |
|
|
|
camVelocityModeBtn.setEnabled(true); |
|
|
|
statusLoopWorker = new StatusLoopWorker(selectedSerialPort); |
|
|
|
statusLoopWorker.execute(); |
|
|
|
} else { |
|
|
|
SwingUtilities.invokeLater(() -> { |
|
|
|
for (IConnectionState listener : connectionStateListeners) { |
|
|
|
listener.connectionStateChanged(new ConnectionStateInfo(ConnectionState.WRONG_SW_VERSION, selectedSerialPort.getSystemPortName(), deserializedMsg.getVal())); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} else if (deserializedMsg.getSender().equals(Message.CMD_SENDER_AN) && deserializedMsg.getCmd().equals(Message.CMD_STATUS_RELAY)) { |
|
|
|
//Power relais status |
|
|
|
String val = deserializedMsg.getVal(); |
|
|
|
relaisPwrBtn.getFirstSwitchListener().suspend(); |
|
|
|
relaisPwrBtn.setSelected(val.equals(Message.CMD_VAL_ON)); |
|
|
|
relaisPwrBtn.getFirstSwitchListener().resume(); |
|
|
|
relaisPwrLed.doSwitch(val); |
|
|
|
} else if (deserializedMsg.getSender().equals(Message.CMD_SENDER_AN) && deserializedMsg.getCmd().equals(Message.CMD_STATUS_CAM)) { |
|
|
|
//Cam relais status |
|
|
|
String val = deserializedMsg.getVal(); |
|
|
|
camStepperPwrBtn.getFirstSwitchListener().suspend(); |
|
|
|
camStepperPwrBtn.setSelected(val.equals(Message.CMD_VAL_ON)); |
|
|
|
camStepperPwrBtn.getFirstSwitchListener().resume(); |
|
|
|
camStepperPwrLed.doSwitch(val); |
|
|
|
} else if (deserializedMsg.getSender().equals(Message.CMD_SENDER_AN) && deserializedMsg.getCmd().equals(Message.CMD_STATUS_VELOCITY_CAM)) { |
|
|
|
//Cam velocity status |
|
|
|
String val = deserializedMsg.getVal(); |
|
|
|
camVelocityModeBtn.getFirstSwitchListener().suspend(); |
|
|
|
camVelocityModeBtn.setSelected(val.equals(Message.CMD_VAL_ON)); |
|
|
|
camVelocityModeBtn.getFirstSwitchListener().resume(); |
|
|
|
} else if (deserializedMsg.getSender().equals(Message.CMD_SENDER_AN) && deserializedMsg.getCmd().equals(Message.CMD_ACT_AZIMUT_CAM)) { |
|
|
|
//Actual azimut status |
|
|
|
String val = deserializedMsg.getVal(); |
|
|
|
rotationSlider.setValue(Integer.parseInt(val)); |
|
|
|
rotationValTxtFld.setText(val + "°"); |
|
|
|
} |
|
|
|
} else if (serialPortEvent.getEventType() == SerialPort.LISTENING_EVENT_DATA_WRITTEN) { |
|
|
|
System.out.println("serialEvent: LISTENING_EVENT_DATA_WRITTEN"); |
|
|
|
@@ -361,6 +420,7 @@ public class MainPanel { |
|
|
|
createUIComponents(); |
|
|
|
mainPanel = new JPanel(); |
|
|
|
mainPanel.setLayout(new GridBagLayout()); |
|
|
|
mainPanel.setOpaque(true); |
|
|
|
final JPanel spacer1 = new JPanel(); |
|
|
|
GridBagConstraints gbc; |
|
|
|
gbc = new GridBagConstraints(); |
|
|
|
@@ -726,6 +786,62 @@ public class MainPanel { |
|
|
|
gbc.anchor = GridBagConstraints.NORTHWEST; |
|
|
|
gbc.insets = new Insets(10, 10, 10, 10); |
|
|
|
mainPanel.add(logWindowBtn, gbc); |
|
|
|
rotationSlider = new JSlider(); |
|
|
|
Font rotationSliderFont = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 14, rotationSlider.getFont()); |
|
|
|
if (rotationSliderFont != null) rotationSlider.setFont(rotationSliderFont); |
|
|
|
rotationSlider.setMajorTickSpacing(60); |
|
|
|
rotationSlider.setMaximum(180); |
|
|
|
rotationSlider.setMinimum(-180); |
|
|
|
rotationSlider.setMinorTickSpacing(30); |
|
|
|
rotationSlider.setPaintLabels(true); |
|
|
|
rotationSlider.setPaintTicks(true); |
|
|
|
rotationSlider.setSnapToTicks(false); |
|
|
|
rotationSlider.setValue(0); |
|
|
|
gbc = new GridBagConstraints(); |
|
|
|
gbc.gridx = 3; |
|
|
|
gbc.gridy = 2; |
|
|
|
gbc.gridwidth = 2; |
|
|
|
gbc.anchor = GridBagConstraints.WEST; |
|
|
|
gbc.fill = GridBagConstraints.BOTH; |
|
|
|
gbc.insets = new Insets(0, 10, 0, 10); |
|
|
|
mainPanel.add(rotationSlider, gbc); |
|
|
|
final JPanel panel5 = new JPanel(); |
|
|
|
panel5.setLayout(new GridBagLayout()); |
|
|
|
gbc = new GridBagConstraints(); |
|
|
|
gbc.gridx = 3; |
|
|
|
gbc.gridy = 3; |
|
|
|
gbc.gridwidth = 2; |
|
|
|
gbc.gridheight = 2; |
|
|
|
gbc.fill = GridBagConstraints.BOTH; |
|
|
|
mainPanel.add(panel5, gbc); |
|
|
|
rotationValTxtFld = new JTextField(); |
|
|
|
rotationValTxtFld.setBackground(new Color(-16777216)); |
|
|
|
rotationValTxtFld.setCaretColor(new Color(-14690702)); |
|
|
|
rotationValTxtFld.setDisabledTextColor(new Color(-14690702)); |
|
|
|
rotationValTxtFld.setEditable(false); |
|
|
|
rotationValTxtFld.setEnabled(false); |
|
|
|
Font rotationValTxtFldFont = this.$$$getFont$$$("Bahnschrift", Font.PLAIN, 14, rotationValTxtFld.getFont()); |
|
|
|
if (rotationValTxtFldFont != null) rotationValTxtFld.setFont(rotationValTxtFldFont); |
|
|
|
rotationValTxtFld.setForeground(new Color(-14690702)); |
|
|
|
rotationValTxtFld.setHorizontalAlignment(0); |
|
|
|
rotationValTxtFld.setPreferredSize(new Dimension(100, 36)); |
|
|
|
rotationValTxtFld.setSelectedTextColor(new Color(-14690702)); |
|
|
|
rotationValTxtFld.setText("0°"); |
|
|
|
gbc = new GridBagConstraints(); |
|
|
|
gbc.gridx = 0; |
|
|
|
gbc.gridy = 0; |
|
|
|
panel5.add(rotationValTxtFld, gbc); |
|
|
|
rotateBtn = new JButton(); |
|
|
|
rotateBtn.setIcon(new ImageIcon(getClass().getResource("/rotate.png"))); |
|
|
|
rotateBtn.setPreferredSize(new Dimension(85, 70)); |
|
|
|
rotateBtn.setText(""); |
|
|
|
gbc = new GridBagConstraints(); |
|
|
|
gbc.gridx = 0; |
|
|
|
gbc.gridy = 1; |
|
|
|
gbc.weightx = 1.0; |
|
|
|
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
|
|
gbc.insets = new Insets(10, 10, 10, 10); |
|
|
|
panel5.add(rotateBtn, gbc); |
|
|
|
} |
|
|
|
|
|
|
|
/** |