Send the game's vibration values as they are to a Switch Pro Controller or Joy-Con, behind rumble_hd.

With NX2NAVI_RUMBLE_HD=1 (live, off by default) the gamepad the game reads, when it is a Switch Pro Controller, a
single Joy-Con or a pair of them, gets each side's low and high band with its own frequency and amplitude in the
controller's rumble report, and no dual-motor call any more. A Pro Controller and a single Joy-Con take the report
through SDL's effect call, over USB and Bluetooth; SDL refuses that call for a combined pair, so a pair's reports are
written to its two HID devices directly. Every other gamepad, the Switch 2 controllers included, keeps the motors.

The game's thread posts its newest values and a thread of input.c writes the reports: at most one every 15 ms
(rumble_hd_ms), a held value again every 30 ms, and the neutral value when the game stops sending for 250 ms, when
another gamepad takes over, when the setting is turned off and before the process ends. The rumble strength scales the
amplitude and rumble = 0 silences this path as well. With the setting off nothing is written to the controller: the
log line at the take names it by its ids, and the first report is the trial.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-12 22:27:34 -05:00
parent 59e3c6c35a
commit df8431da7b
9 changed files with 441 additions and 7 deletions

View File

@@ -2,6 +2,8 @@
#pragma once
#include <stdint.h>
#include "rumble_hd.h"
// Bits of HidNpadButton (A=0 B=1 X=2 Y=3 StickL=4 StickR=5 L=6 R=7 ZL=8 ZR=9 Plus=10 Minus=11 Left=12 Up=13 Right=14
// Down=15) and the stick directions (StickLLeft..Down 16-19, StickRLeft..Down 20-23, derived from the sticks).
// Sticks are -32767..32767, up is +y. NX2NAVI_INPUT=none reports no input. Callable from any thread.
@@ -88,6 +90,19 @@ int input_rumble(uint16_t low, uint16_t high, uint32_t ms);
uint16_t rumble_motor(float a, float curve, float strength);
// NX2NAVI_RUMBLE_TRIGGERS=1: input_rumble also drives the impulse triggers (Xbox) with the high motor's value.
int input_rumble_triggers_enabled(void);
// HD rumble (input.c "HD rumble", rumble_hd.h): the game's vibration values as they are, for a gamepad with linear
// actuators (a Switch Pro Controller, a Joy-Con or a pair of them). All callable from any thread.
// input_rumble_hd_available: the gamepad the game reads is one of these (the menu's row).
// input_rumble_hd_on: ... and NX2NAVI_RUMBLE_HD is 1 (live) and NX2NAVI_RUMBLE is not 0: input_rumble then leaves that
// gamepad's motors alone, and the caller posts every new value with input_rumble_hd.
// input_rumble_hd: the game's newest value per side (v[0] left, v[1] right; live[s] 0: that side is at rest), the
// amplitudes scaled by strength (1 = as they are). Returns at once: a thread of input.c writes the reports, the newest
// value only, and the neutral value once the game stops posting.
// input_rumble_hd_stop: before the process ends, the neutral value for a controller that is still vibrating.
int input_rumble_hd_available(void);
int input_rumble_hd_on(void);
void input_rumble_hd(const RumbleHdValue v[2], const int live[2], float strength);
void input_rumble_hd_stop(void);
// Motion (NX2NAVI_MOTION=0 turns it off, live). input_motion_start starts the sensor thread once: every 4 ms it reads the
// gamepad's gyro and accelerometer (when it has them) and feeds motion_global(). Callable from any thread.