Skip to content

Studio: a battery layer never updated on a wireless device - #93

Merged
infinityInfinite merged 1 commit into
infinityInfinite:mainfrom
a3k7dotmd:studio-battery-wireless-tick
Nov 21, 2026
Merged

infinityInfinite merged 1 commit into
infinityInfinite:mainfrom
a3k7dotmd:studio-battery-wireless-tick

Conversation

@a3k7dotmd

Copy link
Copy Markdown
Contributor

Found a bug in RGB Studio's battery layer: on my wireless keyboard the bar never moved. Text below and fix is by Fable 5.2 reviewed by GPT-6.2 Astra.

Problem

A battery layer on a wireless device keeps showing the level it had when its stream started. On my DeathStalker V2 Pro (Wireless) the bar on the top row stood below 40 % (orange, up to F6) for hours while secbird info said Battery 100%.

Cause

Studio::tick reads the battery on tick 1 of every BATTERY_EVERY (1800). A wireless device whose stream has started is skipped on every tick that isn't a multiple of WIRELESS_EVERY (3), and that check comes first:

(r.wireless, r.scene.animated(), r.last.is_some(), r.scene.uses(Kind::Battery) && (tick % BATTERY_EVERY == 1 || r.battery.is_none()))
...
if wireless && started && !tick.is_multiple_of(WIRELESS_EVERY) {
    continue;
}

1800 is a multiple of 3, so a tick with tick % 1800 == 1 is never a multiple of 3. While the stream runs and a level is noted, the read doesn't happen again. The level only changes when a stream starts without one: at tray start, or when the device comes back after being gone.

Fix

  • The battery's turn is tick 3 of the 1800 (BATTERY_TICK = WIRELESS_EVERY), a tick wireless devices get. Wired devices are read as often as before, two ticks later.
  • A const assertion keeps the turn on such a tick if the numbers change.
  • A test runs Studio::tick on the simulated wireless mouse: a started stream with 75 % noted, the battery full since. The level must still be 75 % after ticks 1801 and 1802, and 100 % after 1803. With the old schedule in the loop it fails with left: (1803, Some(75)), right: (1803, Some(100)).

Tested

  • Setup: Windows 11 26H2, 20 Nov 2026. DeathStalker V2 Pro (Wireless, 0290) on its receiver, a scene with a static layer and a battery layer on the top row.
  • Build: main with Tray: keep looking for a wireless device after its receiver comes back (dock reconnect, replaces #84) #92 and this change, cross-built on Linux for x86_64-pc-windows-gnu (rustc 1.100.0, mingw-w64). Only secbird-tray.exe was replaced.
  • Reads on the keyboard. A build with one more log line at the read (not part of this change) wrote:
    2026-11-21 01:31:56Z DEBUG studio battery read: Some(100) at tick 1
    2026-11-21 01:31:56Z DEBUG studio battery read: Some(100) at tick 3
    2026-11-21 01:33:21Z DEBUG studio battery read: Some(100) at tick 1803
    2026-11-21 01:34:45Z DEBUG studio battery read: Some(100) at tick 3603
    2026-11-21 01:36:10Z DEBUG studio battery read: Some(100) at tick 5403
    
    1800 ticks take about 85 s on this PC.
  • Checks on this branch: cargo clippy --release --target x86_64-pc-windows-gnu --all-targets -- -D warnings is clean. Unit tests: 6 (tray) pass on Windows, 128 (core) and 1 (CLI) pass on Linux.

…runs

A battery layer on a wireless device kept showing the level it had when
its stream started: on a DeathStalker V2 Pro (Wireless) the bar stood
below 40 % for hours while the keyboard reported 100 %.

The level is read once every 1800 ticks, and it was read on tick 1 of
them. A wireless device whose stream has started is only served on every
third tick, and that check comes first. 1800 is a multiple of 3, so tick 1
is never one of those and the read did not run again.

- The battery's turn is tick 3 of the 1800 (BATTERY_TICK), a tick wireless
  devices get. Wired devices are read as often as before, two ticks later.
- A const assertion keeps the turn on such a tick if the numbers change.
- A test runs Studio::tick on the simulated wireless mouse: a started
  stream with 75 % noted, the battery full since. The level is still 75 %
  after ticks 1801 and 1802 and 100 % after 1803. With the old schedule it
  stays 75 %.
@infinityInfinite
infinityInfinite merged commit fd08837 into infinityInfinite:main Nov 21, 2026
3 checks passed
@infinityInfinite

Copy link
Copy Markdown
Owner

Merged, thanks. Your test fails on the old schedule ((1803, Some(75))) and passes with the fix, and the const assert keeps the read on a tick wireless devices get. In 0.6.1.

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.

2 participants