Skip to content

feat(hid-rp): a HID Descriptor Inspector web app, on the firmware's own parser - #965

Merged
finger563 merged 3 commits into
mainfrom
feat/hid-descriptor-inspector
Dec 2, 2026
Merged

finger563 merged 3 commits into
mainfrom
feat/hid-descriptor-inspector

Conversation

@finger563

@finger563 finger563 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This adds a new web app, the HID Descriptor Inspector. You paste a USB or BLE HID report descriptor and see it the way espp's firmware reads it. The parsing is hid-rp's own C++, the code the firmware runs on a device's descriptor, compiled to WebAssembly. hid-rp can't be exposed to Python, and the browser's WebHID API doesn't hand a page the raw descriptor bytes, so this is parsing a web page couldn't otherwise do.

It's part of step 4d of the testing plan (previews of on-device code in the browser), and it's the "HID descriptor inspector" tool the plan names.

#964 (the ReportMap::parse() safety fix this tool relies on) is merged; this is rebased onto main.

What it shows

  • Every item: named, with usage-page and usage names, collections indented, and main-item flags such as Data, Var, Abs. A cut-off descriptor is listed up to where it's cut, with the reason.
  • The fields ReportMap maps, inputs and outputs: report ID, bit offset and size, usage, logical range, array or variable.
  • The report sizes, and what the decoders take the descriptor for: a gamepad and its button layout (Xbox-style, DirectInput or Android), a keyboard or a mouse.
  • A decoded input report, as the GamepadState a remapper (gamepad_map) sees:
    • Report: typed in, or decoded live from a HID device over WebHID; the VID/PID fill in from the device.
    • Options: pass-through or combined controls, and per-device quirks by VID/PID.
  • Presets: hid-rp's generated Xbox, DualSense-over-BLE and SpaceMouse descriptors, plus a real controller's (ShanWan BM-769, Android mode, over BLE) with a sample report.

What's in it

  • inspector/hid_inspector.hpp:
    • parse_json(), decode_json() and presets_json();
    • built on ReportMap, GamepadDecoder, KeyboardDecoder, MouseDecoder and gamepad_map's to_gamepad_state().
  • inspector/hid_inspector_wasm.cpp and build_wasm.sh:
    • Emscripten 4.0.10, built with -fno-exceptions like the firmware;
    • writes web/hid_inspector.js, 84 KB and gitignored; the docs build publishes it beside the page.
  • web/hid_descriptor_inspector.html: the page. Without the module, it explains how to build it or links the published copy.
  • CI: the WebAssembly job also builds this module and requires the page's test.
  • Docs: the hid-rp README and the web apps page describe it.

Tests

  • test/hid_inspector_host_test.cpp (C++):
    • every preset parses;
    • items, fields and classification for the Xbox descriptor and the SpaceMouse;
    • the real controller's report, pass-through and combined;
    • sign-extended item values, malformed descriptors, JSON escaping.
  • web/test/hid_inspector_ui_test.js (headless Chrome): the presets, the real controller (classification, 60 items, 24 fields, its report decoded, R2 when combined), item naming, hex with commas / 0x / comments, a truncated descriptor refused with where it's cut, and bad hex.
  • Results: 3 of 3 runs pass, 8 checks each, and all 40 host tests and 17 web tests pass.
  • Mutation check: inverting the combine flag in decode_json fails the UI test.

Worth knowing

The inspector shows what the decoders conclude, not what a device is:

  • Xbox: hid-rp's Xbox descriptor is the Xbox Wireless controller over BLE, which reads with the Android layout.
  • SpaceMouse: a SpaceMouse classifies as a gamepad and a mouse.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU

@finger563
finger563 force-pushed the feat/hid-descriptor-inspector branch from c18f701 to 48419f8 Compare December 2, 2026 02:01
Base automatically changed from fix/hid-rp-truncated-descriptor to main December 2, 2026 03:17
finger563 and others added 2 commits December 1, 2026 21:17
…wn parser

