Skip to content

Commit

Permalink
Fix build on newer flutter
Browse files Browse the repository at this point in the history
Added interfaceCount to UsbDevice
  • Loading branch information
altera2015 committed Mar 7, 2020
1 parent 787794a commit ec66fa4
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,9 @@
## 0.2.3

* Fixed threading issue ( PR10 )
* Added interfaceCount
* Added CH340 VID/PID to example xml.
* Added exception catch for Device Create

## 0.2.2

Expand Down
Expand Up @@ -179,6 +179,8 @@ public void onFailed(UsbDevice device) {
} else {
result.error(TAG, "Failed to acquire USB permission.", null);
}
} catch ( java.lang.Exception e ) {
result.error(TAG, "Failed to acquire USB device.", null);
}
}

Expand All @@ -202,6 +204,7 @@ private HashMap<String, Object> serializeDevice(UsbDevice device) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
dev.put("manufacturerName", device.getManufacturerName());
dev.put("productName", device.getProductName());
dev.put("interfaceCount", device.getInterfaceCount());
/* if the app targets SDK >= android.os.Build.VERSION_CODES.Q and the app does not have permission to read from the device. */
try {
dev.put("serialNumber", device.getSerialNumber());
Expand Down
1 change: 1 addition & 0 deletions example/.flutter-plugins-dependencies
@@ -0,0 +1 @@
{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"usb_serial","dependencies":[]}]}
4 changes: 2 additions & 2 deletions example/android/app/build.gradle
Expand Up @@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 27
compileSdkVersion 28

lintOptions {
disable 'InvalidPackage'
Expand All @@ -35,7 +35,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "dev.bessems.usbserialexample"
minSdkVersion 24
targetSdkVersion 27
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down
1 change: 1 addition & 0 deletions example/android/gradle.properties
@@ -1 +1,2 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
10 changes: 10 additions & 0 deletions example/ios/Flutter/flutter_export_environment.sh
@@ -0,0 +1,10 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=C:\flutter"
export "FLUTTER_APPLICATION_PATH=C:\Devel\usbserial\example"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build\ios"
export "FLUTTER_FRAMEWORK_DIR=C:\flutter\bin\cache\artifacts\engine\ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
15 changes: 12 additions & 3 deletions lib/usb_serial.dart
Expand Up @@ -195,12 +195,21 @@ class UsbDevice {
/// The Serial number from the USB device.
final String serial;

/// The number of interfaces on this UsbPort
final int interfaceCount;

UsbDevice(this.vid, this.pid, this.productName, this.manufacturerName,
this.deviceId, this.serial);
this.deviceId, this.serial, this.interfaceCount);

static UsbDevice fromJSON(dynamic json) {
return UsbDevice(json["vid"], json["pid"], json["productName"],
json["manufacturerName"], json["deviceId"], json["serialNumber"]);
return UsbDevice(
json["vid"],
json["pid"],
json["productName"],
json["manufacturerName"],
json["deviceId"],
json["serialNumber"],
json["interfaceCount"]);
}

@override
Expand Down

0 comments on commit ec66fa4

Please sign in to comment.