Skip to content

The battery's charge and charging show in the status bar - #43

Merged
finger563 merged 1 commit into
mainfrom
fix/battery-status-bar
Nov 26, 2026
Merged

finger563 merged 1 commit into
mainfrom
fix/battery-status-bar

Conversation

@finger563

Copy link
Copy Markdown
Contributor

Summary

The launcher's status bar always read "--%", and the pause menu 0%: nothing ever read the battery.

  • The cache was never refreshed. The BSP reads the INA226 only in read_battery_status(). Tab5Emu::battery_status() returns the BSP's cache (get_battery_status()), which initialize_battery_monitoring() zeroes and nothing refreshed afterwards.
  • The topic was never published. The launcher (Gui::on_battery) waits for battery_topic, but nothing published it.

Changes

  • A battery task. Tab5Emu::initialize_battery() starts it, with a 4 KB stack in PSRAM at priority 1.
    • Every 2 s it calls read_battery_status(), which also refreshes the cache that battery_status() returns.
    • It publishes battery_topic only when what the UI shows changes: the percent, charging, or whether a pack is in the bay. It logs each change, e.g. battery: 99%, charging (8.38 V, -502 mA).
  • LVGL stays on the GUI's own task. Gui::on_battery now only marks the reading new, and Gui::update() applies it. The pause menu runs LVGL on its own task, so touching the launcher from the event task could race it.
    • The flag starts set, so the launcher shows the battery from its first update, even when the first publish comes before the Gui subscribes. (initialize_battery() runs before the Gui is constructed in main.cpp.)
  • No pack in the bay. When is_present is false (running from USB), the launcher and the pause menu show "--%" instead of an empty battery.

Testing (Tab5, audio muted)

  • Launcher: 99% with the charging symbol, from the first reading (8.38 V, -502 mA).
  • The log followed the hardware:
    • 96% and 95% at 0 mA while a NES game ran;
    • 99% charging again once it paused;
    • then back and forth as charging paused and resumed.
  • Pause menu: it reads the same refreshed battery_status() cache. It couldn't be screenshot, because emulink refuses screenshots while the menu is open.
  • Memory: back to the boot value after quitting the game. Internal RAM is unaffected, since the task's stack is in PSRAM.

Notes

  • The charge estimate jumps between about 95% and 99%. That's the BSP's own estimate from the pack voltage (update_battery_status, which calls itself a rough placeholder), and the voltage rises under charge. The BSP also pauses charging while audio plays (update_charging_for_audio), even with audio muted. A steadier figure needs the BSP to allow for the charge current; that's not in this PR.
  • Gui::on_volume has the same LVGL-from-the-event-task pattern this avoids for the battery. It's untouched here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY

The launcher's status bar always read "--%" and the pause menu 0%. The BSP
reads the INA226 only in read_battery_status(); Tab5Emu::battery_status()
returns its cache, which nothing refreshed after initialize_battery_monitoring()
zeroed it. The launcher waits for battery_topic, but nothing published it.

- Tab5Emu::initialize_battery() starts a battery task (4 KB stack in PSRAM,
  priority 1). Every 2 s it reads the battery and publishes battery_topic
  when what the UI shows changes: the percent, charging, or whether a pack
  is in the bay. It logs each change.
- Gui::on_battery only marks the reading new; Gui::update() applies it on
  the GUI's own task, so LVGL isn't touched from the event task while the
  pause menu runs LVGL on its own. The flag starts set, so the launcher
  shows the battery from its first update, even if the first publish came
  before the Gui subscribed.
- With no pack in the bay (is_present false: running from USB), the
  launcher and the pause menu show "--%", not an empty battery.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY
@finger563
finger563 merged commit b62d988 into main Nov 26, 2026
1 check passed
@finger563
finger563 deleted the fix/battery-status-bar branch November 26, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant