Skip to content

feat(gamepad_map): a virtual gamepad map device for the Gamepad Map console - #962

Merged
finger563 merged 3 commits into
mainfrom
feat/virtual-gamepad-map
Dec 1, 2026
Merged

finger563 merged 3 commits into
mainfrom
feat/virtual-gamepad-map

Conversation

@finger563

@finger563 finger563 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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: GamepadMapService over a GamepadProfiles store, with its demo controller, behind the dispatcher with discovery. It runs on one thread and is compiled to WebAssembly.

#960 (and #953 / #954 under it) are merged; this is rebased onto main and targets it.

What's in it

  • GamepadMapService: a new Config::manual_stream flag, off by default. With it set, the service starts no stream task: the owner calls poll_stream(), which sends the INPUT events that are due and ends the stream when its lease runs out. The task path is unchanged, and webapp_example still builds.
  • virtual/:
    • VirtualGamepadMap: the example's wiring and demo controller on one thread; set_button() and set_axis() hold controls on top of the demo motion.
    • C entry points for the page.
    • build_wasm.sh: Emscripten 4.0.10. It writes web/virtual_gamepad_map.js (387 KB, gitignored); the docs build publishes it with the apps.
    • Profiles live in the module's in-memory file system, so they last until the page reloads.
  • Console:
    • Connect virtual device, shown only when the module is present.
    • A Virtual controller row that holds buttons on the virtual controller, and can follow a gamepad connected to the computer through the browser's Gamepad API (standard mapping). That previews a map on a real controller, with no dongle.
  • Tests:
    • 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.
    • CI: the virtual-devices job builds the module and requires the UI test.

Verification

Locally, on macOS:

  • Host tests: 37 of 37 pass, including the existing gamepad_map_service_host_test, which exercises the refactored stream code.
  • Web tests: 13 of 13 pass, including the shared-block splice check.
  • Console UI test: 5 of 5 runs pass, 8 checks each.
  • Mutation check: giving the "Swap South / East" preset the wrong rules fails the test. The page is restored afterwards.
  • Firmware: webapp_example builds (ESP-IDF v6.1).

🤖 Generated with Claude Code

https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU

@finger563
finger563 force-pushed the feat/virtual-can-bridge branch from e4ed92f to 3bf4e7e Compare December 1, 2026 19:48
@finger563
finger563 force-pushed the feat/virtual-gamepad-map branch 3 times, most recently from d65bfbb to 5c10441 Compare December 1, 2026 20:10
Base automatically changed from feat/virtual-can-bridge to main December 1, 2026 21:31
finger563 and others added 2 commits December 1, 2026 15:31
…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
@finger563
finger563 force-pushed the feat/virtual-gamepad-map branch from 118f77b to 6f6448e Compare December 1, 2026 21:31
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

✅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
@finger563
finger563 marked this pull request as ready for review December 1, 2026 22:48
Copilot AI balanced review requested due to automatic review settings December 1, 2026 22:48
@finger563
finger563 merged commit 72515d6 into main Dec 1, 2026
199 of 201 checks passed
@finger563
finger563 deleted the feat/virtual-gamepad-map branch December 1, 2026 22:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
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 produce web/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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants