Skip to content
Snippets Groups Projects
Commit b2e46f3c authored by Lennart Goedhart's avatar Lennart Goedhart
Browse files

Fix for Crashlytics #1

parent 56aac588
Branches
No related tags found
No related merge requests found
...@@ -8,7 +8,6 @@ import android.hardware.usb.UsbManager; ...@@ -8,7 +8,6 @@ import android.hardware.usb.UsbManager;
import android.util.Log; import android.util.Log;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator;
//import com.hoho.android.usbserial.driver.UsbId; //import com.hoho.android.usbserial.driver.UsbId;
...@@ -17,8 +16,8 @@ import java.util.Iterator; ...@@ -17,8 +16,8 @@ import java.util.Iterator;
* *
* @author mike wakerly (opensource@hoho.com), Lennart Goedhart (lennart@omnibase.com.au) * @author mike wakerly (opensource@hoho.com), Lennart Goedhart (lennart@omnibase.com.au)
* @see <a * @see <a
* href="http://www.usb.org/developers/devclass_docs/usbcdc11.pdf">Universal * href="http://www.usb.org/developers/devclass_docs/usbcdc11.pdf">Universal
* Serial Bus Class Definitions for Communication Devices, v1.1</a> * Serial Bus Class Definitions for Communication Devices, v1.1</a>
*/ */
public class UsbHidDriver extends CommonUsbDriver { public class UsbHidDriver extends CommonUsbDriver {
...@@ -35,17 +34,14 @@ public class UsbHidDriver extends CommonUsbDriver { ...@@ -35,17 +34,14 @@ public class UsbHidDriver extends CommonUsbDriver {
super(device, connection); super(device, connection);
} }
public static UsbHidDriver acquire( UsbManager usbManager, int vendorId, int productId ) { public static UsbHidDriver acquire(UsbManager usbManager, int vendorId, int productId) {
Iterator<UsbDevice> deviceIterator = usbManager.getDeviceList().values().iterator();
// Iterate all the available devices and find ours. // Iterate all the available devices and find ours.
while( deviceIterator.hasNext() ){ for (UsbDevice device : usbManager.getDeviceList().values()) {
UsbDevice device = deviceIterator.next();
if (device.getProductId() == productId && device.getVendorId() == vendorId) { if (device.getProductId() == productId && device.getVendorId() == vendorId) {
final UsbDevice mDevice = device; final UsbDeviceConnection mConnection = usbManager.openDevice(device);
final UsbDeviceConnection mConnection = usbManager.openDevice( mDevice );
return new UsbHidDriver( mDevice, mConnection ); return new UsbHidDriver(device, mConnection);
} }
} }
...@@ -54,14 +50,11 @@ public class UsbHidDriver extends CommonUsbDriver { ...@@ -54,14 +50,11 @@ public class UsbHidDriver extends CommonUsbDriver {
@Override @Override
public void open() throws IOException { public void open() throws IOException {
Log.d(TAG, "claiming interfaces, count=" + mDevice.getInterfaceCount());
int count = mDevice.getInterfaceCount();
Log.d(TAG, "Claiming HID interface."); Log.d(TAG, "Claiming HID interface.");
mInterface = mDevice.getInterface(0); mInterface = mDevice.getInterface(0);
Log.d(TAG, "data iface=" + mInterface);
if (!mConnection.claimInterface(mInterface, true)) { if (!mConnection.claimInterface(mInterface, true)) {
isConnectionOpen = false; isConnectionOpen = false;
throw new IOException("Could not claim data interface."); throw new IOException("Could not claim data interface.");
} }
...@@ -75,7 +68,9 @@ public class UsbHidDriver extends CommonUsbDriver { ...@@ -75,7 +68,9 @@ public class UsbHidDriver extends CommonUsbDriver {
@Override @Override
public void close() { public void close() {
mConnection.close(); if (mConnection != null) {
mConnection.close();
}
isConnectionOpen = false; isConnectionOpen = false;
} }
...@@ -136,8 +131,8 @@ public class UsbHidDriver extends CommonUsbDriver { ...@@ -136,8 +131,8 @@ public class UsbHidDriver extends CommonUsbDriver {
return offset; return offset;
} }
@Override @Override
public boolean isConnectionOpen(){ public boolean isConnectionOpen() {
return isConnectionOpen; return isConnectionOpen;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment