From 102855b3c13e4fc6b1df4325ee51855a69874f88 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Thu, 1 Feb 2024 11:17:17 +0100 Subject: [PATCH] base-files/leds: save led color value if available There are monochrome LEDs that can only display one color. However, there are also LEDs that can display multiple colors. This can be tested in the led subsystem of the kernel if the files 'multi_index' and 'multi_intensity' are present in the folder '/sys/class/leds/'. Until now it was not possible to reset the default color. This commit adds the missing information in the file '/var/run/led.state' so that the bootup color can be seen on the LED again when the LED configuration has been changed. Signed-off-by: Florian Eckert --- package/base-files/files/etc/init.d/led | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/package/base-files/files/etc/init.d/led b/package/base-files/files/etc/init.d/led index 08a1e6df3b..d7fee9ebb2 100755 --- a/package/base-files/files/etc/init.d/led +++ b/package/base-files/files/etc/init.d/led @@ -49,11 +49,18 @@ load_led() { [ -e /sys/class/leds/${sysfs}/brightness ] && { echo "setting up led ${name}" - printf "%s %s %d\n" \ + printf "%s %s %d" \ "$sysfs" \ "$(sed -ne 's/^.*\[\(.*\)\].*$/\1/p' /sys/class/leds/${sysfs}/trigger)" \ "$(cat /sys/class/leds/${sysfs}/brightness)" \ >> /var/run/led.state + # Save default color if supported + [ -e /sys/class/leds/${sysfs}/multi_intensity ] && { + printf " %s" \ + "$(sed 's/\ /:/g' /sys/class/leds/${sysfs}/multi_intensity)" \ + >> /var/run/led.state + } + printf "\n" >> /var/run/led.state [ "$default" = 0 ] && echo 0 >/sys/class/leds/${sysfs}/brightness @@ -128,13 +135,17 @@ load_led() { start() { [ -e /sys/class/leds/ ] && { [ -s /var/run/led.state ] && { - local led trigger brightness - while read led trigger brightness; do + local led trigger brightness color + while read led trigger brightness color; do [ -e "/sys/class/leds/$led/trigger" ] && \ echo "$trigger" > "/sys/class/leds/$led/trigger" [ -e "/sys/class/leds/$led/brightness" ] && \ echo "$brightness" > "/sys/class/leds/$led/brightness" + + [ -e "/sys/class/leds/$led/multi_intensity" ] && \ + echo "$color" | sed 's/:/\ /g' > \ + "/sys/class/leds/$led/multi_intensity" done < /var/run/led.state rm /var/run/led.state } -- 2.30.2