gituser 10 месяцев назад
Родитель
Сommit
5139f2059c

+ 1
- 1
src/main/java/ch/spherICIT/communication/StatusLoopWorker.java Просмотреть файл

@@ -31,7 +31,7 @@ public class StatusLoopWorker extends SwingWorker<Void, Void> {
SerialCommHandler.sendActualAzimutCommand(this.serialPort);
}
counter++;
Thread.sleep(3000);
Thread.sleep(2000);
}
return null;
}

+ 2
- 1
src/main/java/ch/spherICIT/main/MainPanel.form Просмотреть файл

@@ -419,9 +419,10 @@
<component id="d53d9" class="javax.swing.JButton" binding="rotateBtn">
<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"/>
<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>
<properties>
<enabled value="false"/>
<icon value="rotate.png"/>
<preferredSize width="85" height="70"/>
<text value=""/>

+ 48
- 39
src/main/java/ch/spherICIT/main/MainPanel.java Просмотреть файл

@@ -28,6 +28,7 @@ import javax.swing.event.ChangeListener;
import javax.swing.plaf.FontUIResource;
import javax.swing.text.StyleContext;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
@@ -77,7 +78,7 @@ public class MainPanel {
private List<CommPort> commPorts;
private SerialPort selectedSerialPort;
private FSSerialPortMessageListener serialPortMessageListener;
private Timer timer;
private Timer timeoutTimer;
private StatusLoopWorker statusLoopWorker;

/**
@@ -92,19 +93,15 @@ public class MainPanel {
this.reconnectActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
connect();
initConnection();
}
};

this.serPortOpenBtn.addActionListener(new ActionListener() {
@Override
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();
}
});

@@ -163,6 +160,7 @@ public class MainPanel {
@Override
public void onSwitchSelected(boolean selected) {
logWindow.addLogEntry(SerialCommHandler.sendCamPwrCommand(selectedSerialPort, selected ? Message.CMD_VAL_ON : Message.CMD_VAL_OFF), OUT);
rotateBtn.setEnabled(selected);
}
});

@@ -204,35 +202,48 @@ public class MainPanel {
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() {
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);
}
}

@@ -255,10 +266,6 @@ public class MainPanel {
selectedSerialPort = selCommPortOptional.get().getSerialPort().get();
selectedSerialPort.setComPortParameters(9600, 8, SerialPort.ONE_STOP_BIT, SerialPort.NO_PARITY);
selectedSerialPort.addDataListener(serialPortMessageListener);
selectedSerialPort.openPort();
SwingUtilities.invokeLater(() -> {
logWindow.addLogEntry(SerialCommHandler.sendInitCommand(selectedSerialPort), OUT);
});
serPortOpenBtn.setEnabled(true);
} else {
if (selectedSerialPort != null) {
@@ -354,7 +361,7 @@ public class MainPanel {
logWindow.addLogEntry(input, IN);
if (deserializedMsg.getSender().equals(Message.CMD_SENDER_AN) && deserializedMsg.getCmd().equals(Message.CMD_VER)) {
// connected
timer.cancel();
timeoutTimer.cancel();
if (deserializedMsg.getVal().equals(MIN_ARDUINO_VERSION)) {
SwingUtilities.invokeLater(() -> {
for (IConnectionState listener : connectionStateListeners) {
@@ -388,13 +395,14 @@ public class MainPanel {
String val = deserializedMsg.getVal();
camStepperPwrBtn.getFirstSwitchListener().suspend();
camStepperPwrBtn.setSelected(val.equals(Message.CMD_VAL_ON));
rotateBtn.setEnabled(camStepperPwrBtn.isSelected());
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.setSelected(val.equals(Message.CMD_VELOCITY_FAST));
camVelocityModeBtn.getFirstSwitchListener().resume();
} else if (deserializedMsg.getSender().equals(Message.CMD_SENDER_AN) && deserializedMsg.getCmd().equals(Message.CMD_ACT_AZIMUT_CAM)) {
//Actual azimut status
@@ -832,6 +840,7 @@ public class MainPanel {
gbc.gridy = 0;
panel5.add(rotationValTxtFld, gbc);
rotateBtn = new JButton();
rotateBtn.setEnabled(false);
rotateBtn.setIcon(new ImageIcon(getClass().getResource("/rotate.png")));
rotateBtn.setPreferredSize(new Dimension(85, 70));
rotateBtn.setText("");
@@ -840,7 +849,7 @@ public class MainPanel {
gbc.gridy = 1;
gbc.weightx = 1.0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(10, 10, 10, 10);
gbc.insets = new Insets(10, 20, 10, 20);
panel5.add(rotateBtn, gbc);
}


Загрузка…
Отмена
Сохранить