I'm working on an Android application that communicates with the Concept2 Rowing ergometer. My setup is a Concept2 Model D with a PM5. I am aware that the PM5 can communicate with an Android phone through Bluetooth, but I am implementing mine to communicate over a USB cable. I was able to establish a successful USB connection between phone and ergo by opening the device and successfully claim the USBInterface. I am using the Android USB host API. I am writing the app in Kotlin, though Java is just as fine.
Everything goes according to plan with the following two lines.
Code: Select all
usbHidConnection = usbManager.openDevice(usbDevice)
val claimed = usbHidConnection?.claimInterface(usbHidInterface, true)
Code: Select all
val distanceBuffer = listOf(0xF0, 0xFD, 0x00, 0x9B, 0x9B, 0xF2)
val ba = ByteArray(distanceBuffer.size)
var i = 0
while (i < distanceBuffer.size) {
ba[i] = distanceBuffer[i].toByte()
i++
}
val byteBuffer = ByteBuffer.wrap(ba)
val request = UsbRequest()
request.initialize(conceptManager.usbHidConnection, conceptManager.usbHidRead)
doAsync {
request.queue(byteBuffer)
if (conceptManager.usbHidConnection?.requestWait() === request) {
val x = byteBuffer[0]
// TODO: process info from ergo
}
}
Does anyone have any ideas as to why my approach is not working? I must admit I do feel kind of stuck here as there are not many examples with Android USB on github to learn from.
Also, I have a second question. In the Android API for USB communication, the framework requires that I send the USB device a ByteBuffer. A ByteBuffer consists of bytes. In Kotlin (and Java), bytes can only be signed. This means they can only assume values from -128 to 127. Since that is the case, and the Concept2 expects unsigned byte values, e.g. 0 to 255, what is to happen? Am I to let Kotlin convert the integers I have ready to signed bytes and the PM5 will convert them on its own to the desired values? Just to clarify, after converting the above values to signed bytes, the frame looks like this:
-16 -3 0 -101 -101 -14
So, yeah. If anyone could share some expertise, I'd be grateful. Thanks in advance.