Skip to content

Commit

Permalink
update hid4java to 0.8 (#992)
Browse files Browse the repository at this point in the history
Co-authored-by: sctanf <[email protected]>
  • Loading branch information
ImUrX and sctanf committed Apr 21, 2024
1 parent ae4391b commit 827e2ce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
expat
libayatana-appindicator
libusb1
libudev-zero
])
++ lib.optionals pkgs.stdenv.isDarwin [
pkgs.darwin.apple_sdk.frameworks.Security
Expand Down
2 changes: 1 addition & 1 deletion server/desktop/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 827e2ce

Please sign in to comment.