Skip to content
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

update hid4java to 0.8 #992

Merged
merged 7 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading