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
|
|
|
|
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
|
2009-08-07 00:07:56 +00:00
|
|
|
config_get mode $1 mode "link"
|
|
|
|
config_get_bool default $1 default "nil"
|
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
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
echo $mode > /sys/class/leds/${sysfs}/mode
|
|
|
|
}
|
|
|
|
;;
|
|
|
|
|
|
|
|
"timer")
|
|
|
|
[ -n "$delayon" ] && \
|
|
|
|
echo $delayon > /sys/class/leds/${sysfs}/delay_on
|
|
|
|
[ -n "$delayoff" ] && \
|
|
|
|
echo $delayoff > /sys/class/leds/${sysfs}/delay_off
|
|
|
|
;;
|
|
|
|
|
|
|
|
"usbdev")
|
|
|
|
[ -n "$dev" ] && {
|
|
|
|
echo $dev > /sys/class/leds/${sysfs}/device_name
|
|
|
|
echo $interval > /sys/class/leds/${sysfs}/activity_interval
|
|
|
|
}
|
|
|
|
;;
|
|
|
|
|
|
|
|
"port_state")
|
|
|
|
[ -n "$port_state" ] && \
|
|
|
|
echo $port_state > /sys/class/leds/${sysfs}/port_state
|
|
|
|
;;
|
2011-12-31 15:02:35 +00:00
|
|
|
|
2012-11-25 17:20:49 +00:00
|
|
|
"morse")
|
|
|
|
echo $message > /sys/class/leds/${sysfs}/message
|
|
|
|
echo $delay > /sys/class/leds/${sysfs}/delay
|
|
|
|
;;
|
|
|
|
|
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
|
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/ ] && {
|
|
|
|
config_load system
|
|
|
|
config_foreach load_led led
|
|
|
|
}
|
|
|
|
}
|