Skip to content

Studio: put a wireless keyboard back on its frame when it answers the battery read - #100

Open
a3k7dotmd wants to merge 1 commit into
infinityInfinite:mainfrom
a3k7dotmd:studio-wireless-frame-refresh
Open

a3k7dotmd wants to merge 1 commit into
infinityInfinite:mainfrom
a3k7dotmd:studio-wireless-frame-refresh

Conversation

@a3k7dotmd

Copy link
Copy Markdown
Contributor

One more thing with the battery layer on my wireless keyboard: after the keyboard was switched off and on it shows its own lighting while the tray keeps streaming, and the bar is gone until the next lock. Text below and fix is by Fable 5.2 reviewed by GPT-6.2 Astra. Tested on my keyboard.

Problem

A DeathStalker V2 Pro (Wireless) with a scene of a static layer and a battery layer on the top row showed the whole top row green while it was at 15 % (secbird info, and the tray's own low battery warning three minutes earlier). At 15 % the bar is two keys in red-orange.

  • The drawing on the RGB Studio page showed the right bar, so the tray had the level and was streaming that frame.
  • After a lock and unlock the keyboard showed it too.

So the keyboard had gone back to its own saved lighting, green on every key in this profile, while the stream ran. One way to get there: switch the keyboard off for two minutes and on again, with the PC unlocked. It comes up on its own lighting.

Cause

A wireless device gets only the rows that changed, without reading the replies, and the custom-frame effect only from show_frame when a stream starts. Wired keyboards get the whole frame every 3 s (RESEND_EVERY, #45); wireless ones are left out so the traffic doesn't keep them awake. Once a wireless keyboard has left the effect, rows alone change nothing it shows, and nothing tells the tray.

Fix

One change in Studio::tick:

  • When a wireless device whose scene uses a battery layer has just answered the battery read, its stream starts over on that tick: start_stream, with replies, the same path as after a lock. The device is awake then, and the radio is in use for the read anyway.
  • A device that doesn't answer the read is left alone and counts no failure. Wireless scenes without a battery layer are as they were, and so are wired devices.
  • Why with replies: a first version sent the six rows and the effect without waiting for them, as stream does. On the keyboard about two of the six rows got lost each time. That shows nothing while the keyboard's frame is complete, and as dark rows after it was switched off and on.
  • What it takes: 45 to 47 ms on the tick the battery is read, once every 1800 ticks (85 s on my PC).

New tests

All run Studio::tick on the simulated keyboard, opened as a wireless one at 50 %:

  • a_wireless_keyboard_gets_its_whole_frame_again: a static and a battery layer, the keyboard set back to its own effect. Nothing is sent on ticks 1801 and 1802; six rows, then the effect on 1803; nothing on 1804 to 1806.
  • a_still_wireless_scene_is_left_alone: the same without a battery layer, nothing is sent.
  • a_wireless_keyboard_that_does_not_answer_is_left_alone: no battery answer, so no frame is sent, the stream stays as it is and no failure is counted.
  • a_refused_row_ends_the_refresh_as_a_failed_frame: the keyboard refuses a row; the start stops there, sends no effect and counts one failed frame. A start that doesn't read replies would run on.

Tested

  • Setup: Windows 11 26H2, 29 Nov 2026. DeathStalker V2 Pro (Wireless, 0290) on its receiver, a scene with a static layer and a battery layer on the top row, Synapse not installed.
  • Build: 0.6.1 with this change, cross-built on Linux for x86_64-pc-windows-gnu (rustc 1.100.0, mingw-w64). Only secbird-tray.exe was replaced.
  • Keyboard switched off for two minutes and on, PC unlocked. A build with log lines at these steps (not part of this change) wrote:
    2026-11-30 04:32:33Z DEBUG studio: refresh (stream started over) ok in 45 ms, battery Some(55), failures before 0
    2026-11-30 04:33:57Z DEBUG studio: battery read got no answer, no refresh
    2026-11-30 04:35:22Z DEBUG studio: battery read got no answer, no refresh
    2026-11-30 04:36:46Z DEBUG studio: refresh (stream started over) ok in 47 ms, battery Some(56), failures before 0
    
    The keyboard came up on its own lighting, and after the last line it showed the whole scene again: the bar on the top row and every other row lit.
  • Checks: cargo clippy --release --target x86_64-pc-windows-gnu --all-targets -- -D warnings is clean. Unit tests: 132 (core) and 1 (CLI) pass on Linux, 12 (tray) pass on Windows. node --test crates/secbird-tray/tests/*.test.cjs passes.

…tery read

A DeathStalker V2 Pro (Wireless) showed its own saved lighting, green on
every key, while the tray kept streaming a scene with a battery bar at
15 %. The editor's drawing had the right bar; a lock and unlock put the
keyboard right, because a stream then starts with a whole frame.

A wireless device only gets the rows that changed, without reading the
replies, and the custom-frame effect only when a stream starts. A keyboard
that was switched off and on comes up on its own lighting; rows alone
change nothing it shows then, and nothing tells the tray.

- When a wireless device whose scene shows its battery has just answered
  the battery read, its stream starts over there and then (start_stream,
  with replies, as after a lock). The device is awake, and the radio is in
  use for that read anyway.
- A device that doesn't answer the read is left alone and counts no
  failure. Wireless scenes without a battery layer and wired devices are
  as they were.
- Tests run Studio::tick on the simulated keyboard as a wireless one: the
  whole frame and the effect again on the battery's tick, nothing for a
  still scene, nothing for a keyboard that doesn't answer, and a refused
  row ends the refresh as a failed frame.

On the keyboard: switched off for two minutes and on, it came up on its
own lighting and had the whole frame back at the next battery read, in
47 ms. A first version sent the rows without waiting for replies; two of
the six got lost and stayed dark.

This branch has not been deployed

No deployments
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