mirror of
https://github.com/mik3y/usb-serial-for-android.git
synced 2026-08-17 11:23:00 +00:00
SerialInputOutputManager: use optimal read buffer size to reduce latency for FTDI and CH34x
This commit is contained in:
+2
-8
@@ -66,16 +66,10 @@ public abstract class CommonUsbSerialPort implements UsbSerialPort {
|
||||
return mPortNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the write endpoint.
|
||||
* @return write endpoint
|
||||
*/
|
||||
@Override
|
||||
public UsbEndpoint getWriteEndpoint() { return mWriteEndpoint; }
|
||||
|
||||
/**
|
||||
* Returns the read endpoint.
|
||||
* @return read endpoint
|
||||
*/
|
||||
@Override
|
||||
public UsbEndpoint getReadEndpoint() { return mReadEndpoint; }
|
||||
|
||||
/**
|
||||
|
||||
+13
@@ -8,6 +8,7 @@ package com.hoho.android.usbserial.driver;
|
||||
|
||||
import android.hardware.usb.UsbDevice;
|
||||
import android.hardware.usb.UsbDeviceConnection;
|
||||
import android.hardware.usb.UsbEndpoint;
|
||||
import android.hardware.usb.UsbManager;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
@@ -74,6 +75,18 @@ public interface UsbSerialPort extends Closeable {
|
||||
*/
|
||||
int getPortNumber();
|
||||
|
||||
/**
|
||||
* Returns the write endpoint.
|
||||
* @return write endpoint
|
||||
*/
|
||||
UsbEndpoint getWriteEndpoint();
|
||||
|
||||
/**
|
||||
* Returns the read endpoint.
|
||||
* @return read endpoint
|
||||
*/
|
||||
UsbEndpoint getReadEndpoint();
|
||||
|
||||
/**
|
||||
* The serial number of the underlying UsbDeviceConnection, or {@code null}.
|
||||
*
|
||||
|
||||
+3
-1
@@ -34,7 +34,7 @@ public class SerialInputOutputManager implements Runnable {
|
||||
private final Object mReadBufferLock = new Object();
|
||||
private final Object mWriteBufferLock = new Object();
|
||||
|
||||
private ByteBuffer mReadBuffer = ByteBuffer.allocate(BUFSIZ);
|
||||
private ByteBuffer mReadBuffer; // default size = getReadEndpoint().getMaxPacketSize()
|
||||
private ByteBuffer mWriteBuffer = ByteBuffer.allocate(BUFSIZ);
|
||||
|
||||
public enum State {
|
||||
@@ -62,11 +62,13 @@ public class SerialInputOutputManager implements Runnable {
|
||||
|
||||
public SerialInputOutputManager(UsbSerialPort serialPort) {
|
||||
mSerialPort = serialPort;
|
||||
mReadBuffer = ByteBuffer.allocate(serialPort.getReadEndpoint().getMaxPacketSize());
|
||||
}
|
||||
|
||||
public SerialInputOutputManager(UsbSerialPort serialPort, Listener listener) {
|
||||
mSerialPort = serialPort;
|
||||
mListener = listener;
|
||||
mReadBuffer = ByteBuffer.allocate(serialPort.getReadEndpoint().getMaxPacketSize());
|
||||
}
|
||||
|
||||
public synchronized void setListener(Listener listener) {
|
||||
|
||||
Reference in New Issue
Block a user