We need a unique identifier for each controller for alerts. Previously we used the vendor/product ID tuple, but that would be a problem when someone connects multiple controllers with the same tuple. The ID is used in alerts to control how often we send a low-battery warning. To accomplish this, I made a new id() method that uses the device path if found, otherwise falls back to the serial number, or if both are missing, uses the vendor/product ID tuple.
I moved most of our controller logic to controller.rs and created two constructor methods, one for hidapi and another for udev. These constructors will extract the device path and serial number for each API, and set other fields where we were duplicating logic for each vendor module (like detecting Bluetooth).
Finally, I ran cargo clippy (Rust linter) and cleaned up a bunch of the stuff it detected. It also suggests more idiomatic ways to do things.
We need a unique identifier for each controller for alerts. Previously we used the vendor/product ID tuple, but that would be a problem when someone connects multiple controllers with the same tuple. The ID is used in alerts to control how often we send a low-battery warning. To accomplish this, I made a new
id()
method that uses the device path if found, otherwise falls back to the serial number, or if both are missing, uses the vendor/product ID tuple.I moved most of our controller logic to
controller.rs
and created two constructor methods, one for hidapi and another for udev. These constructors will extract the device path and serial number for each API, and set other fields where we were duplicating logic for each vendor module (like detecting Bluetooth).Finally, I ran
cargo clippy
(Rust linter) and cleaned up a bunch of the stuff it detected. It also suggests more idiomatic ways to do things.