base-files: reorder led trigger/brightness writes
[openwrt/svn-archive/archive.git] / package / base-files / files / etc / init.d / led
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008 OpenWrt.org
3
4 START=96
5
6 load_led() {
7 local name
8 local sysfs
9 local trigger
10 local dev
11 local mode
12 local default
13 local delayon
14 local delayoff
15 local interval
16
17 config_get sysfs $1 sysfs
18 config_get name $1 name "$sysfs"
19 config_get trigger $1 trigger "none"
20 config_get dev $1 dev
21 config_get mode $1 mode "link"
22 config_get_bool default $1 default "nil"
23 config_get delayon $1 delayon
24 config_get delayoff $1 delayoff
25 config_get interval $1 interval "50"
26 config_get port_state $1 port_state
27 config_get delay $1 delay "150"
28 config_get message $1 message ""
29
30 if [ "$trigger" = "rssi" ]; then
31 # handled by rssileds userspace process
32 return
33 fi
34
35 [ -e /sys/class/leds/${sysfs}/brightness ] && {
36 echo "setting up led ${name}"
37
38 [ "$default" = 0 ] ||
39 echo 0 >/sys/class/leds/${sysfs}/brightness
40
41 echo $trigger > /sys/class/leds/${sysfs}/trigger 2> /dev/null
42 ret="$?"
43
44 [ $default = 1 ] &&
45 echo 1 >/sys/class/leds/${sysfs}/brightness
46
47 [ $ret = 0 ] || {
48 echo >&2 "Skipping trigger '$trigger' for led '$name' due to missing kernel module"
49 return 1
50 }
51 case "$trigger" in
52 "netdev")
53 [ -n "$dev" ] && {
54 echo $dev > /sys/class/leds/${sysfs}/device_name
55 echo $mode > /sys/class/leds/${sysfs}/mode
56 }
57 ;;
58
59 "timer")
60 [ -n "$delayon" ] && \
61 echo $delayon > /sys/class/leds/${sysfs}/delay_on
62 [ -n "$delayoff" ] && \
63 echo $delayoff > /sys/class/leds/${sysfs}/delay_off
64 ;;
65
66 "usbdev")
67 [ -n "$dev" ] && {
68 echo $dev > /sys/class/leds/${sysfs}/device_name
69 echo $interval > /sys/class/leds/${sysfs}/activity_interval
70 }
71 ;;
72
73 "port_state")
74 [ -n "$port_state" ] && \
75 echo $port_state > /sys/class/leds/${sysfs}/port_state
76 ;;
77
78 "morse")
79 echo $message > /sys/class/leds/${sysfs}/message
80 echo $delay > /sys/class/leds/${sysfs}/delay
81 ;;
82
83 switch[0-9]*)
84 local port_mask
85
86 config_get port_mask $1 port_mask
87 [ -n "$port_mask" ] && \
88 echo $port_mask > /sys/class/leds/${sysfs}/port_mask
89 ;;
90 esac
91 }
92 }
93
94 start() {
95 [ -e /sys/class/leds/ ] && {
96 config_load system
97 config_foreach load_led led
98 }
99 }