Skip to content

Sync Brick Fn actions and the volume keys with spruce state#1549

Open
Felixmil wants to merge 9 commits into
spruceUI:mainfrom
Felixmil:brick-fnkey-backlight
Open

Sync Brick Fn actions and the volume keys with spruce state#1549
Felixmil wants to merge 9 commits into
spruceUI:mainfrom
Felixmil:brick-fnkey-backlight

Conversation

@Felixmil

@Felixmil Felixmil commented Jun 5, 2026

Copy link
Copy Markdown

The TrimUI Brick "Fn Key and Switch Settings" actions are stock scripts that write to firmware sinks spruce does not use, so their effects did not stay in sync with spruce's own state. This reworks three of those actions to go through spruce's own helpers, so the hardware, the stored value, and the in-UI sliders all move together. It also stops the audio actions from triggering the stock volume popup, which was redundant with the switch's own on-screen toast, and adds a watcher so the in-UI volume bar follows the physical volume keys.

Backlight action

The "LCD brightness switcher" action wrote the new level to /tmp/system/set_brightness for the stock hardwareservice to apply, which spruce does not consume, so the brightness slider and stored value did not follow the key. It now sources helperFunctions.sh and cycles the backlight with spruce's current_backlight / set_backlight, stepping through 1, 4, 7, 10 and wrapping back to 1. Because set_backlight records the value spruce reads elsewhere, the UI slider updates in step.

Silent Mode action

Silent Mode hard-muted the speaker via /sys/class/speaker/mute but never told spruce, so the in-UI volume value stayed at its old level while muted. It now also drops the volume to 0 through spruce's set_volume on enter (so the volume value reflects the mute) and restores the prior volume on exit. The speaker hard-mute is kept as a backstop.

Quiet Mode action

Quiet Mode poked an ALSA mixer control directly (tinymix set 9 N), which spruce neither reads nor respects, so nothing audible changed and the volume slider stayed wrong. It now lowers the volume to a low but audible level through spruce's set_volume on enter, saving the current volume first, and restores that saved volume on exit, mirroring the Silent Mode approach.

Volume popup suppression

In game (when MainUI is not running) set_volume shows the stock volume OSD popup. When Silent or Quiet was toggled by the switch this popped up alongside the switch's own toast, which was redundant. set_volume gains an optional third argument that controls the popup (defaulting to shown, so every existing caller is unchanged), and the Silent and Quiet actions opt out of it. The physical volume keys still show their popup as before.

Volume key sync

The physical Volume +/- keys are handled entirely by the stock firmware, which adjusts the audio and writes the new level to /tmp/system/set_volume on every key event (autorepeat included). spruce never read that file back, so its stored volume (.vol) only changed when spruce itself set the volume. Since the in-UI volume bar reads .vol, holding a volume key moved the audio but the bar updated once at most and never ramped. A small watchdog (spruce/brick/volume_sync_watchdog.sh) now polls /tmp/system/set_volume and mirrors the value into spruce's volume through set_volume (config only, with the popup suppressed because the firmware already draws its own), so the bar tracks the hardware keys including while held. It is started from device_init_a133p and stopped on shutdown alongside the other watchdogs.

Notes

These changes are independent of the daemon that dispatches Fn key presses (see #1548, which starts keymon); they only change what the actions do when they run. The Fn key and switch actions in this PR only reach users once keymon is also started, but the volume key sync is independent of keymon and works on its own. The volume sync watcher is launched next to the line #1548 adds to device_init_a133p, so merging the two produces a one-line conflict that is resolved by keeping both lines. #1550 edits a different part of the same file (the runtime mounts) and merges independently.

Validated on a physical Brick (FW 1.1.1): the backlight cycle runs 1 → 4 → 7 → 10 → 1 with the stored value updating each step, Silent Mode drops the volume value to 0 on enter and restores the previous level on exit, Quiet Mode drops the volume to a low level on enter and restores the previous level on exit, in game the switch no longer shows the stock volume popup for Silent or Quiet while the volume keys still do, and holding the Volume +/- keys now ramps the in-UI volume bar smoothly in sync with the audio.

Felixmil added 2 commits June 5, 2026 09:17
- com.trimui.switch.backlight.sh:
  - source helperFunctions and cycle via spruce set_backlight / current_backlight
  - cycle levels 1, 4, 7, 10 then wrap, keeping hardware, stored value and UI slider in sync
  - drop the stock /tmp/system/set_brightness path that spruce does not honor
- com.trimui.silent.sh:
  - source helperFunctions and drop volume to 0 via spruce set_volume on enter, so the in-UI volume value reflects the mute
  - save the prior volume and restore it via set_volume on exit
  - keep the speaker hard-mute as a backstop
@Felixmil Felixmil changed the title Make Brick Fn backlight action use spruce's own backlight control Sync Brick Fn backlight and Silent Mode actions with spruce state Jun 5, 2026
- App/fn_editor/com.trimui.quiet.sh:
  - source spruce helperFunctions for set_volume / get_volume_level
  - on enter, save the current volume then set spruce volume to a low level
  - on exit, restore the saved volume and clean up the temp file
  - drop the tinymix mixer pokes that spruce did not read or respect
@Felixmil Felixmil changed the title Sync Brick Fn backlight and Silent Mode actions with spruce state Sync Brick Fn backlight, Silent and Quiet actions with spruce state Jun 5, 2026
Felixmil added 2 commits June 5, 2026 11:48
- spruce/scripts/platform/device_functions/trimui_a133p.sh:
  - add an optional SHOW_OSD third arg to set_volume (defaults to true)
  - only show the stock volume popup when SHOW_OSD is true
- App/fn_editor/com.trimui.silent.sh:
  - pass "true false" to set_volume so the config syncs without the popup
- App/fn_editor/com.trimui.quiet.sh:
  - pass "true false" to set_volume so the config syncs without the popup
- spruce/brick/volume_sync_watchdog.sh:
  - add a watcher that polls /tmp/system/set_volume and mirrors the value into spruce's stored volume via set_volume (config only, OSD suppressed) so the in-UI volume bar tracks the hardware Volume +/- keys, including while held
- spruce/scripts/platform/device_functions/trimui_a133p.sh:
  - launch volume_sync_watchdog.sh from device_init_a133p
- spruce/scripts/save_poweroff.sh:
  - kill volume_sync_watchdog.sh during shutdown alongside the other watchdogs
@Felixmil Felixmil changed the title Sync Brick Fn backlight, Silent and Quiet actions with spruce state Sync Brick Fn actions and the volume keys with spruce state Jun 5, 2026
Felixmil added 4 commits June 5, 2026 15:32
- volume_sync_watchdog.sh:
  - add unmute_if_raised() to clear the speaker amp mute and the muted marker when a non-zero volume arrives
  - call unmute_if_raised on each observed volume change so volume-up lifts Silent Mode's hard mute without flipping the switch
- trimui_a133p.sh:
  - remove the volume_sync_watchdog launch from device_init_a133p, where the bare background job started during early-boot churn and did not survive
  - add a launch_startup_watchdogs override that runs the common watchdogs then starts volume_sync_watchdog alongside them, pinned to the system CPU like its siblings
…nfig

- volume_sync_watchdog.sh:
  - react to /tmp/system/set_volume via inotifywait instead of a 150ms poll, so the bar tracks held volume keys without the sampling delay
  - mirror only into SYSTEM_JSON (the file PyUI polls) and drop the set_volume call, since the firmware already owns the durable /mnt/UDISK copy and ALSA; this removes a redundant synchronous flash write from each ramp step
  - keep the Silent Mode unmute and add a polling fallback for when inotifywait is unavailable
- trim_ui_brick.py:
  - lower the system-config FileWatcher interval from 0.2s to 0.05s so the volume bar redraws within ~50ms of the volume sync watchdog mirroring a new level, instead of trailing by up to 200ms while a key is held
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