fix(input): a controller swapped onto a reused hidraw node while Motion controls is off is another device #3297
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3297
Loading…
Reference in a new issue
No description provided.
Delete branch "sandymac/Longshot:feat/hid-imu-uniq-device-id"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Follows #3045 (controller gyro under Steam Input), whose review left this open: BeanBot's L2, item 1 of #3276.
The game keeps each controller's learned gyroscope bias by the builder's device id (
motion_hid_biasinhost/pad_sdl.c). That id washid_imu::device_id(path, plugged): the node's path hashed with the count of devices thenode has had. The count only moves while the reader looks (a read that says the device is gone, or a look that no longer
finds the node), and with Motion controls off the reader is stopped. So on
main, on Linux:/dev/hidrawN; its bias learned./dev/hidrawN.learns its own.
This PR mixes the device's own identity into the id where the system gives one: Linux's
HID_UNIQfrom the hidrawnode's
uevent(a Bluetooth controller's address, a USB serial where the device has one), read besideHID_ID. Adifferent controller on a reused node gets another id. A controller that stays connected keeps its id across Motion
controls off and on. A controller that comes back to the node is recognized as itself again.
Node::uniq(new):Sys::nodesfills it fromHID_UNIQon Linux (hid_uniq, besidehid_id). It stays empty onWindows, whose node path already holds the device instance id.
device_id(path, uniq, plugged)hashes it between the path and the count. An emptyuniqadds nothing, so the idfor a device without one (and every id on Windows) is the same as on
main.pads: motion: <family> found on <node>log line now gives the device id ((device xxxxxxxx)), so alog shows which id each controller got. It logs the id, a hash, never the address.
docs/dev/reference/input.md: the device-id sentence updated.Read first:
device_id,Node,hid_uniqandSys::nodes(Linux) inbuilder/crates/build-core/src/hid_imu.rs, thena_controller_swapped_onto_a_node_while_motion_is_off_is_another_deviceinhid_imu/tests.rs.See #3276 (item 1; item 2 is testing #3045 on other hardware and stays open there).
Testing
Tested: SteamOS on a Steam Machine (AMD, RADV NAVI33), build gyro-5d33df41 (this change before the rebase onto
8c0beeec, which touches none of its files), two DualSense controllers over Bluetooth, near the start of the game.Motion controls on, aimed with controller 1; Motion controls off in the menu; controller 1 turned off, controller 2 on;
Motion controls on, aimed with controller 2; the same again back to controller 1. Both controllers got
/dev/hidraw9,and the log's lines give each its own id, controller 1 its first one back:
Controller 1 getting
44a03390back shows the reader didn't see either swap (its count stayed at 1), so onmainall three would have been one id. Aiming with each worked in the game.
Checks:
cargo test -p build-coreon Windows (31hid_imutests) and on Linux (WSL, 264 tests), at the head: pass. The new testa_controller_swapped_onto_a_node_while_motion_is_off_is_another_devicefails onmain'sdevice_id(
another device: the same id for the second controller) and passes here.hid_uniqanddevice_idhave unittests in
only_known_hid_nodes_by_their_idsanda_node_s_id_is_its_path_s_hash_and_a_device_s_its_count_on_it.cargo clippy -p build-core -p longshot-game --all-targets -- -D warnings: clean.rustfmt --checkon the changedfiles: clean.
tests/run_all.py:test_hid_imu test_steam_pads test_switch_table test_builder_pads_route test_pads_after_menu test_pad_motion_policy test_gyro_rearm test_sdl_pad_diagnostics: pass.mise run test --container(CI's container, WSL, at 5d33df41 before the rebase): 897 passed, 42 failed, 13 skipped, the same failures asmainat48f85101run the same way (none new). Among them,ffi-gen --check(host/game_host.h:338,rx_menu_open) andsettings_now::tests::a_file_of_every_frozen_key_is_read_and_written_back_byte_identical, both failing onmain.uniqis empty there, so every id is the same as onmain(the unit tests above, run onWindows, check that an empty
uniqleaves the id unchanged).Still to test:
main. The Deck'sbuilt-in controls may report a
HID_UNIQ, which changes their id (not their behaviour). (@Beanstalk steamdeck)Measurements
Nothing to measure: one more line read from a
ueventfile the reader already reads (at most every 2 s, on its own thread), and a few more bytes hashed once per device found; no frame, build or load path changes.Risks
HID_UNIQ(seen on aSteamOS box:
28de:1304/1305, one node giving the receiver's own serial), so two controllers swapped on one slotwhile Motion is off still share an id there, as on
main. Bluetooth controllers (a DualSense's address) are told apart.HID_UNIQon the same reused node still share an id while the reader isn'tlooking, as on
main(the issue's remaining case).uniqis taken from the reader's last look at the nodes (at most 2 s old). A swap between that look and the open ofthe node is still the narrow window it was on
main.HID_UNIQthat changes while it stays connected, it would get a new id and relearn its bias.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Tested in game: SteamOS, Steam Machine (AMD RADV NAVI33), build gyro-5d33df41 (this change before a rebase that touched none of its files). Two DualSense controllers over Bluetooth: Motion controls off in the menu, controller swapped, Motion controls on, then back again. Both got /dev/hidraw9 with their own device ids (44a03390, cfe3fb26, then 44a03390 again for the first one); on main all three would share one id. Gyro aiming worked with each.
WIP: fix(input): a controller swapped onto a reused hidraw node while Motion controls is off is another deviceto fix(input): a controller swapped onto a reused hidraw node while Motion controls is off is another device@Beanstalk steamdeck: Motion controls on, aim with the Steam Deck's built-in gyro near the start of the game; it should aim as on main. The log's 'pads: motion: the Steam Deck ... found on' line gives the device id.
@sandymac only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.@review
Recommendation: Approve. The code is ready: only testing is left. The reported controller swap is fixed in the game-free test and worked with two Bluetooth DualSense controllers in the game. The requested Steam Deck run and head CI results are still pending. Recommend approval; not approved on the forge.
The reader includes Linux HID_UNIQ in the device ID, so controllers with distinct identities do not share learned gyro bias when they replace one another on a reused node while Motion controls is off. Devices without an identity retain the previous behavior.
Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
builder/crates/build-core/src/hid_imu.rs:1173: The Steam Deck built-in gyro run is still outstanding. (more on the line) Do: Run the requested Steam Deck test with Motion controls on and confirm gyro aiming works near the start of the game.Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes for the tested case: the game-free swap test reportedly fails on main and passes here, and an in-game SteamOS run gave the two DualSense controllers different IDs and restored the first controller's ID when swapped back. Controllers with empty HID_UNIQ remain indistinguishable in this case.
Other systems: Windows supplies an empty identity and retains its existing ID calculation. Linux controllers with empty HID_UNIQ retain the existing limitation. Steam Deck built-in gyro behavior remains to be checked in game; the change does not alter rendering or the motion report parser.
Switches: None added, changed or removed.
Reviewed:
7978400afeagainst8c0beeec5d: Read the repository rules, PR template, standards, commit, complete diff, changed identity and reader code, the new tests, and the host bias storage and restore path. Skimmed the remaining portions of hid_imu.rs, hid_imu/tests.rs and input.md; the combined full-file output was truncated. Tooling's adjacent AGENTS.md and docs/review-checklist.md were absent.; nothing run (a code review).Checked and fine:
Testing: No commands from the project or tests were run, as requested. The PR reports passing Rust and game-free checks; Forgejo CI is still running.
Overlaps and merge order: Not checked; network access is unavailable.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -1154,3 +1171,3 @@let (vendor, product) = hid_id(&t)?;family(vendor, product)?;Some(Node { path: format!("/dev/{n}"), vendor, product })Some(Node { path: format!("/dev/{n}"), vendor, product, uniq: hid_uniq(&t).to_owned() })L1 (should fix): The Steam Deck built-in gyro run is still outstanding.
When: On a Deck whose built-in HID node reports an identity, the new ID path is used; the supplied game run covers external DualSense controllers, not the Deck's built-in controls.
Do: Run the requested Steam Deck test with Motion controls on and confirm gyro aiming works near the start of the game.