You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
1.8 KiB
93 lines
1.8 KiB
#!/sbin/openrc-run
|
|
# Copyright (C) 2011 Henning Schild <henning@wh9.tu-dresden.de>
|
|
# Copyright (C) 2011 Sebastian Pipping <sebastian@pipping.org>
|
|
#
|
|
# Distributed under the terms of the GNU General Public License, v2 or later
|
|
|
|
extra_started_commands="low high info"
|
|
|
|
SMAPI_SYSFS="/sys/devices/platform/smapi"
|
|
BATS="BAT0 BAT1"
|
|
|
|
depend() {
|
|
after modules
|
|
}
|
|
|
|
start() {
|
|
local state1
|
|
local state2
|
|
|
|
ebegin "Making sure that module 'tp_smapi' is loaded"
|
|
modprobe tp_smapi
|
|
state1=$?
|
|
eend ${state1}
|
|
|
|
ebegin "Checking for \"${SMAPI_SYSFS}\""
|
|
test -d "${SMAPI_SYSFS}"
|
|
state2=$?
|
|
eend ${state2}
|
|
|
|
if [ "${state1}" -ne "0" ] || [ "${state2}" -ne "0" ]; then
|
|
return 1
|
|
fi
|
|
|
|
ebegin "Starting ${SVCNAME}"
|
|
set_all ${SMAPI_THRESH_START} ${SMAPI_THRESH_STOP}
|
|
eend $?
|
|
}
|
|
|
|
stop() {
|
|
einfo "Nothing required to be done to stop ${SVCNAME}"
|
|
}
|
|
|
|
require_started() {
|
|
if ! service_started; then
|
|
"${RC_SERVICE}" start || return $?
|
|
fi
|
|
}
|
|
|
|
high() {
|
|
require_started
|
|
|
|
einfo "Switching ${SVCNAME} to high thesholds"
|
|
set_all ${SMAPI_HIGH_THRESH_START} ${SMAPI_HIGH_THRESH_STOP}
|
|
}
|
|
|
|
low() {
|
|
require_started
|
|
|
|
einfo "Switching ${SVCNAME} to low thesholds"
|
|
set_all ${SMAPI_LOW_THRESH_START} ${SMAPI_LOW_THRESH_STOP}
|
|
}
|
|
|
|
set_all() {
|
|
local tstart=$1
|
|
local tstop=$2
|
|
local bat
|
|
|
|
for bat in ${BATS}; do
|
|
ebegin " setting thresholds for ${bat}: $tstart $tstop"
|
|
echo ${tstart} > ${SMAPI_SYSFS}/${bat}/start_charge_thresh
|
|
echo ${tstop} > ${SMAPI_SYSFS}/${bat}/stop_charge_thresh
|
|
eend $?
|
|
done
|
|
}
|
|
|
|
info() {
|
|
local presence
|
|
local tstart
|
|
local tstop
|
|
local bat
|
|
|
|
require_started
|
|
|
|
for bat in ${BATS}; do
|
|
tstart=$(cat ${SMAPI_SYSFS}/${bat}/start_charge_thresh)
|
|
tstop=$(cat ${SMAPI_SYSFS}/${bat}/stop_charge_thresh)
|
|
if [ "$(cat ${SMAPI_SYSFS}/${bat}/installed)" -eq "1" ]; then
|
|
presence=" [installed]"
|
|
fi
|
|
einfo "${bat}: ${tstart} ${tstop}${presence}"
|
|
done
|
|
}
|