Repository navigation
feat(gamepad_map): a virtual gamepad map device for the Gamepad Map console - #962
Merged
Merged
Conversation
finger563
force-pushed
the
feat/virtual-can-bridge
branch
from
December 1, 2026 19:48
e4ed92f to
3bf4e7e
Compare
finger563
force-pushed
the
feat/virtual-gamepad-map
branch
3 times, most recently
from
December 1, 2026 20:10
d65bfbb to
5c10441
Compare
…onsole The gamepad map web app example's device side - GamepadMapService over a GamepadProfiles store, with its demo controller, behind the dispatcher with discovery - compiled to WebAssembly and run in the Gamepad Map console as a "virtual device": edit maps, save them, and watch the demo controller's input go through them, with no dongle. - GamepadMapService: Config::manual_stream (off by default) - no stream task; the owner calls poll_stream(), which sends the INPUT events that are due (and ends the stream when its lease ran out). The task path is unchanged (stream_step() now calls the shared send_stream_event()). - virtual/: VirtualGamepadMap (the example's wiring and demo controller on one thread; set_button() / set_axis() hold controls on top of the demo motion), its C entry points and build_wasm.sh (Emscripten 4.0.10, web/virtual_gamepad_map.js, gitignored; the docs build publishes it). The profile store lives in the module's in-memory file system. - console: "Connect virtual device" when the module is present, and a "Virtual controller" row that holds its buttons and can follow a gamepad connected to the computer (the browser's Gamepad API, standard mapping). - tests: virtual_gamepad_map_host_test (C++); web/test/virtual_device_ui_test.js (the console in headless Chrome: connect, live input, a held button, the South / East preset saved for the controller and applied at once, the profile list, the rumble test, erasing the profile). CI's virtual-devices job builds the module and requires the test. 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> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
finger563
force-pushed
the
feat/virtual-gamepad-map
branch
from
December 1, 2026 21:31
118f77b to
6f6448e
Compare
|
✅Static analysis result - no issues found! ✅ |
… write before the service cppcheck (initializerList): the service's callbacks capture this and write members that were declared after it. They only run after construction, but the order now says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
Contributor
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
3 open issues
poll_stream()returns early whennow < next_event_ms_, which means it won’t notice/stop an… · New When turning off “follow this computer’s gamepad” (!on), the code releases axes but does not… · Newstd::filesystem::remove(p)can throw (e.g., permission issues, unexpected filesystem errors) and… · New
What changed in this PR
Adds a WebAssembly-backed “virtual gamepad map” device so the Gamepad Map console can connect and preview/edit maps entirely in-page (no hardware dongle), including CI coverage for the new virtual-device flow.
Changes:
- Add
VirtualGamepadMap(C++), WASM entry points, and build script to produceweb/virtual_gamepad_map.js. - Extend the Gamepad Map console UI to load/connect the virtual device and optionally drive it via the browser Gamepad API.
- Add host (doctest) and headless Chrome UI tests, plus CI wiring to build and validate virtual devices.
| File | Description |
|---|---|
| doc/en/web_apps.rst | Document virtual device availability in the Gamepad Map console. |
| components/gamepad_map/web/test/virtual_device_ui_test.js | New headless-Chrome UI test for the console against the WASM virtual device. |
| components/gamepad_map/web/gamepad_map_console.html | Add “Connect virtual device” UI, virtual controller controls, and embed shared virtual-device transport block. |
| components/gamepad_map/virtual/virtual_gamepad_map_wasm.cpp | Provide C ABI exports used by the shared VirtualDevice transport. |
| components/gamepad_map/virtual/virtual_gamepad_map.hpp | Implement the single-threaded virtual device wrapper around GamepadMapService + demo controller. |
| components/gamepad_map/virtual/build_wasm.sh | Build script to generate virtual_gamepad_map.js via Emscripten. |
| components/gamepad_map/test/virtual_gamepad_map_host_test.cpp | New doctest host test exercising discovery, maps/profiles, rumble, and input streaming. |
| components/gamepad_map/test/CMakeLists.txt | Register the new host test and include the virtual headers. |
| components/gamepad_map/include/gamepad_map_service.hpp | Add manual_stream mode and poll_stream() for single-threaded/WASM usage. |
| components/gamepad_map/README.md | Document how to build/use the virtual device and its tests/CI. |
| components/dispatcher/web/test/shared_blocks_test.js | Update expected carrier count for the shared “virtual device” block. |
| components/dispatcher/web/shared/splice_shared.js | Update comments to include the new Gamepad Map console as a carrier of the virtual-device block. |
| .gitignore | Ignore generated components/gamepad_map/web/virtual_gamepad_map.js. |
| .github/workflows/host_tests.yml | Build the new virtual device and run its UI test in CI. |
| .github/workflows/build_and_publish_docs.yml | Build the new virtual device as part of docs publishing. |
Review effort: Lite
Comment on lines
+262
to
+270
| void poll_stream() { | ||
| if (!config_.manual_stream || !streaming_.load()) | ||
| return; | ||
| const int64_t now = now_ms(); | ||
| if (now < next_event_ms_.load()) | ||
| return; | ||
| next_event_ms_.store(now + period_ms_.load()); | ||
| send_stream_event(); | ||
| } |
Comment on lines
+2290
to
+2305
| function followGamepad(on) { | ||
| if (gamepadTimer) { clearInterval(gamepadTimer); gamepadTimer = null; } | ||
| const t = transport; | ||
| if (!(t instanceof VirtualDeviceTransport)) return; | ||
| if (!on) { for (let a = 0; a < 6; a++) t.call("set_axis", a, 0, 0); return; } | ||
| gamepadTimer = setInterval(() => { | ||
| if (transport !== t) { clearInterval(gamepadTimer); gamepadTimer = null; return; } | ||
| const pads = typeof navigator.getGamepads === "function" ? [...navigator.getGamepads()].filter(Boolean) : []; | ||
| const pad = pads[0]; | ||
| if (!pad) return; | ||
| STANDARD_TO_BUTTON.forEach((button, i) => { if (pad.buttons[i]) t.call("set_button", button, pad.buttons[i].pressed ? 1 : 0); }); | ||
| for (let a = 0; a < 4 && a < pad.axes.length; a++) t.call("set_axis", a, Math.round(pad.axes[a] * 32767), 1); | ||
| if (pad.buttons[6]) t.call("set_axis", 4, Math.round(pad.buttons[6].value * 32767), 1); | ||
| if (pad.buttons[7]) t.call("set_axis", 5, Math.round(pad.buttons[7].value * 32767), 1); | ||
| }, 16); | ||
| } |
Comment on lines
+30
to
+34
| std::filesystem::path temp_store(const char *name) { | ||
| auto p = std::filesystem::temp_directory_path() / name; | ||
| std::filesystem::remove(p); | ||
| return p; | ||
| } |
Copilot stopped reviewing on behalf of
finger563 due to an error
December 1, 2026 23:14
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.


Summary
This is the second virtual device (step 4d): the Gamepad Map console can now connect to a virtual gamepad map device. It runs in the page, so maps can be edited, saved and watched being applied to a controller's input, with no dongle.
The virtual device is the web app example's device side:
GamepadMapServiceover aGamepadProfilesstore, with its demo controller, behind the dispatcher with discovery. It runs on one thread and is compiled to WebAssembly.What's in it
GamepadMapService: a newConfig::manual_streamflag, off by default. With it set, the service starts no stream task: the owner callspoll_stream(), which sends the INPUT events that are due and ends the stream when its lease runs out. The task path is unchanged, andwebapp_examplestill builds.virtual/:VirtualGamepadMap: the example's wiring and demo controller on one thread;set_button()andset_axis()hold controls on top of the demo motion.build_wasm.sh: Emscripten 4.0.10. It writesweb/virtual_gamepad_map.js(387 KB, gitignored); the docs build publishes it with the apps.virtual_gamepad_map_host_test.cpp(C++): discovery, GET_INFO, SET_MAP for the controller changing its mapped input at once (including an inverted axis), LIST / ERASE, an invalid map refused, TEST_RUMBLE, and the INPUT stream with the moving demo stick.web/test/virtual_device_ui_test.js: the console in headless Chrome. It covers connecting, live raw and mapped input, a held button, the South / East preset saved for the controller and applied at once, the profile list, the rumble test, and erasing the profile.virtual-devicesjob builds the module and requires the UI test.Verification
Locally, on macOS:
gamepad_map_service_host_test, which exercises the refactored stream code.webapp_examplebuilds (ESP-IDF v6.1).🤖 Generated with Claude Code
https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU