base-files: allow forcing all LEDs to on/off/blink state main
authorJohn Crispin <john@phrozen.org>
Fri, 9 Feb 2024 17:10:12 +0000 (18:10 +0100)
committerJohn Crispin <john@phrozen.org>
Tue, 17 Sep 2024 17:59:53 +0000 (19:59 +0200)
* add a UCI option to disable all LEDs.
* add an init.d parameter to blink all LEDs
* add on/off parameters to init.d

Signed-off-by: John Crispin <john@phrozen.org>
package/base-files/files/etc/init.d/led

index 9c4d2091c8b884a729fb34e2e216ebc2eafd7ef9..1d8930f2cdceccf935b8050f211279c18abd9622 100755 (executable)
@@ -3,6 +3,10 @@
 
 START=96
 
+extra_command "turnon" "Put the LEDs into their default state"
+extra_command "turnoff" "Turn all LEDs off"
+extra_command "blink" "Blink all LEDs"
+
 led_color_set() {
        local cfg="$1"
        local sysfs="$2"
@@ -171,7 +175,31 @@ load_led() {
        }
 }
 
+turnoff() {
+       for led in `ls /sys/class/leds/`; do
+               echo 0 > /sys/class/leds/$led/brightness
+       done
+}
+
+turnon() {
+       turnoff
+       . /etc/diag.sh
+       set_state done
+       start
+}
+
+blink() {
+       for led in `ls /sys/class/leds/`; do
+               echo 0 > /sys/class/leds/$led/brightness
+               echo timer > /sys/class/leds/$led/trigger
+       done
+}
+
 start() {
+       [ "$(uci -q get system.@system[-1].leds_off)" = '1' ] && {
+               turnoff
+               exit 0
+       }
        [ -e /sys/class/leds/ ] && {
                [ -s /var/run/led.state ] && {
                        local led trigger brightness color