Browse Source

Bugfixing

master
gituser 10 months ago
parent
commit
5139f2059c

+ 1
- 1
src/main/java/ch/spherICIT/communication/StatusLoopWorker.java View File

SerialCommHandler.sendActualAzimutCommand(this.serialPort); SerialCommHandler.sendActualAzimutCommand(this.serialPort);
} }
counter++; counter++;
Thread.sleep(3000);
Thread.sleep(2000);
} }
return null; return null;
} }

+ 2
- 1
src/main/java/ch/spherICIT/main/MainPanel.form View File

<component id="d53d9" class="javax.swing.JButton" binding="rotateBtn"> <component id="d53d9" class="javax.swing.JButton" binding="rotateBtn">
<constraints> <constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<gridbag top="10" left="10" bottom="10" right="10" weightx="1.0" weighty="0.0"/>
<gridbag top="10" left="20" bottom="10" right="20" weightx="1.0" weighty="0.0"/>
</constraints> </constraints>
<properties> <properties>
<enabled value="false"/>
<icon value="rotate.png"/> <icon value="rotate.png"/>
<preferredSize width="85" height="70"/> <preferredSize width="85" height="70"/>
<text value=""/> <text value=""/>

+ 48
- 39
src/main/java/ch/spherICIT/main/MainPanel.java View File

import javax.swing.plaf.FontUIResource; import javax.swing.plaf.FontUIResource;
import javax.swing.text.StyleContext; import javax.swing.text.StyleContext;
import java.awt.Color; import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
private List<CommPort> commPorts; private List<CommPort> commPorts;
private SerialPort selectedSerialPort; private SerialPort selectedSerialPort;
private FSSerialPortMessageListener serialPortMessageListener; private FSSerialPortMessageListener serialPortMessageListener;
private Timer timer;
private Timer timeoutTimer;
private StatusLoopWorker statusLoopWorker; private StatusLoopWorker statusLoopWorker;


/** /**
this.reconnectActionListener = new ActionListener() { this.reconnectActionListener = new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
connect();
initConnection();
} }
}; };


this.serPortOpenBtn.addActionListener(new ActionListener() { this.serPortOpenBtn.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (!selectedSerialPort.isOpen()) {
System.out.println("connecten clicked");
selectedSerialPort.openPort();
logWindow.addLogEntry(SerialCommHandler.sendInitCommand(selectedSerialPort), OUT);
}
connect();
System.out.println("connecten clicked");
initConnection();
} }
}); });


@Override @Override
public void onSwitchSelected(boolean selected) { public void onSwitchSelected(boolean selected) {
logWindow.addLogEntry(SerialCommHandler.sendCamPwrCommand(selectedSerialPort, selected ? Message.CMD_VAL_ON : Message.CMD_VAL_OFF), OUT); logWindow.addLogEntry(SerialCommHandler.sendCamPwrCommand(selectedSerialPort, selected ? Message.CMD_VAL_ON : Message.CMD_VAL_OFF), OUT);
rotateBtn.setEnabled(selected);
} }
}); });


return this.serPortCboBox.getSelectedIndex() != -1 ? Optional.of(this.serPortCboBox.getItemAt(this.serPortCboBox.getSelectedIndex())) : Optional.empty(); return this.serPortCboBox.getSelectedIndex() != -1 ? Optional.of(this.serPortCboBox.getItemAt(this.serPortCboBox.getSelectedIndex())) : Optional.empty();
} }


private void initConnection() {
for (IConnectionState listener : connectionStateListeners) {
listener.connectionStateChanged(new ConnectionStateInfo(ConnectionState.CONNECTING, selectedSerialPort.getSystemPortName(), null));
}
SwingUtilities.invokeLater(() -> {
connect();
});
}

private void connect() { private void connect() {
if (this.selectedSerialPort != null) {
if (this.selectedSerialPort.openPort()) {
this.timer = new Timer();
this.timer.schedule(new TimerTask() {
@Override
public void run() {
SwingUtilities.invokeLater(() -> {
for (IConnectionState listener : connectionStateListeners) {
listener.connectionStateChanged(new ConnectionStateInfo(ConnectionState.TIMEOUT, null, null));
}
serPortOpenBtn.setEnabled(true);
serPortCloseBtn.setEnabled(false);
});
}
}, COMM_TIMEOUT);
if (this.selectedSerialPort != null && this.selectedSerialPort.openPort()) {

try {
this.mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
this.logWindow.addLogEntry(SerialCommHandler.sendInitCommand(this.selectedSerialPort), OUT);
Thread.sleep(3000);
} catch (InterruptedException ex) {
throw new RuntimeException(ex);
} finally {
this.mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}


for (IConnectionState listener : this.connectionStateListeners) {
listener.connectionStateChanged(new ConnectionStateInfo(ConnectionState.CONNECTING, selectedSerialPort.getSystemPortName(), null));
this.timeoutTimer = new Timer();
this.timeoutTimer.schedule(new TimerTask() {
@Override
public void run() {
SwingUtilities.invokeLater(() -> {
for (IConnectionState listener : connectionStateListeners) {
listener.connectionStateChanged(new ConnectionStateInfo(ConnectionState.TIMEOUT, null, null));
}
serPortOpenBtn.setEnabled(true);
serPortCloseBtn.setEnabled(false);
});
} }
}, COMM_TIMEOUT);


SwingUtilities.invokeLater(() -> {
logWindow.addLogEntry(SerialCommHandler.sendVersionCommand(selectedSerialPort),
OUT);
});
SwingUtilities.invokeLater(() -> {
logWindow.addLogEntry(SerialCommHandler.sendVersionCommand(selectedSerialPort), OUT);
});


this.serPortOpenBtn.setEnabled(false);
this.serPortCloseBtn.setEnabled(true);
}
this.serPortOpenBtn.setEnabled(false);
this.serPortCloseBtn.setEnabled(true);
} }
} }


selectedSerialPort = selCommPortOptional.get().getSerialPort().get(); selectedSerialPort = selCommPortOptional.get().getSerialPort().get();
selectedSerialPort.setComPortParameters(9600, 8, SerialPort.ONE_STOP_BIT, SerialPort.NO_PARITY); selectedSerialPort.setComPortParameters(9600, 8, SerialPort.ONE_STOP_BIT, SerialPort.NO_PARITY);
selectedSerialPort.addDataListener(serialPortMessageListener); selectedSerialPort.addDataListener(serialPortMessageListener);
selectedSerialPort.openPort();
SwingUtilities.invokeLater(() -> {
logWindow.addLogEntry(SerialCommHandler.sendInitCommand(selectedSerialPort), OUT);
});
serPortOpenBtn.setEnabled(true); serPortOpenBtn.setEnabled(true);
} else { } else {
if (selectedSerialPort != null) { if (selectedSerialPort != null) {
logWindow.addLogEntry(input, IN); logWindow.addLogEntry(input, IN);
if (deserializedMsg.getSender().equals(Message.CMD_SENDER_AN) && deserializedMsg.getCmd().equals(Message.CMD_VER)) { if (deserializedMsg.getSender().equals(Message.CMD_SENDER_AN) && deserializedMsg.getCmd().equals(Message.CMD_VER)) {
// connected // connected
timer.cancel();
timeoutTimer.cancel();
if (deserializedMsg.getVal().equals(MIN_ARDUINO_VERSION)) { if (deserializedMsg.getVal().equals(MIN_ARDUINO_VERSION)) {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
for (IConnectionState listener : connectionStateListeners) { for (IConnectionState listener : connectionStateListeners) {
String val = deserializedMsg.getVal(); String val = deserializedMsg.getVal();
camStepperPwrBtn.getFirstSwitchListener().suspend(); camStepperPwrBtn.getFirstSwitchListener().suspend();
camStepperPwrBtn.setSelected(val.equals(Message.CMD_VAL_ON)); camStepperPwrBtn.setSelected(val.equals(Message.CMD_VAL_ON));
rotateBtn.setEnabled(camStepperPwrBtn.isSelected());
camStepperPwrBtn.getFirstSwitchListener().resume(); camStepperPwrBtn.getFirstSwitchListener().resume();
camStepperPwrLed.doSwitch(val); camStepperPwrLed.doSwitch(val);
} else if (deserializedMsg.getSender().equals(Message.CMD_SENDER_AN) && deserializedMsg.getCmd().equals(Message.CMD_STATUS_VELOCITY_CAM)) { } else if (deserializedMsg.getSender().equals(Message.CMD_SENDER_AN) && deserializedMsg.getCmd().equals(Message.CMD_STATUS_VELOCITY_CAM)) {
//Cam velocity status //Cam velocity status
String val = deserializedMsg.getVal(); String val = deserializedMsg.getVal();
camVelocityModeBtn.getFirstSwitchListener().suspend(); camVelocityModeBtn.getFirstSwitchListener().suspend();
camVelocityModeBtn.setSelected(val.equals(Message.CMD_VAL_ON));
camVelocityModeBtn.setSelected(val.equals(Message.CMD_VELOCITY_FAST));
camVelocityModeBtn.getFirstSwitchListener().resume(); camVelocityModeBtn.getFirstSwitchListener().resume();
} else if (deserializedMsg.getSender().equals(Message.CMD_SENDER_AN) && deserializedMsg.getCmd().equals(Message.CMD_ACT_AZIMUT_CAM)) { } else if (deserializedMsg.getSender().equals(Message.CMD_SENDER_AN) && deserializedMsg.getCmd().equals(Message.CMD_ACT_AZIMUT_CAM)) {
//Actual azimut status //Actual azimut status
gbc.gridy = 0; gbc.gridy = 0;
panel5.add(rotationValTxtFld, gbc); panel5.add(rotationValTxtFld, gbc);
rotateBtn = new JButton(); rotateBtn = new JButton();
rotateBtn.setEnabled(false);
rotateBtn.setIcon(new ImageIcon(getClass().getResource("/rotate.png"))); rotateBtn.setIcon(new ImageIcon(getClass().getResource("/rotate.png")));
rotateBtn.setPreferredSize(new Dimension(85, 70)); rotateBtn.setPreferredSize(new Dimension(85, 70));
rotateBtn.setText(""); rotateBtn.setText("");
gbc.gridy = 1; gbc.gridy = 1;
gbc.weightx = 1.0; gbc.weightx = 1.0;
gbc.fill = GridBagConstraints.HORIZONTAL; gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(10, 10, 10, 10);
gbc.insets = new Insets(10, 20, 10, 20);
panel5.add(rotateBtn, gbc); panel5.add(rotateBtn, gbc);
} }



Loading…
Cancel
Save