[PR #348] [MERGED] DualSense output over HID: the report, a writer thread, and rumble through it #2509

Closed
opened 2026-11-02 15:56:47 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/348
Author: @ludovic111
Created: 10/15/2026
Status: ✅ Merged
Merged: 10/15/2026
Merged by: @ludovic111

Base: main ← Head: feat/dualsense-hid


📝 Commits (2)

  • ac95593 DualSense output over HID: the report, a writer thread, and rumble through it
  • 6086758 DualSense output: rumble, LEDs and Bluetooth checked against SDL and the kernel

📊 Changes

10 files changed (+1267 additions, -11 deletions)

View changed files

📝 Cargo.lock (+22 -0)
📝 Cargo.toml (+1 -1)
📝 crates/horizon-client/Cargo.toml (+2 -0)
📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/pad.rs (+45 -2)
➕ crates/horizon-dualsense/Cargo.toml (+16 -0)
➕ crates/horizon-dualsense/examples/dualsense.rs (+270 -0)
➕ crates/horizon-dualsense/src/device.rs (+461 -0)
➕ crates/horizon-dualsense/src/lib.rs (+350 -0)
📝 docs/controllers.md (+99 -8)

📄 Description

What

First of the DualSense PRs (docs/controllers.md, PR plan item 3): the HID output layer, with today's rumble routed through it.

  • New crate crates/horizon-dualsense: builds the DualSense output report (one 47-byte block: valid flags, compatible-vibration motors, both trigger effects, lightbar, player LEDs). It is sent as report 0x02 over USB, or as report 0x31 over Bluetooth (sequence tag, 0x10 tag, then a CRC-32 of seed 0xA2 + report). It reads the firmware's update version (feature report 0x20) to pick the vibration flag (v2 from 0x0224, as hid-playstation.c does).
  • Link: a writer thread owns the pad (Bluetooth writes block). The game hands it a state and timed vibrations; the thread writes only what changed, rewrites everything after a reconnect, and on drop frees both triggers and stops the motors.
  • Game: when the active pad is a DualSense and the window has focus, rumble pulses go through HID. This makes vibration work on macOS, where gilrs has no force feedback. If the device can't be opened (Linux without hidraw access), it falls back silently to gilrs force feedback. exiting() closes the link (release written). pad status shows dualsense_output.
  • hidapi 2.6.7 (MIT; bundles the C hidapi under its BSD option): linux-static-hidraw (libudev, which gilrs already links) and macos-shared-device (non-exclusive open, so gilrs keeps reading the same pad).
  • Docs: the byte-layout references (kernel, SDL, dualsensectl/DualSenseX; no code copied), the Linux udev rule (Steam's rules already cover it; the launcher could install one), the off-safe rules.
  • Example cargo run -p horizon-dualsense --example dualsense -- all|rumble|triggers|lightbar|leds|link|watch plays each output and reads back what the pad reports.

Size: about 1050 lines, mostly the new crate (290 lines of report code and tests, 340 for the device and thread, 270 for the example). The game-side change is about 50 lines.

Verified on the real pad (Mac mini, USB)

  • Report and flags: the IMU confirms rumble. Accel std-dev is 20 at rest; 2,157 for the left motor at 50%, 4,183 at 100%, 3,895 for the right motor at 100% and 6,187 for both. After the stop it decays to 72 at about 0.5 s and 19 at about 0.8 s. My first attempt used the flag bits the other way round and the pad didn't move; the kernel's ordering (HAPTICS_SELECT, plus COMPATIBLE_VIBRATION or VIBRATION2) is what's shipped.
  • Triggers: the pad's input report reads back the active effect. Feedback gives effects 0x11, weapon 0x22, off 0x00.
  • In game (horizon-ctl: virtual-pad tap, then /damage @s 4 and /damage @s 10): pad status shows dualsense_output: "Usb", and the example's watch logged both hits on the IMU (accel about 2,700 and 4,800, each for about 0.4 s).
  • Link: opens in about 30 ms; dropping it writes the release.
  • Bluetooth is not verified on the pad yet: the pad was on USB and then got unplugged during my session. The BT report and CRC are covered by unit tests (zlib check value plus the seeded CRC).

Self-check

cargo fmt --check                                                       ok
cargo clippy -p horizon-dualsense -p horizon-client --all-targets -D warnings   ok (macOS)
cargo clippy -p horizon-dualsense --all-targets -D warnings             ok (Linux, ThinkPad NixOS with libudev)
cargo test -p horizon-dualsense                                         7 passed (macOS and Linux build)
cargo test -p horizon-client                                            ok (exit 0)

tools/parity.py --changed origin/main lists all 306 harnesses (game.rs changed). This PR only touches the pad code and exiting(). I'll run them once on the integration commit of the DualSense stack and report there.

Needs Ludovic

  • Feel-test: with the DualSense on USB, take damage, break blocks and stand near an explosion. Vibration now works on macOS.
  • Bluetooth: unplug the pad and repeat. One open question: on macOS/Windows over BT, sending report 0x31 switches the pad to full input reports, which could change what gilrs reads. Linux's hid-playstation already does this itself. Please say whether input still works over BT on the Mac.

Reference audit (dualsense-2, no pad)

Every byte was checked against SDL, the Linux kernel, dualsensectl and Nielk1's notes, and the discrepancies were fixed in this PR's top commit; see the audit comment. The self-check on the stack top passed: fmt, workspace clippy -D warnings, cargo test -p horizon-dualsense -p horizon-client. Anything not listed above as verified on hardware is verified against the references only.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/348 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/dualsense-hid` --- ### 📝 Commits (2) - [`ac95593`](https://github.com/horizon-rust/horizon/commit/ac955934b501a451cc5b0c3c5d244e57a057517c) DualSense output over HID: the report, a writer thread, and rumble through it - [`6086758`](https://github.com/horizon-rust/horizon/commit/6086758f94cf1ab813137800d02f773e2c7b1f7c) DualSense output: rumble, LEDs and Bluetooth checked against SDL and the kernel ### 📊 Changes **10 files changed** (+1267 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+22 -0) 📝 `Cargo.toml` (+1 -1) 📝 `crates/horizon-client/Cargo.toml` (+2 -0) 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/pad.rs` (+45 -2) ➕ `crates/horizon-dualsense/Cargo.toml` (+16 -0) ➕ `crates/horizon-dualsense/examples/dualsense.rs` (+270 -0) ➕ `crates/horizon-dualsense/src/device.rs` (+461 -0) ➕ `crates/horizon-dualsense/src/lib.rs` (+350 -0) 📝 `docs/controllers.md` (+99 -8) </details> ### 📄 Description ## What First of the DualSense PRs (docs/controllers.md, PR plan item 3): the **HID output layer**, with today's rumble routed through it. - New crate `crates/horizon-dualsense`: builds the DualSense output report (one 47-byte block: valid flags, compatible-vibration motors, both trigger effects, lightbar, player LEDs). It is sent as report 0x02 over USB, or as report 0x31 over Bluetooth (sequence tag, 0x10 tag, then a CRC-32 of seed 0xA2 + report). It reads the firmware's update version (feature report 0x20) to pick the vibration flag (v2 from 0x0224, as `hid-playstation.c` does). - `Link`: a writer thread owns the pad (Bluetooth writes block). The game hands it a state and timed vibrations; the thread writes only what changed, rewrites everything after a reconnect, and on drop frees both triggers and stops the motors. - Game: when the active pad is a DualSense and the window has focus, rumble pulses go through HID. **This makes vibration work on macOS, where gilrs has no force feedback.** If the device can't be opened (Linux without hidraw access), it falls back silently to gilrs force feedback. `exiting()` closes the link (release written). `pad status` shows `dualsense_output`. - hidapi 2.6.7 (MIT; bundles the C hidapi under its BSD option): `linux-static-hidraw` (libudev, which gilrs already links) and `macos-shared-device` (non-exclusive open, so gilrs keeps reading the same pad). - Docs: the byte-layout references (kernel, SDL, dualsensectl/DualSenseX; no code copied), the Linux udev rule (Steam's rules already cover it; the launcher could install one), the off-safe rules. - Example `cargo run -p horizon-dualsense --example dualsense -- all|rumble|triggers|lightbar|leds|link|watch` plays each output and reads back what the pad reports. Size: about 1050 lines, mostly the new crate (290 lines of report code and tests, 340 for the device and thread, 270 for the example). The game-side change is about 50 lines. ## Verified on the real pad (Mac mini, USB) - Report and flags: the IMU confirms rumble. Accel std-dev is 20 at rest; 2,157 for the left motor at 50%, 4,183 at 100%, 3,895 for the right motor at 100% and 6,187 for both. After the stop it decays to 72 at about 0.5 s and 19 at about 0.8 s. My first attempt used the flag bits the other way round and the pad didn't move; the kernel's ordering (HAPTICS_SELECT, plus COMPATIBLE_VIBRATION or VIBRATION2) is what's shipped. - Triggers: the pad's input report reads back the active effect. Feedback gives `effects 0x11`, weapon `0x22`, off `0x00`. - In game (`horizon-ctl`: virtual-pad tap, then `/damage @s 4` and `/damage @s 10`): `pad status` shows `dualsense_output: "Usb"`, and the example's `watch` logged both hits on the IMU (accel about 2,700 and 4,800, each for about 0.4 s). - `Link`: opens in about 30 ms; dropping it writes the release. - **Bluetooth is not verified on the pad yet**: the pad was on USB and then got unplugged during my session. The BT report and CRC are covered by unit tests (zlib check value plus the seeded CRC). ## Self-check ``` cargo fmt --check ok cargo clippy -p horizon-dualsense -p horizon-client --all-targets -D warnings ok (macOS) cargo clippy -p horizon-dualsense --all-targets -D warnings ok (Linux, ThinkPad NixOS with libudev) cargo test -p horizon-dualsense 7 passed (macOS and Linux build) cargo test -p horizon-client ok (exit 0) ``` `tools/parity.py --changed origin/main` lists all 306 harnesses (game.rs changed). This PR only touches the pad code and `exiting()`. I'll run them once on the integration commit of the DualSense stack and report there. ## Needs Ludovic - Feel-test: with the DualSense on USB, take damage, break blocks and stand near an explosion. Vibration now works on macOS. - Bluetooth: unplug the pad and repeat. One open question: on macOS/Windows over BT, sending report 0x31 switches the pad to full input reports, which could change what gilrs reads. Linux's `hid-playstation` already does this itself. Please say whether input still works over BT on the Mac. ## Reference audit (dualsense-2, no pad) Every byte was checked against SDL, the Linux kernel, dualsensectl and Nielk1's notes, and the discrepancies were fixed in this PR's top commit; see [the audit comment](https://github.com/ludovic111/horizon/pull/348#issuecomment-6198163309). The self-check on the stack top passed: fmt, workspace clippy `-D warnings`, `cargo test -p horizon-dualsense -p horizon-client`. Anything not listed above as verified on hardware is verified against the references only. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:56:47 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2509
No description provided.