Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build_and_publish_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ jobs:
# written next to their pages (components/*/web/*.js), so the apps
# copy below publishes them and the pages offer "Connect virtual device"
run: |
git submodule update --init components/format/detail/fmt components/serialization/detail/alpaca
git submodule update --init components/format/detail/fmt components/serialization/detail/alpaca components/hid-rp/detail/hid-rp
source ~/emsdk/emsdk_env.sh
components/canopen/can_bridge_example/virtual/build_wasm.sh
components/gamepad_map/virtual/build_wasm.sh
components/hid-rp/inspector/build_wasm.sh
- name: Build Documentation (HTML)
run: |
cd doc
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/host_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ jobs:
~/emsdk/emsdk activate "$EMSDK_VERSION"
- name: Build the virtual devices
run: |
git submodule update --init components/format/detail/fmt components/serialization/detail/alpaca
git submodule update --init components/format/detail/fmt components/serialization/detail/alpaca components/hid-rp/detail/hid-rp
source ~/emsdk/emsdk_env.sh
components/canopen/can_bridge_example/virtual/build_wasm.sh
components/gamepad_map/virtual/build_wasm.sh
components/hid-rp/inspector/build_wasm.sh
- name: The protocol, end to end (the apps' code over the virtual device)
env:
REQUIRE_VIRTUAL_DEVICES: "1"
Expand All @@ -131,3 +132,8 @@ jobs:
REQUIRE_VIRTUAL_DEVICES: "1"
CHROME: google-chrome
run: node components/gamepad_map/web/test/virtual_device_ui_test.js
- name: The HID Descriptor Inspector in headless Chrome
env:
REQUIRE_VIRTUAL_DEVICES: "1"
CHROME: google-chrome
run: node components/hid-rp/web/test/hid_inspector_ui_test.js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ components/rtps/interop/qemu/images/
# the docs build publishes them, they are never committed
components/canopen/web/virtual_can_bridge.js
components/gamepad_map/web/virtual_gamepad_map.js
components/hid-rp/web/hid_inspector.js
2 changes: 1 addition & 1 deletion components/dispatcher/web/test/shared_blocks_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const expected = {
"virtual device": 3, // the CAN bridge console and DS402 panel (virtual CAN bridge), the Gamepad Map console
"module discovery": 11, // every dispatcher-module console
"connection helpers": 12, // ... and the hub
"app navigation": 19, // every web app
"app navigation": 20, // every web app
"app hand-back": 11, // every dispatcher-module console
};
for (const block of S.BLOCKS) {
Expand Down
22 changes: 22 additions & 0 deletions components/hid-rp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@ Pop balance, only known items, a usage page for every short usage) and returns
exceptions are enabled; without them (ESP-IDF's default) a truncated or
malformed descriptor made it read past the buffer.

## Descriptor inspector

The [HID Descriptor Inspector](https://esp-cpp.github.io/espp/apps/hid_descriptor_inspector.html)
web app shows a pasted report descriptor the way the firmware reads it: every
item, the fields `ReportMap` maps (bit offsets, usages, logical ranges), the
report sizes, what the decoders take it for (a gamepad and its button layout, a
keyboard, a mouse), and any input report decoded into the `GamepadState` a
remapper sees, typed in or live from a HID device through WebHID (browsers do
not hand a page the raw descriptor, so it is pasted; they also keep keyboards
and mice from WebHID). The parsing is this component's own C++
(`inspector/hid_inspector.hpp`, host-tested by `test/hid_inspector_host_test.cpp`),
compiled to WebAssembly:

```
source <emsdk>/emsdk_env.sh # emsdk install 4.0.10 && emsdk activate 4.0.10
components/hid-rp/inspector/build_wasm.sh
```

That writes `web/hid_inspector.js` (gitignored; the docs build publishes it
with the apps). `web/test/hid_inspector_ui_test.js` runs the page in headless
Chrome; CI builds the module and requires it.

## Rumble

`hid-rp-rumble.hpp` handles rumble in both directions of a controller bridge:
Expand Down
39 changes: 39 additions & 0 deletions components/hid-rp/inspector/build_wasm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# Build the HID descriptor inspector's C++ side (hid-rp's ReportMap and
# decoders) for the hid_descriptor_inspector web app, with a pinned Emscripten:
#
# source <emsdk>/emsdk_env.sh # emsdk install 4.0.10 && emsdk activate 4.0.10
# components/hid-rp/inspector/build_wasm.sh [out.js]
#
# Writes components/hid-rp/web/hid_inspector.js by default (gitignored): the
# WebAssembly module inlined (base64) in its loader, so the page works from
# file:// as well as from the published apps (the docs build runs this, then
# copies it beside the page). Without it the page says how to build it.
set -euo pipefail
EMSCRIPTEN_VERSION=4.0.10
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
components="$(cd "$here/../.." && pwd)"
have="$(emcc --version | head -1 | sed -E 's/.* ([0-9]+\.[0-9]+\.[0-9]+) .*/\1/')"
if [ "$have" != "$EMSCRIPTEN_VERSION" ]; then
echo "need Emscripten $EMSCRIPTEN_VERSION (emsdk install/activate $EMSCRIPTEN_VERSION), have $have" >&2
exit 1
fi
out="${1:-$components/hid-rp/web/hid_inspector.js}"
mkdir -p "$(dirname "$out")"
for h in "$components/hid-rp/detail/hid-rp/hid-rp/hid/rdf/parser.hpp" \
"$components/format/detail/fmt/include/fmt/format.h"; do
[ -f "$h" ] || { echo "missing $h: git submodule update --init components/hid-rp/detail/hid-rp components/format/detail/fmt" >&2; exit 1; }
done
includes=(-I"$here")
for d in "$components"/*/include; do includes+=(-I"$d"); done
includes+=(-isystem "$components/hid-rp/detail/hid-rp/hid-rp"
-isystem "$components/format/detail/fmt/include")
# -fno-exceptions, as the firmware builds hid-rp (ReportMap::parse() checks the
# descriptor first, so its parser's assertions are never needed)
em++ -std=c++23 -Oz -fno-exceptions -flto "${includes[@]}" "$here/hid_inspector_wasm.cpp" \
-sMODULARIZE -sEXPORT_NAME=HidInspectorModule -sENVIRONMENT=web,node -sSINGLE_FILE=1 \
-sALLOW_MEMORY_GROWTH -sFILESYSTEM=0 -sASSERTIONS=0 \
-sEXPORTED_FUNCTIONS=_hri_alloc,_hri_free,_hri_parse,_hri_decode,_hri_presets \
-sEXPORTED_RUNTIME_METHODS=HEAPU8,UTF8ToString \
-o "$out"
echo "wrote $out ($(wc -c < "$out" | tr -d ' ') bytes)"
Loading
Loading