better error handling
This commit is contained in:
parent
b81ee47d12
commit
9114689a68
|
@ -192,8 +192,10 @@ public class rusEFI extends Activity {
|
|||
@SuppressLint("SetTextI18n")
|
||||
private void switchToDfu() {
|
||||
AndroidSerial serial = AndroidSerial.getAndroidSerial(mStatusView, mResultView, usbManager);
|
||||
if (serial == null)
|
||||
if (serial == null) {
|
||||
// error already reported to mStatusView
|
||||
return;
|
||||
}
|
||||
|
||||
mResultView.append("Switching to DFU\n");
|
||||
DfuHelper.sendDfuRebootCommand(serial, new StringBuilder());
|
||||
|
@ -241,6 +243,7 @@ public class rusEFI extends Activity {
|
|||
} else if (view.getId() == R.id.buttonBroadcast) {
|
||||
AndroidSerial serial = AndroidSerial.getAndroidSerial(mStatusView, mResultView, usbManager);
|
||||
if (serial == null) {
|
||||
// error already reported to mStatusView
|
||||
Snackbar mySnackbar = Snackbar.make(view, "No ECU detected", BaseTransientBottomBar.LENGTH_LONG);
|
||||
mySnackbar.show();
|
||||
return;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.app.serial;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.hardware.usb.UsbDeviceConnection;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.widget.TextView;
|
||||
|
@ -40,6 +41,7 @@ public class AndroidSerial extends AbstractIoStream {
|
|||
dataBuffer = IncomingDataBuffer.createDataBuffer("", this);
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Nullable
|
||||
public static AndroidSerial getAndroidSerial(TextView mStatusView, TextView mResultView, UsbManager usbManager) {
|
||||
List<UsbSerialDriver> availableDrivers = findUsbSerial(usbManager);
|
||||
|
@ -63,7 +65,8 @@ public class AndroidSerial extends AbstractIoStream {
|
|||
port.open(connection);
|
||||
port.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
mStatusView.append("Error opening " + e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return new AndroidSerial(port);
|
||||
|
|
Loading…
Reference in New Issue