From ef77defbfe444c4ab06d5c8c01ce4cfd460238be Mon Sep 17 00:00:00 2001 From: Felix MIL Date: Tue, 7 Jul 2026 09:22:49 +0200 Subject: [PATCH 1/2] Dispatch Brick Fn keys with a spruce-native watchdog - spruce/brick/fnkey_watchdog.sh: - new watchdog that reads Fn key-down events via getevent and runs the action mapped in /usr/trimui/fnkeys/f1key_launch and f2key_launch - spruce/scripts/platform/device_functions/trimui_a133p.sh: - add launch_startup_watchdogs to launch and pin the Fn key watchdog alongside the common watchdogs --- spruce/brick/fnkey_watchdog.sh | 63 +++++++++++++++++++ .../platform/device_functions/trimui_a133p.sh | 11 ++++ 2 files changed, 74 insertions(+) create mode 100755 spruce/brick/fnkey_watchdog.sh diff --git a/spruce/brick/fnkey_watchdog.sh b/spruce/brick/fnkey_watchdog.sh new file mode 100755 index 000000000..b2d2d33f6 --- /dev/null +++ b/spruce/brick/fnkey_watchdog.sh @@ -0,0 +1,63 @@ +#!/bin/sh +# Dispatch the Brick's two Fn keys by running the action the user picked in the +# "Fn Key and Switch Settings" editor. +# +# On stock firmware the TrimUI keymon daemon reads the editor's per-key mapping +# and runs the chosen action on each Fn press. spruce deliberately does not run +# keymon (it replaced keymon everywhere with its own getevent watchdogs), so the +# Fn keys did nothing. This watchdog is the spruce-native replacement for that +# one job: watch the input node, and on an Fn key-down run the mapped action. +# +# Data model (all owned by the editor, /usr/trimui/apps/fn_editor/fneditor): +# /usr/trimui/fnkeys/f1key_launch - one line, absolute path to the left Fn action +# /usr/trimui/fnkeys/f2key_launch - one line, absolute path to the right Fn action +# The launch files are re-read on every press, so remapping in the editor takes +# effect immediately with no restart. An unmapped key has no launch file and is +# simply ignored. +# +# The action scripts are stateless togglers invoked with no argument (e.g. +# com.trimui.toggle.ledc.sh flips the LED, com.trimui.switch.backlight.sh cycles +# brightness), so this watchdog just executes the launch path as-is, exactly as +# keymon did. +# +# Key codes: on the Brick the left/right Fn keys report as $B_L3 (1 317) and +# $B_R3 (1 318) on $EVENT_PATH_READ_INPUTS_SPRUCE (event3). The Brick has no +# analog sticks, so 317/318 are exclusively the Fn keys here (the B_L3/B_R3 +# naming is inherited from the shared TrimUI config). The node is read +# non-exclusively, alongside the home/buttons watchdogs that already read it. + +. /mnt/SDCARD/spruce/scripts/helperFunctions.sh + +F1_LAUNCH="/usr/trimui/fnkeys/f1key_launch" +F2_LAUNCH="/usr/trimui/fnkeys/f2key_launch" + +# Run the action named in a *key_launch file, if it points at a runnable script. +# Backgrounded so a slow action never blocks the next keypress. +run_fnkey() { + launch_file="$1" + which_key="$2" + [ -r "$launch_file" ] || return 0 # key unmapped: nothing to do + action=$(cat "$launch_file" 2>/dev/null) + [ -n "$action" ] || return 0 # empty mapping + if [ ! -x "$action" ]; then + log_message "fnkey_watchdog.sh: $which_key Fn action not executable: $action" + return 0 + fi + log_message "fnkey_watchdog.sh: $which_key Fn -> $action" + "$action" & +} + +log_message "fnkey_watchdog.sh: Started up." + +# Outer loop restarts the reader if the getevent pipe ever exits, so the +# watchdog stays durable like its siblings. -pid $$ makes getevent exit with us. +while true; do + getevent -pid $$ "$EVENT_PATH_READ_INPUTS_SPRUCE" | while read line; do + case $line in + *"key $B_L3 1"*) run_fnkey "$F1_LAUNCH" left ;; + *"key $B_R3 1"*) run_fnkey "$F2_LAUNCH" right ;; + esac + done + log_message "fnkey_watchdog.sh: getevent pipe exited, restarting..." + sleep 1 +done diff --git a/spruce/scripts/platform/device_functions/trimui_a133p.sh b/spruce/scripts/platform/device_functions/trimui_a133p.sh index 87419719c..0e259edfc 100644 --- a/spruce/scripts/platform/device_functions/trimui_a133p.sh +++ b/spruce/scripts/platform/device_functions/trimui_a133p.sh @@ -192,6 +192,17 @@ device_init_a133p() { ) & } +launch_startup_watchdogs() { + launch_common_startup_watchdogs_v2 + + # Dispatch the Brick's Fn keys (spruce does not run the stock keymon that + # would otherwise do this). Launched here so it lives alongside the other + # durable watchdogs and survives the early-boot churn; pinned like them. + /mnt/SDCARD/spruce/brick/fnkey_watchdog.sh & + SYSTEM_CPU=${DEVICE_MAX_CORES_ONLINE%"${DEVICE_MAX_CORES_ONLINE#?}"} + pin_cpu "$SYSTEM_CPU" -n fnkey_watchdog.sh & +} + set_event_arg_for_idlemon() { log_message "nothing to do" -v } From 35a7c1271379ae94c8195cb972c43c882d4c4744 Mon Sep 17 00:00:00 2001 From: Felix MIL Date: Tue, 7 Jul 2026 09:29:27 +0200 Subject: [PATCH 2/2] Move the Fn key watchdog launch into Brick.sh - spruce/scripts/platform/device_functions/trimui_a133p.sh: - drop the Brick-only launch_startup_watchdogs from the shared A133P base - spruce/scripts/platform/device_functions/Brick.sh: - add launch_startup_watchdogs to launch and pin the Fn key watchdog --- spruce/scripts/platform/device_functions/Brick.sh | 11 +++++++++++ .../scripts/platform/device_functions/trimui_a133p.sh | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/spruce/scripts/platform/device_functions/Brick.sh b/spruce/scripts/platform/device_functions/Brick.sh index adfc3ffc9..095a8d178 100644 --- a/spruce/scripts/platform/device_functions/Brick.sh +++ b/spruce/scripts/platform/device_functions/Brick.sh @@ -36,4 +36,15 @@ device_init() { cp /mnt/SDCARD/spruce/smartpro/bin/bash /bin/bash chmod +x /bin/bash fi +} + +launch_startup_watchdogs() { + launch_common_startup_watchdogs_v2 + + # Dispatch the Brick's Fn keys (spruce does not run the stock keymon that + # would otherwise do this). Launched here so it lives alongside the other + # durable watchdogs and survives the early-boot churn; pinned like them. + /mnt/SDCARD/spruce/brick/fnkey_watchdog.sh & + SYSTEM_CPU=${DEVICE_MAX_CORES_ONLINE%"${DEVICE_MAX_CORES_ONLINE#?}"} + pin_cpu "$SYSTEM_CPU" -n fnkey_watchdog.sh & } \ No newline at end of file diff --git a/spruce/scripts/platform/device_functions/trimui_a133p.sh b/spruce/scripts/platform/device_functions/trimui_a133p.sh index 0e259edfc..87419719c 100644 --- a/spruce/scripts/platform/device_functions/trimui_a133p.sh +++ b/spruce/scripts/platform/device_functions/trimui_a133p.sh @@ -192,17 +192,6 @@ device_init_a133p() { ) & } -launch_startup_watchdogs() { - launch_common_startup_watchdogs_v2 - - # Dispatch the Brick's Fn keys (spruce does not run the stock keymon that - # would otherwise do this). Launched here so it lives alongside the other - # durable watchdogs and survives the early-boot churn; pinned like them. - /mnt/SDCARD/spruce/brick/fnkey_watchdog.sh & - SYSTEM_CPU=${DEVICE_MAX_CORES_ONLINE%"${DEVICE_MAX_CORES_ONLINE#?}"} - pin_cpu "$SYSTEM_CPU" -n fnkey_watchdog.sh & -} - set_event_arg_for_idlemon() { log_message "nothing to do" -v }