[PATCH] base-files: add blink and turnoff commands to the led script

John Crispin john at phrozen.org
Mon Jun 28 00:05:20 PDT 2021


This allows us to make all leds blink or force all leds to off.
It is also possible to force the default behaviour to not load
any led states/triggers by setting system. at system[-1].leds_off
to 1.

Signed-off-by: John Crispin <john at phrozen.org>
---
 package/base-files/files/etc/init.d/led | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/package/base-files/files/etc/init.d/led b/package/base-files/files/etc/init.d/led
index 51cb8b5178..252bba623a 100755
--- a/package/base-files/files/etc/init.d/led
+++ b/package/base-files/files/etc/init.d/led
@@ -3,6 +3,9 @@
 
 START=96
 
+extra_command "turnoff" "Turn all leds off"
+extra_command "blink" "Blink all leds"
+
 load_led() {
 	local name
 	local sysfs
@@ -121,7 +124,25 @@ load_led() {
 	}
 }
 
+turnoff() {
+	for led in `ls /sys/class/leds/`; do
+		echo none > /sys/class/leds/$led/trigger
+		echo 0 > /sys/class/leds/$led/brightness
+	done
+}
+
+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 get system. at system[-1].leds_off)" -eq 1 ] && {
+		turnoff
+		exit 0
+	}
 	[ -e /sys/class/leds/ ] && {
 		[ -s /var/run/led.state ] && {
 			local led trigger brightness
@@ -137,5 +158,7 @@ start() {
 
 		config_load system
 		config_foreach load_led led
+		. /etc/diag.sh
+		set_state done
 	}
 }
-- 
2.25.1




More information about the openwrt-devel mailing list