jfernandez / ControllerTools

Game controller plugin for the Steam Deck
GNU General Public License v3.0
49 stars 3 forks source link

Fix alert bug with multiple product_id with a refactor #19

Closed jfernandez closed 1 year ago

jfernandez commented 1 year ago

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.