[PATCH] base-files: add blink and turnoff commands to the led script
John Crispin
john at phrozen.org
Mon Jun 28 03:25:42 PDT 2021
you can either use the uci option to make this a boot default or use the
commands to do this manually
this is a common feature of LEDs. they can be on/off have a trigger etc etc.
John
On 28.06.21 12:01, Karl Palsson wrote:
> John Crispin <john at phrozen.org> wrote:
>> 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.
> You actually force them all off though, rather than "not load any
> state" ? Is the intention for "leds_off" like the name, or the
> intention to be "don't touch any leds" in which case the name and
> implementation don't match the commit description?
>
> Also, what's the use case for blink in the default install? It's
> not pushing any stack for a temporary blink, it just hard sets
> allllll led to blink. I can see plenty of uses for this in
> private testing builds, I have something similar myself for
> production testing that all leds function, but i'm having a hard
> time seeing what the use case for it is in general, and why it
> should be in the default build.
>
> Sincerely,
> Karl Palsson
>
>
>> 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
>>
>>
>> _______________________________________________
>> openwrt-devel mailing list
>> openwrt-devel at lists.openwrt.org
>> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list