mirror of https://github.com/rusefi/rusefi-1.git
DFU switch works!
This commit is contained in:
parent
42541da76c
commit
30ccfee1e3
|
@ -28,6 +28,7 @@ android {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(':ecu_io')
|
implementation project(':ecu_io')
|
||||||
|
implementation project(':logging-api')
|
||||||
implementation project(':shared_io')
|
implementation project(':shared_io')
|
||||||
|
|
||||||
implementation files('lib/dfu_java.jar')
|
implementation files('lib/dfu_java.jar')
|
||||||
|
|
|
@ -5,14 +5,23 @@ import android.hardware.usb.UsbManager;
|
||||||
import com.hoho.android.usbserial.driver.CdcAcmSerialDriver;
|
import com.hoho.android.usbserial.driver.CdcAcmSerialDriver;
|
||||||
import com.hoho.android.usbserial.driver.ProbeTable;
|
import com.hoho.android.usbserial.driver.ProbeTable;
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialDriver;
|
import com.hoho.android.usbserial.driver.UsbSerialDriver;
|
||||||
|
import com.hoho.android.usbserial.driver.UsbSerialPort;
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialProber;
|
import com.hoho.android.usbserial.driver.UsbSerialProber;
|
||||||
|
import com.opensr5.Logger;
|
||||||
|
import com.opensr5.io.DataListener;
|
||||||
import com.rusefi.dfu.DfuLogic;
|
import com.rusefi.dfu.DfuLogic;
|
||||||
|
import com.rusefi.io.ByteReader;
|
||||||
|
import com.rusefi.io.IoStream;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AndroidSerial {
|
public class AndroidSerial implements IoStream {
|
||||||
private static final int ST_CDC = 0x5740;
|
private static final int ST_CDC = 0x5740;
|
||||||
|
|
||||||
|
private boolean isClosed;
|
||||||
|
private UsbSerialPort usbSerialPort;
|
||||||
|
|
||||||
static List<UsbSerialDriver> findUsbSerial(UsbManager usbManager) {
|
static List<UsbSerialDriver> findUsbSerial(UsbManager usbManager) {
|
||||||
ProbeTable customTable = UsbSerialProber.getDefaultProbeTable();
|
ProbeTable customTable = UsbSerialProber.getDefaultProbeTable();
|
||||||
customTable.addProduct(DfuLogic.ST_VENDOR, ST_CDC, CdcAcmSerialDriver.class);
|
customTable.addProduct(DfuLogic.ST_VENDOR, ST_CDC, CdcAcmSerialDriver.class);
|
||||||
|
@ -20,4 +29,29 @@ public class AndroidSerial {
|
||||||
|
|
||||||
return prober.findAllDrivers(usbManager);
|
return prober.findAllDrivers(usbManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AndroidSerial(UsbSerialPort usbSerialPort) {
|
||||||
|
this.usbSerialPort = usbSerialPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setInputListener(DataListener listener) {
|
||||||
|
ByteReader reader = buffer -> usbSerialPort.read(buffer, 5000);
|
||||||
|
ByteReader.runReaderLoop(listener, reader, Logger.CONSOLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClosed() {
|
||||||
|
return isClosed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
isClosed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(byte[] bytes) throws IOException {
|
||||||
|
usbSerialPort.write(bytes, 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,10 @@ import android.widget.TextView;
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialDriver;
|
import com.hoho.android.usbserial.driver.UsbSerialDriver;
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialPort;
|
import com.hoho.android.usbserial.driver.UsbSerialPort;
|
||||||
import com.hoho.android.usbserial.util.SerialInputOutputManager;
|
import com.hoho.android.usbserial.util.SerialInputOutputManager;
|
||||||
|
import com.opensr5.Logger;
|
||||||
import com.rusefi.dfu.DfuImage;
|
import com.rusefi.dfu.DfuImage;
|
||||||
import com.rusefi.dfu.android.DfuDeviceLocator;
|
import com.rusefi.dfu.android.DfuDeviceLocator;
|
||||||
|
import com.rusefi.io.DfuHelper;
|
||||||
import com.rusefi.shared.ConnectionAndMeta;
|
import com.rusefi.shared.ConnectionAndMeta;
|
||||||
import com.rusefi.shared.FileUtil;
|
import com.rusefi.shared.FileUtil;
|
||||||
import com.rusefi.*;
|
import com.rusefi.*;
|
||||||
|
@ -175,22 +177,16 @@ public class rusEFI extends Activity {
|
||||||
|
|
||||||
UsbDevice dfuDevice = DfuDeviceLocator.findDevice(usbManager);
|
UsbDevice dfuDevice = DfuDeviceLocator.findDevice(usbManager);
|
||||||
|
|
||||||
if (dfuDevice == null) {
|
if (dfuDevice != null) {
|
||||||
mResultView.append("No DFU device\n");
|
handleDfuDevice(dfuDevice);
|
||||||
} else if (usbManager.hasPermission(dfuDevice)) {
|
|
||||||
dfuUpdate(dfuDevice);
|
|
||||||
} else {
|
} else {
|
||||||
PendingIntent mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
|
mResultView.append("No DFU device\n");
|
||||||
usbManager.requestPermission(dfuDevice, mPermissionIntent);
|
handleSerialDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (1 == 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
// listDevices(manager);
|
// listDevices(manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleSerialDevice() {
|
||||||
List<UsbSerialDriver> availableDrivers = AndroidSerial.findUsbSerial(usbManager);
|
List<UsbSerialDriver> availableDrivers = AndroidSerial.findUsbSerial(usbManager);
|
||||||
if (availableDrivers.isEmpty()) {
|
if (availableDrivers.isEmpty()) {
|
||||||
mStatusView.setText("Not connected");
|
mStatusView.setText("Not connected");
|
||||||
|
@ -212,27 +208,20 @@ public class rusEFI extends Activity {
|
||||||
port.open(connection);
|
port.open(connection);
|
||||||
port.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);
|
port.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);
|
||||||
|
|
||||||
port.write("t".getBytes(), 500);
|
AndroidSerial serial = new AndroidSerial(port);
|
||||||
|
DfuHelper.sendDfuRebootCommand(serial, new StringBuilder(), Logger.CONSOLE);
|
||||||
SerialInputOutputManager usbIoManager = new SerialInputOutputManager(port, new SerialInputOutputManager.Listener() {
|
|
||||||
@Override
|
|
||||||
public void onNewData(final byte[] data) {
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
mResultView.append("WE GOT DATA: " + new String(data) + "\n");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRunError(Exception e) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Executors.newSingleThreadExecutor().submit(usbIoManager);
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleDfuDevice(UsbDevice dfuDevice) {
|
||||||
|
if (usbManager.hasPermission(dfuDevice)) {
|
||||||
|
dfuUpdate(dfuDevice);
|
||||||
|
} else {
|
||||||
|
PendingIntent mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
|
||||||
|
usbManager.requestPermission(dfuDevice, mPermissionIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue