-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/libusb #242
Merged
Merged
Feature/libusb #242
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a219f4a
compile libusb
magnusja 1a890d6
try to read usb devices using libusb
magnusja 97feaaa
control and bulk transfers
magnusja 27f2bb4
claim interface
magnusja 5692d37
refactor api little bit
magnusja 2c50956
clear halt and reset devixce over libusb
magnusja 723ed53
download libusb on travis
magnusja a6cd36e
rename
magnusja d1735bb
try again
magnusja 9dcfdc2
once again
magnusja edbb741
android ci
magnusja c5a2117
android ci
magnusja 20a4746
android ci libusb path
magnusja f841799
claiming in libusb seems to work when claimed by Android before
magnusja ef76d6f
uncomment other usb communications
magnusja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.cxx/ | ||
|
||
# Created by https://www.gitignore.io/api/android,java,intellij,gradle,maven,eclipse | ||
|
||
### Android ### | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,21 +6,35 @@ import android.hardware.usb.UsbInterface | |
import android.hardware.usb.UsbManager | ||
import android.os.Build | ||
import android.util.Log | ||
import com.github.mjdev.libaums.fs.FileSystemCreator | ||
import com.github.mjdev.libaums.fs.FileSystemFactory | ||
import java.io.IOException | ||
import java.util.ArrayList | ||
|
||
/** | ||
* Created by magnusja on 21/12/16. | ||
*/ | ||
|
||
object UsbCommunicationFactory { | ||
class NoUsbCommunicationFound : IOException() | ||
|
||
private val TAG = UsbCommunicationFactory::class.java.simpleName | ||
|
||
private val communications = ArrayList<UsbCommunicationCreator>() | ||
|
||
@JvmStatic | ||
var underlyingUsbCommunication = UnderlyingUsbCommunication.DEVICE_CONNECTION_SYNC | ||
|
||
enum class UnderlyingUsbCommunication { | ||
USB_REQUEST_ASYNC, | ||
DEVICE_CONNECTION_SYNC | ||
DEVICE_CONNECTION_SYNC, | ||
OTHER | ||
} | ||
|
||
@Synchronized | ||
@JvmStatic | ||
fun registerCommunication(creator: UsbCommunicationCreator) { | ||
communications.add(creator) | ||
} | ||
|
||
fun createUsbCommunication( | ||
|
@@ -30,15 +44,36 @@ object UsbCommunicationFactory { | |
outEndpoint: UsbEndpoint, | ||
inEndpoint: UsbEndpoint | ||
): UsbCommunication { | ||
return if (underlyingUsbCommunication == UnderlyingUsbCommunication.DEVICE_CONNECTION_SYNC) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { | ||
JellyBeanMr2Communication(usbManager, usbDevice, usbInterface, outEndpoint, inEndpoint) | ||
} else { | ||
Log.i(TAG, "using workaround usb communication") | ||
HoneyCombMr1Communication(usbManager, usbDevice, usbInterface, outEndpoint, inEndpoint) | ||
} | ||
} else { | ||
UsbRequestCommunication(usbManager, usbDevice, usbInterface, outEndpoint, inEndpoint) | ||
when(underlyingUsbCommunication) { | ||
UnderlyingUsbCommunication.DEVICE_CONNECTION_SYNC -> | ||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { | ||
JellyBeanMr2Communication(usbManager, usbDevice, usbInterface, outEndpoint, inEndpoint) | ||
} else { | ||
Log.i(TAG, "using workaround usb communication") | ||
HoneyCombMr1Communication(usbManager, usbDevice, usbInterface, outEndpoint, inEndpoint) | ||
} | ||
|
||
UnderlyingUsbCommunication.USB_REQUEST_ASYNC -> | ||
return UsbRequestCommunication(usbManager, usbDevice, usbInterface, outEndpoint, inEndpoint) | ||
|
||
UnderlyingUsbCommunication.OTHER -> | ||
for(creator in communications) { | ||
val communication = creator.create(usbManager, usbDevice, usbInterface, outEndpoint, inEndpoint) | ||
|
||
if(communication != null) { | ||
return communication | ||
} | ||
} | ||
|
||
} | ||
throw NoUsbCommunicationFound() | ||
} | ||
} | ||
|
||
interface UsbCommunicationCreator { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
fun create(usbManager: UsbManager, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
usbDevice: UsbDevice, | ||
usbInterface: UsbInterface, | ||
outEndpoint: UsbEndpoint, | ||
inEndpoint: UsbEndpoint): UsbCommunication? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.cxx/ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
cmake_minimum_required(VERSION 3.4.1) | ||
|
||
message("Using libusb path ${LIBUSB_PATH}") | ||
|
||
set(LIBUSB_SRC "${LIBUSB_PATH}/libusb") | ||
set(LIBUSB_INCLUDE "${LIBUSB_PATH}") | ||
|
||
|
||
include_directories(${LIBUSB_INCLUDE}/android/) # config.h | ||
include_directories(${LIBUSB_SRC}) | ||
add_library( libusb | ||
SHARED | ||
${LIBUSB_SRC}/core.c | ||
${LIBUSB_SRC}/descriptor.c | ||
${LIBUSB_SRC}/hotplug.c | ||
${LIBUSB_SRC}/io.c | ||
${LIBUSB_SRC}/sync.c | ||
${LIBUSB_SRC}/os/linux_usbfs.c | ||
${LIBUSB_SRC}/os/poll_posix.c | ||
${LIBUSB_SRC}/os/threads_posix.c | ||
${LIBUSB_SRC}/os/linux_netlink.c) | ||
target_link_libraries(libusb log) | ||
|
||
|
||
include_directories(${LIBUSB_INCLUDE}) | ||
add_library( libusbcom | ||
SHARED | ||
src/c/usb.c ) | ||
target_link_libraries(libusbcom libusb log) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue found: UndocumentedPublicClass - [NoUsbCommunicationFound] at /src/libaums/src/main/java/com/github/mjdev/libaums/usb/UsbCommunicationFactory.kt:19:5