feat(hid): warn on low controller battery and slow controller updates #3038
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3038
Loading…
Reference in a new issue
No description provided.
Delete branch "cfw34683/Longshot:feat/controller-battery-stall-warning"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
A controller on a dying battery, or a PC where reading the controllers keeps stalling, makes input lag with nothing on
screen to say why. This adds a read-only Controller health row to the Controls tab (Controller section, after the
Xbox rows, before Controller menu button) that says so, and a line in the log:
hos_sdl_pad_batteryreports it(the builder's pads included). Each pad is checked when it opens and every 30 s; each low pad is named once in the log.
SDL_UpdateGamepads, which serves every pad at once) took over 10 ms sixtimes within any 5 seconds. It clears after 15 s with no stall, and the log says so; a later run raises it again.
The row doesn't name a cause or a transport, since the timing can't tell a wireless link from a driver or a busy PC.
The row and its hints are translated into the menu's 13 languages. There is no on-screen toast: the renderer has no
translated text, and its UI is moving into mods (#3069), so a toast can come later from a mod.
Read first:
host/pad_health.h(the checks, pure C), the health block at the end ofpads_pollinhost/pad_sdl.c,then the
controller_healthrow ingame/mods/controls/mod.toml.LsRendererStatusgainspad_health, soLS_CAPS_LAYOUTmoves to 24 (C and its Rust mirror). No change tohost/hos_sdl.c: the battery is #3044'shos_sdl_pad_battery.See #2089 (input lag with stable FPS). Overlaps #1092 (a notice on low battery, connect and disconnect).
Testing
Tested: Windows 10 22H2, RTX 3070 Ti, on
22b733e20(maind6e819e08merged):dev.py smokePASS on the same build: in play fromkokiri-start, 900 frames, the Insert menu opened, every system mod started.mise run test(run_all.py --strict, 848 checks): 682 passed at first; 117 more had no tool on this PC (gcc,g++,glslang...). With MSYS2's gcc 16.2 and tools.lock's glslang on the PATH, 113 of those pass and 0 fail; 4 still need tools this PC lacks (test_coverage_runllvm-nm,test_lifterllvm-mc,test_fsr4_tunespirv-val,test_native_zstdzstandard). The other 49 fail the same way on cleanmaind6e819e08on this PC (all 49, none extra), none in this PR's area:the 49
- Linux (Ubuntu 26.04 under WSL 2, tools.lock's toolchain through `mise run tools`), ontest_game_font.py,test_seed_reader.py,test_capture_copy_helpers.py,test_report_words.py,test_jobs_wait_runs_queued.py,test_alt_enter.py,test_audio_deadline.py,test_audio_output_errors.py,test_audio_wave_buffer_release.py,test_bc_levels.py,test_bind_memo.py,test_collect_wide.py,test_dlss_actor.py,test_dlss_checks.py,test_dlss_math.py,test_draw_binds.py,test_fps_overlay_order.py,test_fps_rate.py,test_fps_stats.py,test_framegen_gate.py,test_fsr3_math.py,test_gpu_choice.py,test_helpers_extract.py,test_hle_guest_ranges.py,test_import_span.py,test_libc_hooks.py,test_longshot_builder.py,test_mirror_inherit.py,test_movie_upscale_policy.py,test_pass_hazard.py,test_pool_span.py,test_present_ahead.py,test_prof_clock.py,test_push_state.py,test_quick_pipelines.py,test_same_bind.py,test_same_draw.py,test_same_dyn.py,test_skip_code.py,test_sparse_bc_usage.py,test_status_line.py,test_submitted_page.py,test_table_track.py,test_tex_spans_once_a_present.py,test_texture_layout_sizes.py,test_ub_gap.py,test_upscale_independent.py,test_vertex_bind.py,test_wb_pages.py22b733e20: - `scripts/check_host_compile.py` for Linux, with `dev.py env`'s build environment: 83 host units, 0 failed. - `scripts/check_host_compile.py` for Windows as CI's host-windows job runs it (`RX_TARGET=windows RX_MARCH=x86-64-v3`, llvm-mingw's Linux build, tools.lock's windows-x64 headers and FFmpeg): 81 host units, 0 failed. - `cargo test -p host-sys -p api --lib`: 23 and 566 passed, 0 failed. - `mise run test` (`run_all.py --strict`): 885 passed, 2 failed, 13 skipped (Windows-only or a Vulkan device). The 2, `test_gfx_world` and `test_lifter`, fail the same way on clean `main`d6e819e08there. - `dev.py cargo -- test -p host-sys -p api --lib`: host-sys passes; api 565 of 566, `watch::tests::a_walked_reshade_folder_counts_a_change_once_two_walks_agree` failing on clean `main` too. - `longshot-builder mod test game/mods/menu` (this tree's builder): 73 of 74; "a held scroll, an open dropdown ... cost the script almost nothing a frame" fails on clean `main` too (2 of 74 there). - `test_pad_health` covers the battery threshold, the sliding window across a boundary, six stalls just over 5 s apart not counting, the 15 s recovery and a recurrence, and that no SDL power call bypasses the builder's pads.Still to test:
hid: "<pad>": low battery (<n>%)line (by hand).hid: SDL's controller update is quick again15 s after it stops (by hand).main(@Beanstalk open the Insert menu's Controls tab with a controller connected and screenshot it).Measurements
Nothing to measure: one
hos_now_ns()pair around the existingSDL_UpdateGamepadscall, a ring of six timestamps and a battery read per pad every 30 s; no draw, no allocation, no thread.Risks
LS_CAPS_LAYOUT24: a renderer and host from different commits refuse each other's status, as for every layout change.settings.tomlgains no key.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
tests/that reads changed source is updated, not weakened.mainand here, for a change that shows on screen.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Possibly related, for context:
3d6aa56b241a9fe824981a9fe82498eee639f20c32153408b9d2643ee30aRebased onto
main(0a68a1de) and pushedd2643ee3. CI hasn't run on this PR yet (every job shows blocked), so I ran the game-free checks locally. They found two things, fixed in their own commit,d2643ee3:test_ui_renderer:menu_record's "nothing shows: no painter's frame" gate had&& !toastadded to the line the test pins. The gate now keeps main's line, and the toast is checked inside it, soui::idle()is still skipped while the toast is up and its frame still begins.test_i18n_complete: the Controller health row's 11 texts are now in all 13 languages, with each language's existing word for the controller (Mando, Control, Manette, 手柄, 手把…). Native speakers, please correct any wording.Checked locally (Windows, tools.lock's llvm-mingw):
tests/run_all.py --changed origin/maingives 111 passed and 7 failed. The 7 (test_fps_overlay_order,test_cursor_hidden_linux,test_fps_stats,test_gpu_choice,test_fps_rate,test_input_background,test_gfx_world) fail the same way on cleanmainon this PC, so they're unrelated to this PR.A question for reviewers, which no test checks: the bottom-left toast draws its text straight from
vk_menu.cpp(draw_pad_health_toast), in hardcoded English. Its three messages can't be translated, and the wording differs from the Controller health row's. Since #3069 routes UI through mods, would you rather the toast go through the notice path a mod can show, or drop it and keep only the menu row? I'll change it whichever way you prefer.@review
Recommendation: Request changes. The warning can be missed at startup, remain active after polling recovers, and misidentify the controller or connection responsible. The status layout also changed without its required version bump.
Adds battery and polling warnings to the Controls menu and a temporary toast. The feature could help diagnose controller trouble, but its current state tracking and wording can mislead players.
Blocking (4): must change before merging.
game/settings_caps.h:151: The status layout changes without advancing LS_CAPS_LAYOUT. (more on the line) Do: Advance LS_CAPS_LAYOUT and its Rust mirror together so mismatched layouts are refused.host/pad_health.h:61: Once set, the stall flag never clears while any controller remains connected. (more on the line) Do: Expire the stall state after a suitable healthy interval and test recovery and a subsequent recurrence.gpu/vk/vk_menu.cpp:1700: A warning detected during startup can expire without ever being shown. (more on the line) Do: Queue the warning until it can be displayed, then start its display interval.game/mods/controls/mod.toml:281: The row attributes a slow SDL update to Bluetooth even though the measurement does not identify a transport or a particular controller. (more on the line) Do: Describe the observed SDL polling delay without asserting its cause or transport, unless those can be established independently.Should fix (5): not blocking, but worth doing before merging.
host/pad_sdl.c:889: Battery health is combined across every open pad, although the row says it describes the active controller. (more on the line) Do: Report the selected active pad's battery state, or identify the affected pad and make the row's scope explicit.host/pad_health.h:55: The stall counter uses fixed windows, not the promised sliding window. (more on the line) Do: Keep the recent stall timestamps and count those within the last five seconds; add a boundary-crossing test.gpu/vk/vk_menu.cpp:1668: The toast messages are hardcoded in English. (more on the line) Do: Send the notice through a translatable UI path and provide translations for its messages.game/mods/controls/mod.toml:276: The new Controls row is absent from the user settings table. (more on the line) Do: Add the row in menu order to docs/user/graphics-and-controls.md.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
@fixcan do L1, L2, L3, L4, L5, L6, L7, L8 and L9.Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven: the reported checks exercise the helper and source wiring, but no in-game run demonstrates the warning or its presentation.
Other systems: The SDL update is shared by all open controllers, including wired and virtual devices; its elapsed time also includes time the polling thread is descheduled. The new status crosses the host, renderer and Rust settings ABI. Windows and Linux controller behavior and the on-screen presentation have not been reported tested in game.
Switches: None.
Reviewed:
d2643ee30aagainst0a68a1dea8: Read the repository rules, PR template, standards, commit messages, changed host and renderer hunks, the new helper and test, and the surrounding polling and status paths. Skimmed translations and the Rust and menu declaration changes; did not read every changed code file in full. docs/review-checklist.md was absent.; nothing run (a code review).Checked and fine:
Testing: No commands from the project or tests were run, as requested. The author reports four targeted checks passing and seven broader checks failing identically on their clean base; CI is still running.
Overlaps and merge order: Not checked; network access is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -273,2 +273,4 @@place = { tab = "controls", section = "controller", order = 90 }[[settings]]id = "controller_health"L8 (should fix): The new Controls row is absent from the user settings table.
When: A player consulting the Controls reference cannot find Controller health or what its status means.
Do: Add the row in menu order to docs/user/graphics-and-controls.md.
@ -275,0 +278,4 @@{ when = "status.pad_health == 0", text = "OK" },{ when = "status.pad_health == 1", text = "Low battery" },{ when = "status.pad_health == 2", text = "Slow poll (Bluetooth)" },{ when = "status.pad_health == 3", text = "Low battery + slow poll" },L4 (blocking): The row attributes a slow SDL update to Bluetooth even though the measurement does not identify a transport or a particular controller.
When: Six slow updates with only a wired controller, or while the polling thread is descheduled, set the same flag and display “Slow poll (Bluetooth)” and a Bluetooth-specific explanation.
Do: Describe the observed SDL polling delay without asserting its cause or transport, unless those can be established independently.
@ -148,6 +148,7 @@ typedef struct LsRendererStatus {uint8_t render_thread; /* Threaded rendering as this run resolved it: bit 0 the render thread, bit 1 the recorder's */uint8_t hdr_native; /* the game presents in native HDR now: an HDR display, HDR set to Native (host/nn_vi.c) */uint8_t vibration; /* what plays the controller used last (menu_vibration_status_option) */uint8_t pad_health; /* controller health bitmask: 0 OK, 1 low battery, 2 poll stall (host/pad_health.h) */L1 (blocking): The status layout changes without advancing LS_CAPS_LAYOUT.
When: A renderer and host built against opposite sides of this change both accept layout 23, but interpret the bytes after vibration as different fields; for example, the old menu_open byte is read as pad_health.
Do: Advance LS_CAPS_LAYOUT and its Rust mirror together so mismatched layouts are refused.
@ -1653,0 +1665,4 @@void draw_pad_health_toast(ui::Ctx& c) {const int h = pad_health_cache.load(std::memory_order_relaxed);if (h <= 0) return;const char* msg = (h & 3) == 3 ? "Controller battery low & polling stalling — check batteries, firmware, or USB"L7 (should fix): The toast messages are hardcoded in English.
When: A player using any translated menu receives the warning in English even though the new Controls row has translations.
Do: Send the notice through a translatable UI path and provide translations for its messages.
@ -1669,13 +1697,19 @@ void menu_record(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h, inconst bool start = startup_on.load(std::memory_order_acquire);const bool open = open_now.load(std::memory_order_relaxed);const bool ui = ui_shown(); // ((longshot) UI's frame: something to draw, or textures to take)const bool toast = !start && pad_health_cache.load(std::memory_order_relaxed) > 0 &&L3 (blocking): A warning detected during startup can expire without ever being shown.
When: A low-battery controller is opened during a startup screen lasting at least seven seconds. The timer starts immediately, but the toast is suppressed while startup is active, and the unchanged health bit never starts it again.
Do: Queue the warning until it can be displayed, then start its display interval.
@ -0,0 +52,4 @@}return s->stalled;}if (!s->window_start_ns || now_ns - s->window_start_ns > PAD_HEALTH_STALL_WINDOW_NS) {L6 (should fix): The stall counter uses fixed windows, not the promised sliding window.
When: A stall at 0.1 seconds followed by six stalls between 4.9 and 5.1 seconds resets the counter at 5.1 seconds, so six stalls within five seconds do not trigger the warning.
Do: Keep the recent stall timestamps and count those within the last five seconds; add a boundary-crossing test.
@ -0,0 +58,4 @@} else {s->window_stalls++;}if (s->window_stalls >= PAD_HEALTH_STALL_COUNT) s->stalled = 1;L2 (blocking): Once set, the stall flag never clears while any controller remains connected.
When: After six slow polls, the player fixes the connection or switches to a healthy controller while another pad remains open. The Controls row still says polling is stalling, and a later recurrence cannot trigger a new toast.
Do: Expire the stall state after a suitable healthy interval and test recovery and a subsequent recurrence.
@ -859,0 +886,4 @@}low_bat |= pads[i].battery_low;}if (!any_pad) {L5 (should fix): Battery health is combined across every open pad, although the row says it describes the active controller.
When: An unused low-battery controller remains connected while the player uses a healthy one; the row and toast report low battery for the controller being used.
Do: Report the selected active pad's battery state, or identify the affected pad and make the row's scope explicit.
d2643ee30a49173c5369Rebased onto
main(45d1863b2) and pushed49173c536, answering BeanBot's review:LS_CAPS_LAYOUTis now 24, ingame/settings_caps.hand the Rust mirrorCAPS_LAYOUT.docs/user/graphics-and-controls.md, after DualSense HD Haptics.Also: the Controller health texts were still on Rust's
UNTRANSLATEDlist after being translated, whichrows_data_testsrefuses. They're off it now.feat(hid): warn on low controller battery and Bluetooth poll stallsto WIP: feat(hid): warn on low controller battery and Bluetooth poll stallsWIP: feat(hid): warn on low controller battery and Bluetooth poll stallsto WIP: feat(hid): warn on low controller battery and slow controller updatesMerged
main(d6e819e08) into the branch and pushed22b733e20. That merge resolves the conflicts with #3044 and the menu's new rows:hos_sdl_pad_battery_lowpassed the pad's handle straight to SDL, even when the builder serves the pads (game_builder_pads_remote), where that handle is the builder's. It's gone. The battery now comes from #3044'shos_sdl_pad_battery, which answers for both kinds of pad. Low means on its battery at 15% or less.host/hos_sdl.candhos_sdl.hare now unchanged frommain.menu.test.tsand the user docs' table are updated to match.Checks on the merge: the pad-health, menu, vibration, i18n and keyboard checks pass. The Rust and menu-mod tests pass apart from two that fail on clean
mainon this PC too; the description names them. The smoke run in game passed on the previous head. The Controls tab screenshot is still to take.Ran in game on
22b733e20(Windows 10, RTX 3070 Ti, a controller connected): Insert, Controls. Controller health sits after Xbox direct rumble and before Controller menu button, reads OK, and shows its help and hint. Screenshot attached.dev.py smokepasses on the same build, and the fullmise run testhas no failure of its own (the description names the 49 that fail on cleanmainon this PC too).A maintainer, please approve this PR's CI run: it waits on approval as a PR from a fork. Its Linux build settles the last box.
The same spot on
mainand here: Insert, Controls, the end of the Controller section, with the same controller connected.main(Nightly 1089,d6e819e08): Xbox direct rumble, then Controller menu button.22b733e20, thatmainmerged): Xbox direct rumble, then Controller health: OK, then Controller menu button.Built and checked on Linux (Ubuntu 26.04 under WSL 2, tools.lock's toolchain), on
22b733e20:check_host_compile.pywithdev.py env): 83 units, 0 failed.cargo test -p host-sys -p api: 23 and 566 passed.mise run test: 885 passed, 2 failed. The 2,test_gfx_worldandtest_lifter, fail the same way on cleanmaind6e819e08.Every box of Ready for review is settled, so this leaves WIP.
WIP: feat(hid): warn on low controller battery and slow controller updatesto feat(hid): warn on low controller battery and slow controller updates@rebase
I didn't rebase this pull request: it doesn't allow edits from maintainers (the author can turn on Allow edits from maintainers).
Automated rebase by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
Rebased onto latest
main(8c0beeec5) and ported status forwarding from the removedgpu/vk/vk_menu.cppto the new Rust device-status path (hos_pad_health_status()inhost/pad_sdl.c→host-sys→api::services::devices, matchinghos_vibration_status()with zerogpu/vk/edits).Verified
tests/test_pad_health.py(passed) anddev.py cargo -- test -p host-sys(7/7 passed, 0 warnings). (Allow edits from maintainers is also now enabled.)88c1d73ddc8c0beeec5df8bc686124f040848faaView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.