TS SD integration #1653
This commit is contained in:
parent
6fd56cffdb
commit
52b7eb5f73
|
@ -1,5 +1,6 @@
|
||||||
package com.rusefi.ts_plugin;
|
package com.rusefi.ts_plugin;
|
||||||
|
|
||||||
|
import com.devexperts.logging.Logging;
|
||||||
import com.rusefi.autodetect.PortDetector;
|
import com.rusefi.autodetect.PortDetector;
|
||||||
import com.rusefi.io.ConnectionStateListener;
|
import com.rusefi.io.ConnectionStateListener;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
|
@ -7,11 +8,17 @@ import com.rusefi.io.LinkManager;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
import static com.devexperts.logging.Logging.getLogging;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* todo: move IO away from AWT thread
|
* todo: move IO away from AWT thread
|
||||||
*/
|
*/
|
||||||
public class ConnectPanel {
|
public class ConnectPanel {
|
||||||
|
private static final Logging log = getLogging(ConnectPanel.class);
|
||||||
|
static final Executor IO_THREAD = Executors.newSingleThreadExecutor();
|
||||||
private final JPanel content = new JPanel(new BorderLayout());
|
private final JPanel content = new JPanel(new BorderLayout());
|
||||||
private final JLabel status = new JLabel();
|
private final JLabel status = new JLabel();
|
||||||
|
|
||||||
|
@ -36,30 +43,37 @@ public class ConnectPanel {
|
||||||
|
|
||||||
connect.addActionListener(e -> {
|
connect.addActionListener(e -> {
|
||||||
connect.setEnabled(false);
|
connect.setEnabled(false);
|
||||||
|
status.setText("Looking for rusEFI...");
|
||||||
|
|
||||||
controllerConnector = new LinkManager()
|
IO_THREAD.execute(() -> {
|
||||||
.setCompositeLogicEnabled(false)
|
controllerConnector = new LinkManager()
|
||||||
.setNeedPullData(false);
|
.setCompositeLogicEnabled(false)
|
||||||
|
.setNeedPullData(false);
|
||||||
|
|
||||||
String autoDetectedPort = PortDetector.autoDetectSerial(null);
|
String autoDetectedPort = null;
|
||||||
if (autoDetectedPort == null) {
|
try {
|
||||||
connect.setEnabled(true);
|
autoDetectedPort = PortDetector.autoDetectSerial(null);
|
||||||
status.setText("rusEFI not detected");
|
controllerConnector.startAndConnect(autoDetectedPort, new ConnectionStateListener() {
|
||||||
return;
|
public void onConnectionEstablished() {
|
||||||
}
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
status.setText("Connected to rusEFI");
|
||||||
|
disconnect.setEnabled(true);
|
||||||
|
connectionStateListener.onConnectionEstablished();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//":2390"
|
public void onConnectionFailed() {
|
||||||
//String port = ":29001";
|
}
|
||||||
controllerConnector.startAndConnect(autoDetectedPort, new ConnectionStateListener() {
|
});
|
||||||
public void onConnectionEstablished() {
|
|
||||||
SwingUtilities.invokeLater(() -> {
|
} catch (Throwable er) {
|
||||||
status.setText("Connected to rusEFI");
|
log.error("Error connecting", er);
|
||||||
disconnect.setEnabled(true);
|
|
||||||
connectionStateListener.onConnectionEstablished();
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
status.setText("Not found or error, see logs.");
|
||||||
|
connect.setEnabled(true);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
public void onConnectionFailed() {
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,8 +19,6 @@ import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.text.CharacterIterator;
|
import java.text.CharacterIterator;
|
||||||
import java.text.StringCharacterIterator;
|
import java.text.StringCharacterIterator;
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import static com.devexperts.logging.Logging.getLogging;
|
import static com.devexperts.logging.Logging.getLogging;
|
||||||
|
@ -35,11 +33,9 @@ public class SdCardReader {
|
||||||
private final JPanel fileList = new JPanel(new VerticalFlowLayout());
|
private final JPanel fileList = new JPanel(new VerticalFlowLayout());
|
||||||
private final JLabel status = new JLabel();
|
private final JLabel status = new JLabel();
|
||||||
|
|
||||||
private static final Executor IO_THREAD = Executors.newSingleThreadExecutor();
|
|
||||||
|
|
||||||
private final ConnectPanel connectPanel = new ConnectPanel(new ConnectionStateListener() {
|
private final ConnectPanel connectPanel = new ConnectPanel(new ConnectionStateListener() {
|
||||||
public void onConnectionEstablished() {
|
public void onConnectionEstablished() {
|
||||||
IO_THREAD.execute(() -> requestFileList());
|
ConnectPanel.IO_THREAD.execute(() -> requestFileList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onConnectionFailed() {
|
public void onConnectionFailed() {
|
||||||
|
@ -50,7 +46,7 @@ public class SdCardReader {
|
||||||
public SdCardReader(Supplier<ControllerAccess> controllerAccessSupplier) {
|
public SdCardReader(Supplier<ControllerAccess> controllerAccessSupplier) {
|
||||||
this.controllerAccessSupplier = controllerAccessSupplier;
|
this.controllerAccessSupplier = controllerAccessSupplier;
|
||||||
JButton refresh = new JButton("Refresh");
|
JButton refresh = new JButton("Refresh");
|
||||||
refresh.addActionListener(e -> IO_THREAD.execute(this::requestFileList));
|
refresh.addActionListener(e -> ConnectPanel.IO_THREAD.execute(this::requestFileList));
|
||||||
|
|
||||||
JPanel topPanel = new JPanel(new BorderLayout());
|
JPanel topPanel = new JPanel(new BorderLayout());
|
||||||
JPanel lowPanel = new JPanel(new FlowLayout());
|
JPanel lowPanel = new JPanel(new FlowLayout());
|
||||||
|
@ -118,7 +114,7 @@ public class SdCardReader {
|
||||||
filePanel.add(new JLabel(fileName + " " + humanReadableByteCountBin(fileSize)));
|
filePanel.add(new JLabel(fileName + " " + humanReadableByteCountBin(fileSize)));
|
||||||
|
|
||||||
JButton download = new JButton("Download");
|
JButton download = new JButton("Download");
|
||||||
download.addActionListener(e -> IO_THREAD.execute(() -> downloadFile(fileName)));
|
download.addActionListener(e -> ConnectPanel.IO_THREAD.execute(() -> downloadFile(fileName)));
|
||||||
|
|
||||||
filePanel.add(download);
|
filePanel.add(download);
|
||||||
JButton delete = new JButton("Delete");
|
JButton delete = new JButton("Delete");
|
||||||
|
@ -127,7 +123,7 @@ public class SdCardReader {
|
||||||
"rusEfi", JOptionPane.YES_NO_OPTION);
|
"rusEfi", JOptionPane.YES_NO_OPTION);
|
||||||
if (result == JOptionPane.YES_OPTION) {
|
if (result == JOptionPane.YES_OPTION) {
|
||||||
|
|
||||||
IO_THREAD.execute(() -> {
|
ConnectPanel.IO_THREAD.execute(() -> {
|
||||||
deleteFile(fileName);
|
deleteFile(fileName);
|
||||||
setStatus("Deleted " + fileName);
|
setStatus("Deleted " + fileName);
|
||||||
requestFileList();
|
requestFileList();
|
||||||
|
|
Loading…
Reference in New Issue