Skip to content

Commit

Permalink
Sleep HID dataRead with devices present (#1183)
Browse files Browse the repository at this point in the history
Co-authored-by: lucas lelievre <loucass003@gmail.com>
  • Loading branch information
sctanf and loucass003 authored Oct 4, 2024
1 parent c58209a commit 505a9fc
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer<Tracker>)
private fun dataRead() {
synchronized(devicesByHID) {
var devicesPresent = false
var devicesDataReceived = false
val q = intArrayOf(0, 0, 0, 0)
val a = intArrayOf(0, 0, 0)
for ((hidDevice, deviceList) in devicesByHID) {
Expand All @@ -202,6 +203,7 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer<Tracker>)
LogManager.info("[TrackerServer] Malformed HID packet, ignoring")
continue // Don't continue with this data
}
devicesDataReceived = true // Data is received and is valid (not malformed)
val packetCount = dataReceived.size / 20
var i = 0
while (i < packetCount * 20) {
Expand Down Expand Up @@ -261,6 +263,8 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer<Tracker>)
}
if (!devicesPresent) {
sleep(10) // No hid device, "empty loop" so sleep to save the poor cpu
} else if (!devicesDataReceived) {
sleep(1) // read has no timeout, no data also causes an "empty loop"
}
}
}
Expand Down

0 comments on commit 505a9fc

Please sign in to comment.