2013-02-18 09:56:23 +00:00
|
|
|
# Copyright (C) 2013 OpenWrt.org
|
|
|
|
|
2020-01-31 14:22:54 +00:00
|
|
|
get_dt_led_path() {
|
2017-11-28 21:51:06 +00:00
|
|
|
local ledpath
|
|
|
|
local basepath="/proc/device-tree"
|
|
|
|
local nodepath="$basepath/aliases/led-$1"
|
|
|
|
|
|
|
|
[ -f "$nodepath" ] && ledpath=$(cat "$nodepath")
|
2020-01-31 14:22:54 +00:00
|
|
|
[ -n "$ledpath" ] && ledpath="$basepath$ledpath"
|
|
|
|
|
|
|
|
echo "$ledpath"
|
|
|
|
}
|
|
|
|
|
2023-10-31 10:47:49 +00:00
|
|
|
get_dt_led_color_func() {
|
|
|
|
local enum
|
|
|
|
local func
|
|
|
|
local idx
|
|
|
|
local label
|
|
|
|
|
|
|
|
[ -e "$1/function" ] && func=$(cat "$1/function")
|
|
|
|
[ -e "$1/color" ] && idx=$((0x$(hexdump -n 4 -e '4/1 "%02x"' "$1/color")))
|
|
|
|
[ -e "$1/function-enumerator" ] && \
|
|
|
|
enum=$((0x$(hexdump -n 4 -e '4/1 "%02x"' "$1/function-enumerator")))
|
|
|
|
|
|
|
|
[ -z "$idx" ] && [ -z "$func" ] && return 2
|
|
|
|
|
|
|
|
if [ -n "$idx" ]; then
|
|
|
|
for color in "white" "red" "green" "blue" "amber" \
|
|
|
|
"violet" "yellow" "ir" "multicolor" "rgb" \
|
|
|
|
"purple" "orange" "pink" "cyan" "lime"
|
|
|
|
do
|
|
|
|
[ $idx -eq 0 ] && label="$color" && break
|
|
|
|
idx=$((idx-1))
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
label="$label:$func"
|
|
|
|
[ -n "$enum" ] && label="$label-$enum"
|
|
|
|
echo "$label"
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-01-31 14:22:54 +00:00
|
|
|
get_dt_led() {
|
|
|
|
local label
|
|
|
|
local ledpath=$(get_dt_led_path $1)
|
|
|
|
|
2018-01-26 22:36:50 +00:00
|
|
|
[ -n "$ledpath" ] && \
|
2020-01-31 14:22:54 +00:00
|
|
|
label=$(cat "$ledpath/label" 2>/dev/null) || \
|
2020-08-30 02:42:54 +00:00
|
|
|
label=$(cat "$ledpath/chan-name" 2>/dev/null) || \
|
2023-10-31 10:47:49 +00:00
|
|
|
label=$(get_dt_led_color_func "$ledpath") || \
|
2020-08-30 02:42:54 +00:00
|
|
|
label=$(basename "$ledpath")
|
2017-11-28 21:51:06 +00:00
|
|
|
|
|
|
|
echo "$label"
|
|
|
|
}
|
|
|
|
|
2013-02-18 09:56:23 +00:00
|
|
|
led_set_attr() {
|
|
|
|
[ -f "/sys/class/leds/$1/$2" ] && echo "$3" > "/sys/class/leds/$1/$2"
|
|
|
|
}
|
|
|
|
|
|
|
|
led_timer() {
|
|
|
|
led_set_attr $1 "trigger" "timer"
|
|
|
|
led_set_attr $1 "delay_on" "$2"
|
|
|
|
led_set_attr $1 "delay_off" "$3"
|
|
|
|
}
|
|
|
|
|
|
|
|
led_on() {
|
|
|
|
led_set_attr $1 "trigger" "none"
|
|
|
|
led_set_attr $1 "brightness" 255
|
|
|
|
}
|
|
|
|
|
|
|
|
led_off() {
|
|
|
|
led_set_attr $1 "trigger" "none"
|
|
|
|
led_set_attr $1 "brightness" 0
|
|
|
|
}
|
|
|
|
|
2020-01-31 14:22:54 +00:00
|
|
|
status_led_restore_trigger() {
|
|
|
|
local trigger
|
|
|
|
local ledpath=$(get_dt_led_path $1)
|
|
|
|
|
|
|
|
[ -n "$ledpath" ] && \
|
|
|
|
trigger=$(cat "$ledpath/linux,default-trigger" 2>/dev/null)
|
|
|
|
|
|
|
|
[ -n "$trigger" ] && \
|
|
|
|
led_set_attr "$(get_dt_led $1)" "trigger" "$trigger"
|
|
|
|
}
|
|
|
|
|
2013-02-18 09:56:23 +00:00
|
|
|
status_led_set_timer() {
|
|
|
|
led_timer $status_led "$1" "$2"
|
|
|
|
[ -n "$status_led2" ] && led_timer $status_led2 "$1" "$2"
|
|
|
|
}
|
|
|
|
|
|
|
|
status_led_set_heartbeat() {
|
|
|
|
led_set_attr $status_led "trigger" "heartbeat"
|
|
|
|
}
|
|
|
|
|
|
|
|
status_led_on() {
|
|
|
|
led_on $status_led
|
|
|
|
[ -n "$status_led2" ] && led_on $status_led2
|
|
|
|
}
|
|
|
|
|
|
|
|
status_led_off() {
|
|
|
|
led_off $status_led
|
|
|
|
[ -n "$status_led2" ] && led_off $status_led2
|
|
|
|
}
|
|
|
|
|
|
|
|
status_led_blink_slow() {
|
|
|
|
led_timer $status_led 1000 1000
|
|
|
|
}
|
|
|
|
|
|
|
|
status_led_blink_fast() {
|
|
|
|
led_timer $status_led 100 100
|
|
|
|
}
|
|
|
|
|
|
|
|
status_led_blink_preinit() {
|
base-files: Use 200ms LED timing as before for the new phase preinit_regular.
This restores normal pre-r43715 200ms blink-period for the System LED we're all accustomed to see while our OpenWrt routers are booting.
Failsafe possibility will now be signalled with a new 100ms blinking, which is easily recognizable from the normal 200ms booting.
So no existing user will be scared by a new 500ms LED pattern, since such a slow pattern could easily be mistaken for something wrong... I was like "ok why my router is collapsing now, is this a bad flash, a kernel panic, or what else" when I've seen it for the first time ;)
Sorry for not having explained myself better in v1 of this patch.
Original:
Preinit, failsafe is possible: 200ms
Preinit, failsafe not possible anymore, booting normally: 200ms
Failsafe entered: 50ms
Now (after preinit_regular has been introduced):
Preinit, failsafe is possible: 200ms
Preinit, failsafe not possible anymore, booting normally: 500ms *here is the "offending" change*
Failsafe entered: 50ms
With my proposed patch:
Preinit, failsafe is possible: 100ms *indicate this condition with a new timing, that prompts the user to press the key if they want to start failsafe*
Preinit, failsafe not possible anymore, booting normally: 200ms *keep this as before*
Failsafe entered: 50ms
Signed-off-by: Vittorio Gambaletta <openwrt@vittgam.net>
SVN-Revision: 44056
2015-01-20 06:54:53 +00:00
|
|
|
led_timer $status_led 100 100
|
2013-02-18 09:56:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status_led_blink_failsafe() {
|
|
|
|
led_timer $status_led 50 50
|
|
|
|
}
|
2014-12-15 10:37:00 +00:00
|
|
|
|
|
|
|
status_led_blink_preinit_regular() {
|
base-files: Use 200ms LED timing as before for the new phase preinit_regular.
This restores normal pre-r43715 200ms blink-period for the System LED we're all accustomed to see while our OpenWrt routers are booting.
Failsafe possibility will now be signalled with a new 100ms blinking, which is easily recognizable from the normal 200ms booting.
So no existing user will be scared by a new 500ms LED pattern, since such a slow pattern could easily be mistaken for something wrong... I was like "ok why my router is collapsing now, is this a bad flash, a kernel panic, or what else" when I've seen it for the first time ;)
Sorry for not having explained myself better in v1 of this patch.
Original:
Preinit, failsafe is possible: 200ms
Preinit, failsafe not possible anymore, booting normally: 200ms
Failsafe entered: 50ms
Now (after preinit_regular has been introduced):
Preinit, failsafe is possible: 200ms
Preinit, failsafe not possible anymore, booting normally: 500ms *here is the "offending" change*
Failsafe entered: 50ms
With my proposed patch:
Preinit, failsafe is possible: 100ms *indicate this condition with a new timing, that prompts the user to press the key if they want to start failsafe*
Preinit, failsafe not possible anymore, booting normally: 200ms *keep this as before*
Failsafe entered: 50ms
Signed-off-by: Vittorio Gambaletta <openwrt@vittgam.net>
SVN-Revision: 44056
2015-01-20 06:54:53 +00:00
|
|
|
led_timer $status_led 200 200
|
2014-12-15 10:37:00 +00:00
|
|
|
}
|