base-files/leds: save led color value if available
authorFlorian Eckert <fe@dev.tdt.de>
Thu, 1 Feb 2024 10:17:17 +0000 (11:17 +0100)
committerFlorian Eckert <fe@dev.tdt.de>
Wed, 7 Feb 2024 14:34:43 +0000 (15:34 +0100)
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/<ledname>'.

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 <fe@dev.tdt.de>
package/base-files/files/etc/init.d/led

index 08a1e6df3bbaf697c1eaaaea8e2501af77f4f901..d7fee9ebb2eb136af460a1c96f23ba85431d9731 100755 (executable)
@@ -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
                }