TS SD integration #1653
This commit is contained in:
parent
4c0afb5c83
commit
fbf0df6f65
|
@ -23,13 +23,12 @@ public class ConnectPanel {
|
|||
private final JLabel status = new JLabel();
|
||||
|
||||
private LinkManager controllerConnector;
|
||||
private final JButton connect = new JButton("Connect");
|
||||
private final JButton disconnect = new JButton("Disconnect");
|
||||
|
||||
public ConnectPanel(final ConnectionStateListener connectionStateListener) {
|
||||
JPanel flow = new JPanel(new FlowLayout());
|
||||
|
||||
JButton connect = new JButton("Connect");
|
||||
JButton disconnect = new JButton("Disconnect");
|
||||
|
||||
disconnect.setEnabled(false);
|
||||
disconnect.addActionListener(new AbstractAction() {
|
||||
@Override
|
||||
|
@ -49,10 +48,31 @@ public class ConnectPanel {
|
|||
controllerConnector = new LinkManager()
|
||||
.setCompositeLogicEnabled(false)
|
||||
.setNeedPullData(false);
|
||||
|
||||
String autoDetectedPort = null;
|
||||
try {
|
||||
autoDetectedPort = PortDetector.autoDetectSerial(null);
|
||||
tryToConnect(connectionStateListener);
|
||||
} catch (Throwable er) {
|
||||
log.error("Error connecting", er);
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
status.setText("Some error, see logs.");
|
||||
connect.setEnabled(true);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
flow.add(connect);
|
||||
flow.add(disconnect);
|
||||
|
||||
content.add(flow, BorderLayout.NORTH);
|
||||
content.add(status, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
private void tryToConnect(ConnectionStateListener connectionStateListener) {
|
||||
String autoDetectedPort = PortDetector.autoDetectSerial(null);
|
||||
if (autoDetectedPort == null) {
|
||||
status.setText("rusEFI not found");
|
||||
connect.setEnabled(true);
|
||||
} else {
|
||||
controllerConnector.startAndConnect(autoDetectedPort, new ConnectionStateListener() {
|
||||
public void onConnectionEstablished() {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
|
@ -65,24 +85,7 @@ public class ConnectPanel {
|
|||
public void onConnectionFailed() {
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Throwable er) {
|
||||
log.error("Error connecting", er);
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
status.setText("Not found or error, see logs.");
|
||||
connect.setEnabled(true);
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
flow.add(connect);
|
||||
flow.add(disconnect);
|
||||
|
||||
content.add(flow, BorderLayout.NORTH);
|
||||
content.add(status, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
public LinkManager getControllerConnector() {
|
||||
|
|
Loading…
Reference in New Issue