Paste a USB / BLE HID report descriptor and see it the way espp's firmware
reads it: every item (named, with usage page / usage names, collections
nested), the Input and Output fields hid-rp's ReportMap maps (report ID, bit
offset and size, usage, logical range), the report sizes, what the decoders
take it for (gamepad and its button layout, keyboard, mouse), and an input
report decoded into the GamepadState a remapper sees - typed in, or live from
a HID device over WebHID (the descriptor is pasted: browsers do not expose
it). Presets: hid-rp's generated Xbox / DualSense BLE / SpaceMouse
descriptors and a real controller's (ShanWan BM-769 over BLE, with a report).

- inspector/hid_inspector.hpp: parse_json() / decode_json() / presets_json()
  over ReportMap, GamepadDecoder, KeyboardDecoder, MouseDecoder and
  gamepad_map's to_gamepad_state(); the item walk reports where a
  descriptor is cut. hid_inspector_wasm.cpp + build_wasm.sh (Emscripten
  4.0.10, -fno-exceptions like the firmware): web/hid_inspector.js, 84 KB,
  gitignored; the docs build publishes it.
- web/hid_descriptor_inspector.html: renders the JSON; says how to build
  the module when it is missing.
- tests: test/hid_inspector_host_test.cpp (C++), web/test/hid_inspector_ui_test.js
  (the page in headless Chrome); CI's WebAssembly 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
…erence)

g++ flags binding a reference to what a call taking a temporary returns,
though preset() returns into a static; take a copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
@finger563
finger563 force-pushed the feat/hid-descriptor-inspector branch from 44f0098 to e0995c2 Compare December 2, 2026 03:18
@finger563
finger563 marked this pull request as ready for review December 2, 2026 03:18
Copilot AI balanced review requested due to automatic review settings December 2, 2026 03:18
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

✅Static analysis result - no issues found! ✅

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

4 open issues
What changed in this PR

Adds a new “HID Descriptor Inspector” web app that runs hid-rp’s on-device descriptor parsing + decoding logic in the browser via WebAssembly, plus CI and documentation updates to build and validate it.

Changes:

  • Add C++ inspector API (parse_json, decode_json, presets) and WebAssembly entrypoints + build script.
  • Add the web UI page and headless-Chrome UI test coverage.
  • Wire module build + UI test into CI/docs, and document the new app.
File Description
doc/​en/​web_apps.rst Document the new HID Descriptor Inspector web app in the web apps list.
components/​hid-rp/​web/​test/​hid_inspector_ui_test.js Add headless Chrome UI test for the inspector page + wasm module.
components/​hid-rp/​web/​hid_descriptor_inspector.html Add the inspector UI (descriptor parsing, field display, decoding, WebHID live mode).
components/​hid-rp/​test/​hid_inspector_host_test.cpp Add host-side doctest coverage for inspector JSON outputs and presets.
components/​hid-rp/​test/​CMakeLists.txt Register the new inspector host test and include inspector headers.
components/​hid-rp/​inspector/​hid_inspector_wasm.cpp Add wasm C ABI exports bridging to the inspector JSON functions.
components/​hid-rp/​inspector/​hid_inspector.hpp Implement JSON writer + inspector parse/decode/presets logic in C++.
components/​hid-rp/​inspector/​build_wasm.sh Add a pinned Emscripten build script producing web/hid_inspector.js.
components/​hid-rp/​README.md Document the inspector app, its purpose, and how to build/test it.
components/​dispatcher/​web/​test/​shared_blocks_test.js Update expected shared-block splice counts for app navigation.
.gitignore Ignore generated components/hid-rp/web/hid_inspector.js.
.github/​workflows/​host_tests.yml Build the inspector wasm module and run the inspector UI test in CI.
.github/​workflows/​build_and_publish_docs.yml Build the inspector wasm module as part of docs publishing.

Review effort: Lite

- a module that fails to load shows the notice with the reason and
  disables Inspect / Decode / live (it looked like a hang);
- live reports with an ID are built without argument spreading;
- parse_json() computes well_formed() once;
- the host test's preset() uses std::find_if (cppcheck) and REQUIRE, and
  never dereferences an empty list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
@finger563
finger563 merged commit c8a5708 into main Dec 2, 2026
192 checks passed
@finger563
finger563 deleted the feat/hid-descriptor-inspector branch December 2, 2026 04:51
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