diff options
| author | Bora Sevim <sevimbora@gmail.com> | 2026-11-22 22:35:50 +0300 |
|---|---|---|
| committer | Bora Sevim <sevimbora@gmail.com> | 2026-11-22 22:35:50 +0300 |
| commit | 364fdcbd28feb1708fd28b4727b3cc8f4a1ad1a7 (patch) | |
| tree | acce8da5f81d727993a9cbc8bb11400d89fecda9 /runtime/test/gameinput_probe.cpp | |
| parent | 162821017ea3c286c8bec860f3ff94f037912061 (diff) | |
gameinput: raw HID reports and raw device I/O through SDL's hidapi (RT-175)
The shim opens each pad's HID device with SDL_hid_* (by SDL's device path, else the one game-pad collection with the
pad's vendor and product id) and reads its report descriptor for every input, output and feature report's id and
size. Such a pad reports GameInputKindRawDeviceReport and GameInputDeviceRawIoEnabled and fills inputReportInfo,
outputReportInfo and featureReportInfo (no item tables). Readings carry the newest raw input report, and
IGameInputReading::GetRawReport returns it as an IGameInputRawDeviceReport. CreateRawDeviceReport,
GetRawDeviceFeature, SetRawDeviceFeature and SendRawDeviceOutput work through the backend; an undeclared id or kind
is E_INVALIDARG, a failed transfer E_FAIL, and a pad without a HID device keeps E_NOTIMPL.
gameinput_abi.h declares IGameInputRawDeviceReport, GameInputRawDeviceReportKind and the three raw report info
structs, checked against Microsoft's v0 header (offsetof for every field, the 12 vtable slots, the IID). Xbox pads on
Windows go through XInput, whose HID interface SDL's hidapi skips, so they have no raw I/O; the log says so.
gameinput_test covers the descriptor parser and the whole path with a fake HID backend (24 checks);
gameinput_probe prints each pad's report tables and newest raw input report. docs/gameinput.md: "Raw HID".
Diffstat (limited to 'runtime/test/gameinput_probe.cpp')
| -rw-r--r-- | runtime/test/gameinput_probe.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/runtime/test/gameinput_probe.cpp b/runtime/test/gameinput_probe.cpp index 32ddf5d91..297ca16db 100644 --- a/runtime/test/gameinput_probe.cpp +++ b/runtime/test/gameinput_probe.cpp | |||
| @@ -2,7 +2,8 @@ | |||
| 2 | // | 2 | // |
| 3 | // gameinput_probe [--seconds N] [--rumble] | 3 | // gameinput_probe [--seconds N] [--rumble] |
| 4 | // | 4 | // |
| 5 | // Lists the gamepads the shim sees, then prints the live gamepad reading of each for N seconds (default 10). With | 5 | // Lists the gamepads the shim sees, with the raw HID report tables of each pad opened through HID, then prints the |
| 6 | // live gamepad reading (and its newest raw input report, when there is one) for N seconds (default 10). With | ||
| 6 | // --rumble it first plays, on every pad: the low-frequency motor, the high-frequency motor, the left and the right | 7 | // --rumble it first plays, on every pad: the low-frequency motor, the high-frequency motor, the left and the right |
| 7 | // impulse trigger, one second each. On a DualSense the trigger steps run in the LEONIDA_DS_TRIGGERS mode (rumble by | 8 | // impulse trigger, one second each. On a DualSense the trigger steps run in the LEONIDA_DS_TRIGGERS mode (rumble by |
| 8 | // default; set it to resistance to feel that one). Everything goes through GameInputCreate from the shim registry, | 9 | // default; set it to resistance to feel that one). Everything goes through GameInputCreate from the shim registry, |
| @@ -28,6 +29,22 @@ void CALLBACK on_device(GameInputCallbackToken, void*, IGameInputDevice* device, | |||
| 28 | const GameInputDeviceInfo* i = device->GetDeviceInfo(); | 29 | const GameInputDeviceInfo* i = device->GetDeviceInfo(); |
| 29 | std::printf("\n%s %s (%04x:%04x) motors=0x%x\n", (current & GameInputDeviceConnected) ? "connected " : "disconnected", | 30 | std::printf("\n%s %s (%04x:%04x) motors=0x%x\n", (current & GameInputDeviceConnected) ? "connected " : "disconnected", |
| 30 | i->displayName ? i->displayName->data : "?", i->vendorId, i->productId, i->supportedRumbleMotors); | 31 | i->displayName ? i->displayName->data : "?", i->vendorId, i->productId, i->supportedRumbleMotors); |
| 32 | // Raw HID (RT-175): the report tables read from the pad's HID report descriptor, or why there are none. | ||
| 33 | if (current & GameInputDeviceConnected) { | ||
| 34 | if (!(current & GameInputDeviceRawIoEnabled)) { | ||
| 35 | std::printf("raw hid: no raw I/O (no HID device the backend could open, or no readable descriptor)\n"); | ||
| 36 | } else { | ||
| 37 | const auto list = [](const char* kind, uint32_t n, const void* p) { | ||
| 38 | const auto* r = static_cast<const GameInputRawDeviceReportInfo*>(p); | ||
| 39 | std::printf("raw hid: %u %s report(s):", n, kind); | ||
| 40 | for (uint32_t k = 0; k < n; ++k) std::printf(" id %u = %u bytes;", r[k].id, r[k].size); | ||
| 41 | std::printf("\n"); | ||
| 42 | }; | ||
| 43 | list("input", i->inputReportCount, i->inputReportInfo); | ||
| 44 | list("output", i->outputReportCount, i->outputReportInfo); | ||
| 45 | list("feature", i->featureReportCount, i->featureReportInfo); | ||
| 46 | } | ||
| 47 | } | ||
| 31 | if ((current & GameInputDeviceConnected) && !(previous & GameInputDeviceConnected)) { | 48 | if ((current & GameInputDeviceConnected) && !(previous & GameInputDeviceConnected)) { |
| 32 | device->AddRef(); | 49 | device->AddRef(); |
| 33 | g_devices.push_back(device); | 50 | g_devices.push_back(device); |
| @@ -96,6 +113,16 @@ int main(int argc, char** argv) { | |||
| 96 | if (motion) // fractions of motionInfo's maxima: accel includes gravity, so a resting pad shows ~0.5 g | 113 | if (motion) // fractions of motionInfo's maxima: accel includes gravity, so a resting pad shows ~0.5 g |
| 97 | std::printf("\n[a]=(%+.2f,%+.2f,%+.2f) [w]=(%+.2f,%+.2f,%+.2f) ", m.accelerationX, m.accelerationY, | 114 | std::printf("\n[a]=(%+.2f,%+.2f,%+.2f) [w]=(%+.2f,%+.2f,%+.2f) ", m.accelerationX, m.accelerationY, |
| 98 | m.accelerationZ, m.angularVelocityX, m.angularVelocityY, m.angularVelocityZ); | 115 | m.accelerationZ, m.angularVelocityX, m.angularVelocityY, m.angularVelocityZ); |
| 116 | void* raw = nullptr; | ||
| 117 | if (r->GetRawReport(&raw) && raw) { // the newest raw input report: id and its first 16 bytes | ||
| 118 | auto* rr = static_cast<IGameInputRawDeviceReport*>(raw); | ||
| 119 | unsigned char b[16] = {}; | ||
| 120 | const size_t n = rr->GetRawData(sizeof b, b); | ||
| 121 | std::printf("\nraw id %u (%zu bytes):", rr->GetReportInfo()->id, rr->GetRawDataSize()); | ||
| 122 | for (size_t k = 0; k < n; ++k) std::printf(" %02x", b[k]); | ||
| 123 | std::printf(" "); | ||
| 124 | rr->Release(); | ||
| 125 | } | ||
| 99 | std::fflush(stdout); | 126 | std::fflush(stdout); |
| 100 | r->Release(); | 127 | r->Release(); |
| 101 | } | 128 | } |