kopia lustrzana https://github.com/felHR85/UsbSerial
Merge branch 'master' of https://github.com/felHR85/UsbSerial
commit
f20ed6f864
|
@ -18,6 +18,10 @@ 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
|
||||
|
@ -176,7 +180,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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -112,6 +112,30 @@ public abstract class UsbSerialDevice implements UsbSerialInterface
|
|||
serialBuffer.putWriteBuffer(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Use this setter <strong>before</strong> calling {@link #open()} to override the default baud rate defined in this particular class.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* This is a workaround for devices where calling {@link #setBaudRate(int)} has no effect once {@link #open()} has been called.
|
||||
* </p>
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
|
|
Ładowanie…
Reference in New Issue