Repository navigation
feat: show the controller battery level - #160
Conversation
e737249 to
32b91ba
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes This review covers the controller battery feature from source polling through UI presentation, low-battery notices, localization, tests, and manual verification guidance.
- Battery sources and parsing Converts XInput, Windows.Gaming.Input, and Sony HID battery reports, combines readings, and chooses the emptiest reported controller.
- Indicators and warnings Adds battery indicators to the session menu and Console UI, plus threshold-based notices during active sessions.
- Tests and localization Adds pure-logic tests, translations in all six catalogs, and a manual hardware checklist.
gpt-6-luna | 𝕏
Reads the battery from Windows.Gaming.Input, XInput (approximate) and the DS4/DualSense HID reports, and shows the emptiest pad in the session menu header and the Console interface top bar, with a low-battery notice during a session. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
32b91ba to
07a11fc
Compare
There was a problem hiding this comment.
ℹ️ No critical issues — one minor diagnostics accuracy issue inline.
Reviewed changes This review covers the diagnostics report change since the prior Pullfrog review.
- Added controller battery details — Included each controller's last known battery reading in the diagnostics report.
gpt-6-luna | 𝕏
| ?? batteries.FirstOrDefault(b => b.Source == (raw.HardwareVendorId == ControllerMapping.SonyVendorId | ||
| ? ControllerBattery.SourceSony | ||
| : ControllerBattery.SourceXInput)); |
There was a problem hiding this comment.
When the ID match fails, this fallback can attach one controller's battery to a different row: Sony HID readings are keyed by HID path, while XInput readings are eligible for every non-Sony controller. In multi-pad setups the copied diagnostics report can therefore misidentify which controller has a low battery.
Technical details
# Avoid associating battery readings by source alone
## Affected sites
- `src/ConsoleMode/ViewModels/MainViewModel.Diagnostics.cs:120-124` — Source-only fallback removes the first reading of that source without proving it belongs to the current `RawGameController`.
- `src/ConsoleMode/Services/SonyHidReader.cs:144` — Sony battery IDs are HID device paths, not necessarily `RawGameController.NonRoamableId`.
- `src/ConsoleMode/Services/ControllerBatteryMonitor.cs:44-51` — XInput readings carry slot IDs, which are not tied to arbitrary non-Sony raw controllers.
## Required outcome
- Only include a battery detail when its reading can be associated with the specific controller row; leave the detail empty rather than report a potentially wrong controller battery.
What
Shows the battery of the connected controller(s) (issue #70):
SessionHintWindow, never takes focus). Warns once at <= 15 %, once more at <= 5 %, and re-arms only after charging (or a reading above 25 %, e.g. new batteries).With several pads it shows the emptiest one. Wired pads with no battery show nothing. "~" marks XInput's rough four-step level.
How
Services/ControllerBattery.cs(pure, unit-tested): XInput level mapping (5/30/65/100, approximate), WGIBatteryReportto percent, DS4/DualSense status byte parsing (offsets as in Linux hid-playstation: DS4 USB 30 / BT 0x11 32; DualSense USB 53 / BT 0x31 54; the short Bluetooth 0x01 report is ignored), combining sources (Sony HID wins for PlayStation pads, WGIRawGameController.TryGetBatteryReportfor the rest, XInput only when WGI reported no non-Sony pad), glyph choice (Segoe Fluent battery / charging glyphs) and theLowBatteryAlarmhysteresis.Services/ControllerBatteryMonitor.cs: reads the three sources;ControllerBatteryMonitor.Snapshot(IReadOnlyList<BatteryReading>) is the last result, for other screens (e.g. diagnostics).SonyHidReaderparses the battery byte at most every 5 s per pad (not on every report) and exposesReadBatteries().MainViewModel.Battery.cspolls every 30 s off the UI thread, plus on controller connect/disconnect and when the session menu opens.battery 80%/battery ~65%, chargingin its detail.docs/TESTING.md(1f).Testing
dotnet test tests/ConsoleMode.Tests/ConsoleMode.Tests.csproj: 473 passed (newControllerBatteryTests).Closes #70
🤖 Generated with Claude Code