From 8c6969b6ac682474d414b58279b7e5d3fae97be2 Mon Sep 17 00:00:00 2001 From: Jaromor Date: Mon, 8 May 2017 17:01:39 +0200 Subject: [PATCH 1/6] subclasses can now implement support for initial baud rate (see issue #91) --- .../com/felhr/usbserial/UsbSerialDevice.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/usbserial/src/main/java/com/felhr/usbserial/UsbSerialDevice.java b/usbserial/src/main/java/com/felhr/usbserial/UsbSerialDevice.java index 6eafa66..f24f94a 100644 --- a/usbserial/src/main/java/com/felhr/usbserial/UsbSerialDevice.java +++ b/usbserial/src/main/java/com/felhr/usbserial/UsbSerialDevice.java @@ -112,6 +112,30 @@ public abstract class UsbSerialDevice implements UsbSerialInterface serialBuffer.putWriteBuffer(buffer); } + /** + *

+ * Use this setter before calling {@link #open()} to override the default baud rate defined in this particular class. + *

+ * + *

+ * This is a workaround for devices where calling {@link #setBaudRate(int)} has no effect once {@link #open()} has been called. + *

+ * + * @param initialBaudRate baud rate to be used when initializing the serial connection + */ + public void setInitialBaudRate(int initialBaudRate) { + // this class does not implement initialBaudRate + } + + /** + * Classes that do not implement {@link #setInitialBaudRate(int)} should always return -1 + * + * @return initial baud rate used when initializing the serial connection + */ + public int getInitialBaudRate() { + return -1; + } + @Override public int read(UsbReadCallback mCallback) { From b32cbb57ff5071f8911fc77560a3c2d42bcbd3be Mon Sep 17 00:00:00 2001 From: Jaromor Date: Mon, 8 May 2017 17:02:39 +0200 Subject: [PATCH 2/6] implemented initial baud rate for CDCSerialDevice --- .../com/felhr/usbserial/CDCSerialDevice.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/usbserial/src/main/java/com/felhr/usbserial/CDCSerialDevice.java b/usbserial/src/main/java/com/felhr/usbserial/CDCSerialDevice.java index f9dbaea..b73b204 100644 --- a/usbserial/src/main/java/com/felhr/usbserial/CDCSerialDevice.java +++ b/usbserial/src/main/java/com/felhr/usbserial/CDCSerialDevice.java @@ -45,6 +45,8 @@ public class CDCSerialDevice extends UsbSerialDevice private UsbEndpoint outEndpoint; private UsbRequest requestIN; + private int initialBaudRate = 0; + public CDCSerialDevice(UsbDevice device, UsbDeviceConnection connection) { this(device, connection, -1); @@ -56,6 +58,16 @@ public class CDCSerialDevice extends UsbSerialDevice mInterface = device.getInterface(iface >= 0 ? iface : findFirstCDC(device)); } + @Override + public void setInitialBaudRate(int initialBaudRate) { + this.initialBaudRate = initialBaudRate; + } + + @Override + public int getInitialBaudRate() { + return initialBaudRate; + } + @Override public boolean open() { @@ -297,12 +309,29 @@ public class CDCSerialDevice extends UsbSerialDevice } // Default Setup - setControlCommand(CDC_SET_LINE_CODING, 0, CDC_DEFAULT_LINE_CODING); + setControlCommand(CDC_SET_LINE_CODING, 0, getInitialLineCoding()); setControlCommand(CDC_SET_CONTROL_LINE_STATE, CDC_CONTROL_LINE_ON, null); return true; } + protected byte[] getInitialLineCoding() { + byte[] lineCoding; + + int initialBaudRate = getInitialBaudRate(); + + if(initialBaudRate > 0) { + lineCoding = CDC_DEFAULT_LINE_CODING.clone(); + for (int i = 0; i < 4; i++) { + lineCoding[i] = (byte) (initialBaudRate >> i*8 & 0xFF); + } + } else { + lineCoding = CDC_DEFAULT_LINE_CODING; + } + + return lineCoding; + } + private int setControlCommand(int request, int value, byte[] data) { int dataLength = 0; From b324aec352dab834db6587247e2107159d6c747b Mon Sep 17 00:00:00 2001 From: Henry Addo Date: Mon, 15 Jan 2018 06:20:04 +0100 Subject: [PATCH 3/6] Prepare for release 4.5.2 --- README.md | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2187642..6906b52 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ Then add the dependency to your module's build.gradle: /app/build.gradle ```groovy -compile 'com.github.felHR85:UsbSerial:4.5.1' +compile 'com.github.felHR85:UsbSerial:4.5.2' ``` TO-DO diff --git a/gradle.properties b/gradle.properties index 9ffa414..c809be1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=4.5.1 +VERSION_NAME=4.5.2 VERSION_CODE=1 ANDROID_BUILD_MIN_SDK_VERSION=12 ANDROID_BUILD_TARGET_SDK_VERSION=27 From e17a500f56f4f61ccf43fd0b2f3c390b055760e8 Mon Sep 17 00:00:00 2001 From: Henry Addo Date: Mon, 29 Jan 2018 10:51:00 +0100 Subject: [PATCH 4/6] Add note to readme about known issue --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 6906b52..a80250f 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ Devices Supported [CP2130 SPI-USB](http://www.silabs.com/products/interface/usb-bridges/classic-usb-bridges/Pages/usb-to-spi-bridge.aspx) +Known Issue +-------------------------------------- +Due to a bug in Android itself, it's highly recommended to not use it with a device running [Android 5.1.1 Lollipop](https://en.wikipedia.org/wiki/Android_version_history#Android_5.1_Lollipop_(API_22)). See issue [#142](https://github.com/felHR85/UsbSerial/issues/142) for more details. How to use it? -------------------------------------- Instantiate a new object of the UsbSerialDevice class From f51a0af1aa675411e16a591ec1d7e111f9f7ca10 Mon Sep 17 00:00:00 2001 From: Henry Addo Date: Tue, 30 Jan 2018 02:38:16 +0100 Subject: [PATCH 5/6] Fix formatting with the readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a80250f..e121e97 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Devices Supported Known Issue -------------------------------------- Due to a bug in Android itself, it's highly recommended to not use it with a device running [Android 5.1.1 Lollipop](https://en.wikipedia.org/wiki/Android_version_history#Android_5.1_Lollipop_(API_22)). See issue [#142](https://github.com/felHR85/UsbSerial/issues/142) for more details. + How to use it? -------------------------------------- Instantiate a new object of the UsbSerialDevice class From f49eb6f01d6fe2596ea8650b2ec641c560afa316 Mon Sep 17 00:00:00 2001 From: Henry Addo Date: Tue, 30 Jan 2018 02:43:09 +0100 Subject: [PATCH 6/6] Emphasise on the not word for clearer communication --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e121e97..32cea70 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Devices Supported Known Issue -------------------------------------- -Due to a bug in Android itself, it's highly recommended to not use it with a device running [Android 5.1.1 Lollipop](https://en.wikipedia.org/wiki/Android_version_history#Android_5.1_Lollipop_(API_22)). See issue [#142](https://github.com/felHR85/UsbSerial/issues/142) for more details. +Due to a bug in Android itself, it's highly recommended to **not** use it with a device running [Android 5.1.1 Lollipop](https://en.wikipedia.org/wiki/Android_version_history#Android_5.1_Lollipop_(API_22)). See issue [#142](https://github.com/felHR85/UsbSerial/issues/142) for more details. How to use it? --------------------------------------