summaryrefslogtreecommitdiffstats
path: root/package/network/utils/rssileds/files/rssileds.init
blob: b0d262725bb22ef82548c12b17f5a2b42eefdee3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/sh /etc/rc.common
# (C) 2012 Daniel Golle, Allnet GmbH <dgolle@allnet.de>

START=96
STOP=96
RSSILEDS_BIN="/usr/sbin/rssileds"

SERVICE_DAEMONIZE=1
SERVICE_WRITE_PID=1

start_rssid() {
	local name
	local dev
	local threshold
	local refresh
	local leds
	config_get name $1 name
	config_get dev $1 dev
	config_get threshold $1 threshold
	config_get refresh $1 refresh
	leds="$( cur_iface=$1 ; config_foreach get_led led )"
	SERVICE_PID_FILE=/var/run/rssileds-$dev.pid
	service_start $RSSILEDS_BIN $dev $refresh $threshold $leds
}

stop_rssid() {
	local dev
	config_get dev $1 dev
	SERVICE_PID_FILE=/var/run/rssileds-$dev.pid
	service_stop $RSSILEDS_BIN
}

get_led() {
	local name
	local sysfs
	local trigger
	local iface
	config_get sysfs $1 sysfs
	config_get name $1 name "$sysfs"
	config_get trigger $1 trigger "none"
	config_get iface $1 iface
	config_get minq $1 minq
	config_get maxq $1 maxq
	config_get offset $1 offset
	config_get factor $1 factor
	[ "$trigger" = "rssi" ] || return
	[ "$iface" = "$cur_iface" ] || return
	[ ! "$minq" ] || [ ! "$maxq" ] || [ ! "$offset" ] || [ ! "$factor" ] && return
	echo "none" > /sys/class/leds/$sysfs/trigger
	echo "$sysfs $minq $maxq $offset $factor"
}

off_led() {
	local name
	local sysfs
	local trigger
	config_get sysfs $1 sysfs
	config_get name $1 name "$sysfs"
	config_get trigger $1 trigger "none"
	[ "$trigger" = "rssi" ] || return
	echo "0" > /sys/class/leds/$sysfs/brightness
}

start() {
	[ -e /sys/class/leds/ ] && [ -x "$RSSILEDS_BIN" ] && {
		config_load system
		config_foreach start_rssid rssid
	}
}

stop() {
	config_load system
	config_foreach stop_rssid rssid
	config_foreach off_led led
}