2008-08-04 22:56:46 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
2014-06-24 18:18:50 +00:00
|
|
|
# Copyright (C) 2008 OpenWrt.org
|
2008-08-04 22:56:46 +00:00
|
|
|
|
2010-01-06 02:34:20 +00:00
|
|
|
START=96
|
2008-08-04 22:56:46 +00:00
|
|
|
|
|
|
|
load_led() {
|
|
|
|
local name
|
|
|
|
local sysfs
|
|
|
|
local trigger
|
|
|
|
local dev
|
2016-10-19 10:09:45 +00:00
|
|
|
local ports
|
2008-08-04 22:56:46 +00:00
|
|
|
local mode
|
|
|
|
local default
|
2008-08-07 11:01:46 +00:00
|
|
|
local delayon
|
|
|
|
local delayoff
|
2010-12-17 17:10:14 +00:00
|
|
|
local interval
|
2008-08-04 22:56:46 +00:00
|
|
|
|
|
|
|
config_get sysfs $1 sysfs
|
2009-08-07 00:07:56 +00:00
|
|
|
config_get name $1 name "$sysfs"
|
|
|
|
config_get trigger $1 trigger "none"
|
2008-08-04 22:56:46 +00:00
|
|
|
config_get dev $1 dev
|
2016-10-19 11:05:53 +00:00
|
|
|
config_get ports $1 port
|
2018-09-21 22:38:40 +00:00
|
|
|
config_get mode $1 mode
|
2020-07-26 20:37:53 +00:00
|
|
|
config_get_bool default $1 default "0"
|
2008-08-07 11:01:46 +00:00
|
|
|
config_get delayon $1 delayon
|
|
|
|
config_get delayoff $1 delayoff
|
2010-12-17 17:10:14 +00:00
|
|
|
config_get interval $1 interval "50"
|
2011-01-27 21:49:46 +00:00
|
|
|
config_get port_state $1 port_state
|
2012-11-25 17:20:49 +00:00
|
|
|
config_get delay $1 delay "150"
|
|
|
|
config_get message $1 message ""
|
2015-07-14 07:35:59 +00:00
|
|
|
config_get gpio $1 gpio "0"
|
|
|
|
config_get inverted $1 inverted "0"
|
2008-08-04 22:56:46 +00:00
|
|
|
|
2012-10-11 06:45:02 +00:00
|
|
|
if [ "$trigger" = "rssi" ]; then
|
|
|
|
# handled by rssileds userspace process
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2016-10-19 10:09:45 +00:00
|
|
|
[ "$trigger" = "usbdev" ] && {
|
|
|
|
# Backward compatibility: translate to the new trigger
|
|
|
|
trigger="usbport"
|
|
|
|
# Translate port of root hub, e.g. 4-1 -> usb4-port1
|
|
|
|
ports=$(echo "$dev" | sed -n 's/^\([0-9]*\)-\([0-9]*\)$/usb\1-port\2/p')
|
|
|
|
# Translate port of extra hub, e.g. 2-2.4 -> 2-2-port4
|
|
|
|
[ -z "$ports" ] && ports=$(echo "$dev" | sed -n 's/\./-port/p')
|
|
|
|
}
|
|
|
|
|
2008-09-13 00:08:39 +00:00
|
|
|
[ -e /sys/class/leds/${sysfs}/brightness ] && {
|
2009-08-07 00:07:56 +00:00
|
|
|
echo "setting up led ${name}"
|
2015-04-16 20:09:30 +00:00
|
|
|
|
2016-06-08 08:14:27 +00:00
|
|
|
printf "%s %s %d\n" \
|
|
|
|
"$sysfs" \
|
|
|
|
"$(sed -ne 's/^.*\[\(.*\)\].*$/\1/p' /sys/class/leds/${sysfs}/trigger)" \
|
|
|
|
"$(cat /sys/class/leds/${sysfs}/brightness)" \
|
|
|
|
>> /var/run/led.state
|
|
|
|
|
2015-05-03 18:04:27 +00:00
|
|
|
[ "$default" = 0 ] &&
|
2015-04-16 20:09:30 +00:00
|
|
|
echo 0 >/sys/class/leds/${sysfs}/brightness
|
|
|
|
|
2015-01-23 12:33:04 +00:00
|
|
|
echo $trigger > /sys/class/leds/${sysfs}/trigger 2> /dev/null
|
2015-04-16 20:09:30 +00:00
|
|
|
ret="$?"
|
|
|
|
|
|
|
|
[ $default = 1 ] &&
|
2015-12-11 15:06:11 +00:00
|
|
|
cat /sys/class/leds/${sysfs}/max_brightness > /sys/class/leds/${sysfs}/brightness
|
2015-04-16 20:09:30 +00:00
|
|
|
|
|
|
|
[ $ret = 0 ] || {
|
2015-01-23 12:33:04 +00:00
|
|
|
echo >&2 "Skipping trigger '$trigger' for led '$name' due to missing kernel module"
|
|
|
|
return 1
|
|
|
|
}
|
2011-12-31 15:02:32 +00:00
|
|
|
case "$trigger" in
|
|
|
|
"netdev")
|
|
|
|
[ -n "$dev" ] && {
|
|
|
|
echo $dev > /sys/class/leds/${sysfs}/device_name
|
2018-12-16 15:51:26 +00:00
|
|
|
for m in $mode; do
|
|
|
|
[ -e "/sys/class/leds/${sysfs}/$m" ] && \
|
|
|
|
echo 1 > /sys/class/leds/${sysfs}/$m
|
|
|
|
done
|
2017-10-27 08:17:34 +00:00
|
|
|
echo $interval > /sys/class/leds/${sysfs}/interval
|
2011-12-31 15:02:32 +00:00
|
|
|
}
|
|
|
|
;;
|
|
|
|
|
2016-08-26 11:17:49 +00:00
|
|
|
"timer"|"oneshot")
|
2011-12-31 15:02:32 +00:00
|
|
|
[ -n "$delayon" ] && \
|
|
|
|
echo $delayon > /sys/class/leds/${sysfs}/delay_on
|
|
|
|
[ -n "$delayoff" ] && \
|
|
|
|
echo $delayoff > /sys/class/leds/${sysfs}/delay_off
|
|
|
|
;;
|
|
|
|
|
2016-10-19 10:09:45 +00:00
|
|
|
"usbport")
|
|
|
|
local p
|
|
|
|
|
|
|
|
for p in $ports; do
|
|
|
|
echo 1 > /sys/class/leds/${sysfs}/ports/$p
|
|
|
|
done
|
2011-12-31 15:02:32 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
"port_state")
|
|
|
|
[ -n "$port_state" ] && \
|
|
|
|
echo $port_state > /sys/class/leds/${sysfs}/port_state
|
|
|
|
;;
|
2011-12-31 15:02:35 +00:00
|
|
|
|
2015-07-14 07:35:59 +00:00
|
|
|
"gpio")
|
|
|
|
echo $gpio > /sys/class/leds/${sysfs}/gpio
|
|
|
|
echo $inverted > /sys/class/leds/${sysfs}/inverted
|
|
|
|
;;
|
|
|
|
|
2011-12-31 15:02:35 +00:00
|
|
|
switch[0-9]*)
|
2016-02-25 13:31:29 +00:00
|
|
|
local port_mask speed_mask
|
2011-12-31 15:02:35 +00:00
|
|
|
|
|
|
|
config_get port_mask $1 port_mask
|
|
|
|
[ -n "$port_mask" ] && \
|
|
|
|
echo $port_mask > /sys/class/leds/${sysfs}/port_mask
|
2016-02-25 13:31:29 +00:00
|
|
|
config_get speed_mask $1 speed_mask
|
|
|
|
[ -n "$speed_mask" ] && \
|
|
|
|
echo $speed_mask > /sys/class/leds/${sysfs}/speed_mask
|
2018-09-21 22:38:40 +00:00
|
|
|
[ -n "$mode" ] && \
|
|
|
|
echo "$mode" > /sys/class/leds/${sysfs}/mode
|
2011-12-31 15:02:35 +00:00
|
|
|
;;
|
2011-12-31 15:02:32 +00:00
|
|
|
esac
|
2008-08-04 22:56:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
[ -e /sys/class/leds/ ] && {
|
2016-06-08 08:14:27 +00:00
|
|
|
[ -s /var/run/led.state ] && {
|
|
|
|
local led trigger brightness
|
|
|
|
while read led trigger brightness; do
|
|
|
|
[ -e "/sys/class/leds/$led/trigger" ] && \
|
|
|
|
echo "$trigger" > "/sys/class/leds/$led/trigger"
|
|
|
|
|
|
|
|
[ -e "/sys/class/leds/$led/brightness" ] && \
|
|
|
|
echo "$brightness" > "/sys/class/leds/$led/brightness"
|
|
|
|
done < /var/run/led.state
|
|
|
|
rm /var/run/led.state
|
|
|
|
}
|
2016-06-07 20:58:22 +00:00
|
|
|
|
2008-08-04 22:56:46 +00:00
|
|
|
config_load system
|
|
|
|
config_foreach load_led led
|
|
|
|
}
|
|
|
|
}
|