add app-laptop/tp_smapi-0.41
[shuber-gentoo-overlay.git] / app-laptop / tp_smapi / files / tp_smapi-0.41-initd
1 #!/sbin/runscript
2 # Copyright (C) 2011 Henning Schild <henning@wh9.tu-dresden.de>
3 # Copyright (C) 2011 Sebastian Pipping <sebastian@pipping.org>
4 #
5 # Distributed under the terms of the GNU General Public License, v2 or later
6
7 opts="low high info"
8
9 SMAPI_SYSFS="/sys/devices/platform/smapi"
10 BATS="BAT0 BAT1"
11
12 depend() {
13 after modules
14 }
15
16 start() {
17 local state1
18 local state2
19
20 ebegin "Making sure that module 'tp_smapi' is loaded"
21 modprobe tp_smapi
22 state1=$?
23 eend ${state1}
24
25 ebegin "Checking for \"${SMAPI_SYSFS}\""
26 test -d "${SMAPI_SYSFS}"
27 state2=$?
28 eend ${state2}
29
30 if [ "${state1}" -ne "0" ] || [ "${state2}" -ne "0" ]; then
31 return 1
32 fi
33
34 ebegin "Starting ${SVCNAME}"
35 set_all ${SMAPI_THRESH_START} ${SMAPI_THRESH_STOP}
36 eend $?
37 }
38
39 stop() {
40 einfo "Nothing required to be done to stop ${SVCNAME}"
41 }
42
43 require_started() {
44 if ! service_started; then
45 "${RC_SERVICE}" start || return $?
46 fi
47 }
48
49 high() {
50 require_started
51
52 einfo "Switching ${SVCNAME} to high thesholds"
53 set_all ${SMAPI_HIGH_THRESH_START} ${SMAPI_HIGH_THRESH_STOP}
54 }
55
56 low() {
57 require_started
58
59 einfo "Switching ${SVCNAME} to low thesholds"
60 set_all ${SMAPI_LOW_THRESH_START} ${SMAPI_LOW_THRESH_STOP}
61 }
62
63 set_all() {
64 local tstart=$1
65 local tstop=$2
66 local bat
67
68 for bat in ${BATS}; do
69 ebegin " setting thresholds for ${bat}: $tstart $tstop"
70 echo ${tstart} > ${SMAPI_SYSFS}/${bat}/start_charge_thresh
71 echo ${tstop} > ${SMAPI_SYSFS}/${bat}/stop_charge_thresh
72 eend $?
73 done
74 }
75
76 info() {
77 local presence
78 local tstart
79 local tstop
80 local bat
81
82 require_started
83
84 for bat in ${BATS}; do
85 tstart=$(cat ${SMAPI_SYSFS}/${bat}/start_charge_thresh)
86 tstop=$(cat ${SMAPI_SYSFS}/${bat}/stop_charge_thresh)
87 if [ "$(cat ${SMAPI_SYSFS}/${bat}/installed)" -eq "1" ]; then
88 presence=" [installed]"
89 fi
90 einfo "${bat}: ${tstart} ${tstop}${presence}"
91 done
92 }