update hid4java to 0.8 (#992)

Co-authored-by: sctanf <36978460+sctanf@users.noreply.github.com>
This commit is contained in:
Uriel
2024-04-21 19:31:28 -03:00
committed by GitHub
parent ae4391bff1
commit 827e2ceef8
3 changed files with 10 additions and 4 deletions

View File

@@ -96,6 +96,7 @@
expat
libayatana-appindicator
libusb1
libudev-zero
])
++ lib.optionals pkgs.stdenv.isDarwin [
pkgs.darwin.apple_sdk.frameworks.Security

View File

@@ -59,7 +59,7 @@ dependencies {
implementation("net.java.dev.jna:jna:5.+")
implementation("net.java.dev.jna:jna-platform:5.+")
implementation("com.fazecast:jSerialComm:2.10.2")
implementation("org.hid4java:hid4java:0.7.0")
implementation("org.hid4java:hid4java:0.8.0")
}
tasks.shadowJar {

View File

@@ -32,7 +32,7 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer<Tracker>)
private val hidServices: HidServices
init {
hidServicesSpecification.isAutoStart = false
hidServicesSpecification.setAutoStart(false)
hidServices = HidManager.getHidServices(hidServicesSpecification)
hidServices.addHidServicesListener(this)
val dataReadThread = Thread(dataReadRunnable)
@@ -43,7 +43,7 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer<Tracker>)
private fun checkConfigureDevice(hidDevice: HidDevice) {
if (hidDevice.vendorId == 0x2FE3 && hidDevice.productId == 0x5652) { // TODO: Use correct ids
if (!hidDevice.isOpen) {
if (hidDevice.isClosed) {
check(hidDevice.open()) { "Unable to open device" }
}
// TODO: Configure the device here
@@ -164,7 +164,7 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer<Tracker>)
var devicesPresent = false
for ((hidDevice, deviceList) in devicesByHID) {
val dataReceived: Array<Byte> = try {
hidDevice.read(80, 1) // Read up to 80 bytes, timeout 1ms
hidDevice.read(80, 0) // Read up to 80 bytes
} catch (e: NegativeArraySizeException) {
continue // Skip devices with read error (Maybe disconnected)
}
@@ -174,6 +174,7 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer<Tracker>)
// TODO: make this less bad
if (dataReceived.size % 20 != 0) {
LogManager.info("[TrackerServer] Malformed HID packet, ignoring")
continue // Don't continue with this data
}
val packetCount = dataReceived.size / 20
var i = 0
@@ -243,6 +244,10 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer<Tracker>)
// TODO:
}
override fun hidDataReceived(p0: HidServicesEvent?) {
// Seems to have issues with the size of data returned
}
companion object {
/**
* Change between IMU axes and OpenGL/SteamVR axes