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