upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/gameinput_probe.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/test/gameinput_probe.cpp')
-rw-r--r--runtime/test/gameinput_probe.cpp47
1 files changed, 42 insertions, 5 deletions
diff --git a/runtime/test/gameinput_probe.cpp b/runtime/test/gameinput_probe.cpp
index 510194f1d..58a6a1010 100644
--- a/runtime/test/gameinput_probe.cpp
+++ b/runtime/test/gameinput_probe.cpp
@@ -1,13 +1,15 @@
1// gameinput_probe: the GameInput shim on a real controller. Not a CTest; run it by hand with a pad connected. 1// gameinput_probe: the GameInput shim on a real controller. Not a CTest; run it by hand with a pad connected.
2// 2//
3// gameinput_probe [--seconds N] [--rumble] 3// gameinput_probe [--seconds N] [--rumble] [--force-feedback]
4// 4//
5// Lists the gamepads the shim sees, with the raw HID report tables of each pad opened through HID, then prints the 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// live gamepad reading (and its newest raw input report, when there is one) for N seconds (default 10). With
7// --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
8// 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
9// 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). With --force-feedback it then creates a constant force at
10// as a title would call it. No game data. 10// magnitude 1.0 on motor 0 and holds it for a second, which a wheel feels as a steady pull; a pad the shim reports no
11// force-feedback motor for is skipped with the reason shown. Everything goes through GameInputCreate from the shim
12// registry, as a title would call it. No game data.
11#include <windows.h> 13#include <windows.h>
12 14
13#include <cstdio> 15#include <cstdio>
@@ -61,16 +63,49 @@ void play(const char* what, GameInputRumbleParams p) {
61 Sleep(300); 63 Sleep(300);
62} 64}
63 65
66// A constant force at full magnitude on the pad's first motor, held for a second: the effect a wheel feels as a
67// steady pull. A pad SDL did not open as a haptic device reports no motor, and the step says so and moves on.
68void constant_force() {
69 for (IGameInputDevice* d : g_devices) {
70 const GameInputDeviceInfo* i = d->GetDeviceInfo();
71 if (i->forceFeedbackMotorCount == 0) {
72 std::printf("force feedback: %s reports no force-feedback motor; skipped\n",
73 i->displayName ? i->displayName->data : "?");
74 continue;
75 }
76 const auto* motor = static_cast<const GameInputForceFeedbackMotorInfo*>(i->forceFeedbackMotorInfo);
77 std::printf("force feedback: %u motor(s), motor 0 axes=0x%x constant=%d\n", i->forceFeedbackMotorCount,
78 motor ? static_cast<unsigned>(motor->supportedAxes) : 0u,
79 motor != nullptr && motor->isConstantEffectSupported);
80 GameInputForceFeedbackParams p{};
81 p.kind = GameInputForceFeedbackConstant;
82 p.data.constant.magnitude.linearX = 1.0f;
83 IGameInputForceFeedbackEffect* e = nullptr;
84 const HRESULT hr = d->CreateForceFeedbackEffect(0, &p, reinterpret_cast<void**>(&e));
85 if (FAILED(hr) || !e) {
86 std::printf("force feedback: CreateForceFeedbackEffect failed (0x%08lx)\n", static_cast<unsigned long>(hr));
87 continue;
88 }
89 std::printf("force feedback: constant linearX 1.0 on motor 0, 1 s\n");
90 e->SetState(GameInputFeedbackRunning);
91 Sleep(1000);
92 e->SetState(GameInputFeedbackStopped);
93 e->Release(); // the poll thread destroys the SDL effect
94 Sleep(300);
95 }
96}
97
64} // namespace 98} // namespace
65 99
66int main(int argc, char** argv) { 100int main(int argc, char** argv) {
67 int seconds = 10; 101 int seconds = 10;
68 bool rumble = false; 102 bool rumble = false, force_feedback = false;
69 for (int i = 1; i < argc; ++i) { 103 for (int i = 1; i < argc; ++i) {
70 if (!std::strcmp(argv[i], "--seconds") && i + 1 < argc) seconds = std::atoi(argv[++i]); 104 if (!std::strcmp(argv[i], "--seconds") && i + 1 < argc) seconds = std::atoi(argv[++i]);
71 else if (!std::strcmp(argv[i], "--rumble")) rumble = true; 105 else if (!std::strcmp(argv[i], "--rumble")) rumble = true;
106 else if (!std::strcmp(argv[i], "--force-feedback")) force_feedback = true;
72 else { 107 else {
73 std::printf("usage: gameinput_probe [--seconds N] [--rumble]\n"); 108 std::printf("usage: gameinput_probe [--seconds N] [--rumble] [--force-feedback]\n");
74 return 2; 109 return 2;
75 } 110 }
76 } 111 }
@@ -98,6 +133,8 @@ int main(int argc, char** argv) {
98 play("left trigger at 30%", {0, 0, 0.3f, 0}); 133 play("left trigger at 30%", {0, 0, 0.3f, 0});
99 } 134 }
100 135
136 if (force_feedback && !g_devices.empty()) constant_force();
137
101 const ULONGLONG end = GetTickCount64() + static_cast<ULONGLONG>(seconds) * 1000; 138 const ULONGLONG end = GetTickCount64() + static_cast<ULONGLONG>(seconds) * 1000;
102 while (GetTickCount64() < end) { 139 while (GetTickCount64() < end) {
103 IGameInputReading* r = nullptr; 140 IGameInputReading* r = nullptr;