Message ID | 20210628070520.153877-1-john@phrozen.org |
---|---|
State | Under Review |
Delegated to: | John Crispin |
Headers | show |
Series | base-files: add blink and turnoff commands to the led script | expand |
ACK I like this. Good for many applications, not the least of which include a quick "stealth mode" LED setting or warning/notification LED blink patterns. All the best, Nick On Mon, 28 Jun 2021 at 17:18, John Crispin <john@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.@system[-1].leds_off > to 1. > > Signed-off-by: John Crispin <john@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.@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@lists.openwrt.org > https://lists.openwrt.org/mailman/listinfo/openwrt-devel
John Crispin <john@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.@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@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.@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@lists.openwrt.org > https://lists.openwrt.org/mailman/listinfo/openwrt-devel
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@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.@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@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.@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@lists.openwrt.org >> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
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.@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 } }
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.@system[-1].leds_off to 1. Signed-off-by: John Crispin <john@phrozen.org> --- package/base-files/files/etc/init.d/led | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)