diff options
| author | mrbrinker <41247403+mrbrinker@users.noreply.github.com> | 2026-11-24 08:34:25 +1100 |
|---|---|---|
| committer | mrbrinker <41247403+mrbrinker@users.noreply.github.com> | 2026-11-24 08:34:25 +1100 |
| commit | 52b4f03b78e814f803d4a93c434c326c6698255c (patch) | |
| tree | d46e25b86e0d68c6f59bb88e7505bbaee7182f80 /runtime/test/gameinput_test.cpp | |
| parent | e66bf242e2edb82a24ab83e618d943d1c5ca737f (diff) | |
GameInput: honor the delay between trigger haptic pulses
Diffstat (limited to 'runtime/test/gameinput_test.cpp')
| -rw-r--r-- | runtime/test/gameinput_test.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index 3e6b4b309..df0a7f919 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp | |||
| @@ -1555,6 +1555,8 @@ void test_haptic_motors(IGameInput* input) { | |||
| 1555 | motors[0].waveformInfo != nullptr && motors[0].waveformInfo->isIntensitySupported, | 1555 | motors[0].waveformInfo != nullptr && motors[0].waveformInfo->isIntensitySupported, |
| 1556 | "haptics: they are the left and right trigger, one waveform each, an intensity"); | 1556 | "haptics: they are the left and right trigger, one waveform each, an intensity"); |
| 1557 | check(sticks_at_rest(pad_state(input, dev)), "haptics: the pad still reads normally"); | 1557 | check(sticks_at_rest(pad_state(input, dev)), "haptics: the pad still reads normally"); |
| 1558 | check(motors[0].waveformInfo->isRepeatDelaySupported && motors[1].waveformInfo->isRepeatDelaySupported, | ||
| 1559 | "haptics: both waveforms advertise repeat delay"); | ||
| 1558 | 1560 | ||
| 1559 | GameInputHapticFeedbackParams p{}; | 1561 | GameInputHapticFeedbackParams p{}; |
| 1560 | p.intensity = 0.5f; | 1562 | p.intensity = 0.5f; |
| @@ -1620,6 +1622,40 @@ void test_haptic_motors(IGameInput* input) { | |||
| 1620 | rt::gameinput::poll(); | 1622 | rt::gameinput::poll(); |
| 1621 | check(xbox.left == 0 && xbox.right == 0, "haptics: both long requests stop when the state is cleared"); | 1623 | check(xbox.left == 0 && xbox.right == 0, "haptics: both long requests stop when the state is cleared"); |
| 1622 | 1624 | ||
| 1625 | // Observe the output at the virtual pad. The left pulse plays twice over ordinary rumble; the right repeats | ||
| 1626 | // until stopped. Poll for each transition so the test need not wake on an exact millisecond boundary. | ||
| 1627 | dev->SetRumbleState(&rumble); | ||
| 1628 | p.duration = 120'000; | ||
| 1629 | p.repeatDelay = 180'000; | ||
| 1630 | p.playCount = 2; | ||
| 1631 | dev->SetHapticMotorState(0, &p); | ||
| 1632 | p.playCount = 0; | ||
| 1633 | dev->SetHapticMotorState(1, &p); | ||
| 1634 | auto reaches = [&](uint16_t left, uint16_t right) { | ||
| 1635 | const uint64_t deadline = input->GetCurrentTimestamp() + 900'000; | ||
| 1636 | do { | ||
| 1637 | rt::gameinput::poll(); | ||
| 1638 | if (xbox.left == left && xbox.right == right) return true; | ||
| 1639 | Sleep(5); | ||
| 1640 | } while (input->GetCurrentTimestamp() < deadline); | ||
| 1641 | return false; | ||
| 1642 | }; | ||
| 1643 | check(reaches(65535, 65535), "haptics: both pulse trains start at full intensity"); | ||
| 1644 | check(reaches(16384, 0), "haptics: only ordinary rumble remains between pulses"); | ||
| 1645 | check(reaches(65535, 65535), "haptics: both motors resume for the second pulse"); | ||
| 1646 | check(reaches(16384, 0), "haptics: both motors release after the second pulse"); | ||
| 1647 | check(reaches(16384, 65535), "haptics: only the indefinitely repeating motor starts a third pulse"); | ||
| 1648 | dev->SetHapticMotorState(1, nullptr); | ||
| 1649 | dev->SetRumbleState(nullptr); | ||
| 1650 | check(reaches(0, 0), "haptics: cancelling the repeating waveform releases the trigger"); | ||
| 1651 | |||
| 1652 | p.duration = 80'000; | ||
| 1653 | p.repeatDelay = UINT64_MAX - p.duration + 1; // duration + delay would wrap to zero | ||
| 1654 | dev->SetHapticMotorState(0, &p); | ||
| 1655 | check(reaches(65535, 0), "haptics: an indefinitely repeated pulse accepts a very long delay"); | ||
| 1656 | check(reaches(0, 0), "haptics: the motor enters the quiet interval even if the cycle exceeds UINT64_MAX"); | ||
| 1657 | dev->SetHapticMotorState(0, nullptr); | ||
| 1658 | |||
| 1623 | detach(xbox); | 1659 | detach(xbox); |
| 1624 | rt::gameinput::poll(); | 1660 | rt::gameinput::poll(); |
| 1625 | check(rt::gameinput::connected_count() == 0, "haptics: detached"); | 1661 | check(rt::gameinput::connected_count() == 0, "haptics: detached"); |