Repository navigation
feat(gamepad_map): per-controller rumble options (off / strength / swap motors) - #928
Merged
Merged
Conversation
…ap motors)
espp::RumbleOptions (rumble_options.hpp, beside rumble_state.hpp so both can
move into a rumble component later): {flags: RUMBLE_OFF | SWAP_MOTORS,
strength_percent 0..200, default 100}. apply(request) is pure / constexpr /
allocation-free: off -> all motors 0; otherwise Strong / Weak swapped when
asked (trigger motors never), every motor min(255, (level * pct + 50) / 100).
100 % is the exact identity and a 0 level stays 0 for every option, so a stop
is always a stop. The application applies it once, at send time, to the
host's raw request; espp never applies it by itself.
GamepadProfiles (file schema v2):
- every GamepadProfile has `rumble`, and the store has default_rumble (also
Config::default_rumble for a store without a file);
- rumble_for(), default_rumble(), set_default_rumble(), set_defaults() (map +
rumble in one save), set_profile_map() (keeps a profile's rumble; a new one
starts from the default's); set_profile() replaces the whole profile;
- V1 is frozen (GamepadProfileV1; its layout fingerprint 0x4ed1a13b is pinned
and a V1 file written by the previous release is loaded in the host test).
A V1 file loads with neutral options and stays V1 until the first change
(save_after_migration = false), so a rollback before any edit keeps maps;
- loaded options are sanitized (unknown flag bits cleared, strength clamped),
invalid ones are refused on every write.
Wire protocol: still espp.gamepad_map v1 (a released console hides a module
advertised at another version). INFO flags bit1 = the device stores rumble
options; MAP flags bit1 + a [flags][strength] block; SET_MAP takes an optional
trailing block, and without it the stored options are kept, so an older
console can never reset them. A SET_MAP with anything but 0 or 2 bytes after
the map is malformed.
GamepadMapService: active_rumble(), Config::on_active_rumble_changed. change()
now decides its notifications after the save, with a controller generation
counter: a controller that connected while a change was saved used to keep
the stale map; now it gets the map and rumble callbacks.
Console: a Rumble row in the map editor (on / strength slider / 100 % / swap,
with notes), saved in the same SET_MAP as the map; disabled with a note on
firmware without rumble options. The codec block mirrors the C++ (decoded
objects gain fields only when the device sent them; unknown flag bits are
kept and echoed).
Tests: host test (the apply parity table, exhaustive identity / stop / monotonic
checks, the store API, sanitizing, the V1 golden file + both pinned
fingerprints, the downgrade error), protocol test (rumble goldens), a new
GamepadMapService host test (wire, keep-when-absent, callbacks, the
connect-during-save race) added to CI, codec test (21 groups). Examples
updated (the example gains 3 checks); README / rst / Doxyfile documented.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
…econnect to older firmware) From an adversarial review of the rumble-options change: - GamepadMapService::change(): the controller and its generation are read together (one snapshot under the service lock) and the values are looked up for that controller. After the callbacks, the controller is re-checked: if another one connected while they ran (it may have been handed its values just before a callback delivered the previous controller's), the callbacks run again for it, so the last notification always matches the connected controller. Bounded to 4 rounds. - Several services on one store: set_controller() on every service first, then one lookup, all under the app's lock (doc, README, webapp example); looking up between the services left a window where a change through the second one was neither seen nor notified. - Console: the Rumble row and Save follow the CONNECTED device's INFO bit1 as well as the loaded map. An editor kept across a reconnect to firmware without rumble options used to send the rumble block on every Save (refused as malformed SET_MAP, so the carried edits could never be saved); it now sends the v1 form and says the map alone is saved. An editor loaded from older firmware and reconnected to newer firmware asks for a reload instead of claiming the firmware has no rumble options. - Service host test: case 8 shows the controller generation alone triggers the callbacks (values equal before / after; fails without it), case 9 the re-check after the callbacks (fails on the previous change()). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
|
✅Static analysis result - no issues found! ✅ |
…fore saving - Protocol (still espp.gamepad_map v1): TEST_RUMBLE 0x08, payload [rumble] (exactly 2 bytes). INFO flags bit2 says the device takes it, so a console never sends it to firmware that does not know it. - GamepadMapService: Config::on_test_rumble(options, error) -> bool. The app plays a short test pattern on the connected controller through the unsaved options (returning promptly), or returns false with a reason. Unset: INFO bit2 clear and TEST_RUMBLE answers ERROR (not supported). Invalid options / a malformed payload are refused (EINVAL); nothing is ever saved. - Console: a Test button in the Rumble row sends the options as edited. It is enabled only when the device offers the test, a controller is connected and the options are on and valid (its tooltip says which is missing); the device's reply or refusal shows in the editor status. - Webapp example: on_test_rumble logs the options it would play (the demo controller has no motors); README / webapp README / web_apps.rst document it. - Tests: protocol goldens (INFO 0x06, TEST_RUMBLE 02 96, short / trailing payloads), service (refused without the callback; options reach it unsaved; invalid / malformed refused; the app's reason relayed), codec (22 groups). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
finger563
added a commit
to finger563/esp-usb-ble-hid
that referenced
this pull request
Nov 25, 2026
…rumble Test preview Uses espp's per-controller rumble options (esp-cpp/espp#928): - main/rumble.cpp: the sender keeps the host's request raw and applies the connected controller's RumbleOptions at send time (rumble_set_options()): dedupe / keep-alive / stop repeats work on the shaped levels, so turning rumble off or changing the strength takes effect at once, even while the host holds a level. The test pattern is now strong only at 128 for 300 ms, then weak only (600 ms), through the options, so strength and swap can be heard. rumble_test(preview) returns Ok / NoController / CannotRumble / Off; a preview plays through the given options without saving them. - services: on_gamepad_rumble_changed (GamepadMapService:: on_active_rumble_changed) and on_gamepad_test_rumble (on_test_rumble, so INFO says the dongle takes TEST_RUMBLE); services_gamepad_rumble(). - main.cpp: on connect, the map, rumble options and encoder are handed over under decode_mutex (lock order change_mutex -> decode_mutex -> rumble); the Device tab's Test rumble now also reports "rumble is off for this controller (Button mapping tab)". - Console: the gamepad-map codec block re-synced verbatim from espp; the Button mapping tab gets the Rumble row (on / strength / 100 % / swap, saved with the map) and a Test button (TEST_RUMBLE, the edited settings, not saved), both gated on what the dongle reports. - Docs: button mapping, web console, controllers, troubleshooting, updating (rolling back after editing maps sets gamepad_profiles.bin aside), README. Tested on hardware (T-Dongle-S3 in Xbox 360 mode, espp's hid_service example on an ESP32-S3-BOX as the BLE gamepad, logging each output report): neutral 200/120 -> 78/47 %; 50 % -> 39/24; swap -> 47/78; off -> nothing sent; off while the host holds 255/255 -> stops x3 at once; Test preview plays strong then weak through the unsaved options (also while the saved ones are off), swapped when asked; off previews and the Device-tab test with saved off are refused with their reasons; options survive a reboot. Console test 25 groups, device_config host test, cppcheck (CI flags) pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
finger563
added a commit
to finger563/esp-usb-ble-hid
that referenced
this pull request
Nov 25, 2026
espp/gamepad_map >= 1.4.8 (RumbleOptions, GamepadMapService:: on_active_rumble_changed / on_test_rumble, esp-cpp/espp#928); dependencies.lock regenerated from the registry. docs/architecture.md: the espp rows now name the floors main/idf_component.yml asks for and what the dongle uses from hid-rp / switch_pro / gamepad_map for rumble. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
finger563
added a commit
to finger563/esp-usb-ble-hid
that referenced
this pull request
Nov 25, 2026
…Test preview (#47) * feat: per-controller rumble options (off / strength / swap motors) + rumble Test preview Uses espp's per-controller rumble options (esp-cpp/espp#928): - main/rumble.cpp: the sender keeps the host's request raw and applies the connected controller's RumbleOptions at send time (rumble_set_options()): dedupe / keep-alive / stop repeats work on the shaped levels, so turning rumble off or changing the strength takes effect at once, even while the host holds a level. The test pattern is now strong only at 128 for 300 ms, then weak only (600 ms), through the options, so strength and swap can be heard. rumble_test(preview) returns Ok / NoController / CannotRumble / Off; a preview plays through the given options without saving them. - services: on_gamepad_rumble_changed (GamepadMapService:: on_active_rumble_changed) and on_gamepad_test_rumble (on_test_rumble, so INFO says the dongle takes TEST_RUMBLE); services_gamepad_rumble(). - main.cpp: on connect, the map, rumble options and encoder are handed over under decode_mutex (lock order change_mutex -> decode_mutex -> rumble); the Device tab's Test rumble now also reports "rumble is off for this controller (Button mapping tab)". - Console: the gamepad-map codec block re-synced verbatim from espp; the Button mapping tab gets the Rumble row (on / strength / 100 % / swap, saved with the map) and a Test button (TEST_RUMBLE, the edited settings, not saved), both gated on what the dongle reports. - Docs: button mapping, web console, controllers, troubleshooting, updating (rolling back after editing maps sets gamepad_profiles.bin aside), README. Tested on hardware (T-Dongle-S3 in Xbox 360 mode, espp's hid_service example on an ESP32-S3-BOX as the BLE gamepad, logging each output report): neutral 200/120 -> 78/47 %; 50 % -> 39/24; swap -> 47/78; off -> nothing sent; off while the host holds 255/255 -> stops x3 at once; Test preview plays strong then weak through the unsaved options (also while the saved ones are off), swapped when asked; off previews and the Device-tab test with saved off are refused with their reasons; options survive a reboot. Console test 25 groups, device_config host test, cppcheck (CI flags) pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU * fix(console): rumble review fixes (Save before INFO, Test at 0 %) From an adversarial review: - While the dongle is connected but this connection's gamepad-map INFO has not arrived yet, whether it stores rumble options is unknown: the Rumble row is not editable ("Reading the dongle's map settings...") and Save waits. Before, the loaded map decided, so a map carried across a reconnect to firmware without rumble options could be saved with the rumble block in that window and be refused as malformed. - Test is disabled at 0 % strength like off: the dongle refuses a 0 % test ("rumble is off in these settings"), so the button no longer offers it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU * build: espp 1.4.8 (per-controller rumble options) espp/gamepad_map >= 1.4.8 (RumbleOptions, GamepadMapService:: on_active_rumble_changed / on_test_rumble, esp-cpp/espp#928); dependencies.lock regenerated from the registry. docs/architecture.md: the espp rows now name the floors main/idf_component.yml asks for and what the dongle uses from hid-rp / switch_pro / gamepad_map for rumble. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Per-controller rumble options in
gamepad_map: turn a controller type's rumble off, scale it (0–200 %), or swap its strong and weak motors. Each profile stores its options next to its map, and the default map has its own set for controllers without a profile. Builds on the descriptor-driven rumble pieces from #927.espp::RumbleOptions(rumble_options.hpp)Two bytes of plain data:
flags(RUMBLE_OFF,SWAP_MOTORS) andstrength_percent(0..200, default 100). It sits besiderumble_state.hpp, so both can move into a rumble component later.apply(request)is pure, constexpr and does not allocate:min(255, (level * pct + 50) / 100);espp never applies the options by itself. The application applies them once, at send time, to the host's raw request. The README explains why.
Storage:
GamepadProfilesfile schema v2GamepadProfile::rumble,default_rumbleandConfig::default_rumble;rumble_for(),default_rumble(),set_default_rumble(),set_defaults()(map and rumble in one save), andset_profile_map()(a stored profile keeps its rumble options; a new profile starts from the default's);set_profile()still replaces the whole profile.GamepadProfileV1keeps the V1 layout; its fingerprint0x4ed1a13bis pinned in the host test, and so is V2's;save_after_migration = false). A rollback before any edit therefore keeps the maps.Wire protocol: still
espp.gamepad_mapv1The released dongle console hides a module advertised at any other protocol version, so the additions are announced by capability bits instead:
[flags][strength]block after the map.GamepadMapServiceactive_rumble()andConfig::on_active_rumble_changed.change()now decides its notifications after the save, from one snapshot of the connected controller and its generation, and re-checks once its callbacks have run. Two existing races are fixed:set_controller()on all of them first, then look the values up once. This is documented, and the webapp example does it.Console
The map editor gets a Rumble row (on, a strength slider, 100 %, swap) with explanatory notes, saved in the same SET_MAP as the map. It follows the connected device's INFO as well as the loaded map:
Test button (
TEST_RUMBLE)TEST_RUMBLE(0x08, payload[rumble]). The device plays a short test pattern on the connected controller through them and saves nothing.Config::on_test_rumble(options, error) -> boolis the application's hook. It starts the pattern and returns promptly, or returnsfalsewith a reason (for example "no controller connected"), which the console shows. Without the hook, bit2 stays clear and the request gets a "not supported" ERROR.Tests
gamepad_map_host_test: theapply()parity table, plus exhaustive identity, stop-safety and monotonicity checks; the store API; sanitizing; the V1 golden file and both pinned fingerprints; the downgrade error.gamepad_map_protocol_host_test: the rumble goldens for INFO, MAP, SET_MAP and TEST_RUMBLE.gamepad_map_service_host_test, added to CI: the wire format, keep-when-absent, the callbacks, both races, and TEST_RUMBLE (refused without the hook; options reach the hook unsaved; invalid or malformed requests refused; the app's reason relayed). I checked that the race cases fail against the previouschange()and against a copy with the generation check disabled.🤖 Generated with Claude Code
https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU