From 9cad7d0fe21304a6eef1621edf330378517ab4e9 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Sat, 4 Jan 2014 10:04:09 +0100 Subject: [PATCH] Adding smapi set battery scripts --- smapi/smapi.conf | 13 +++++ smapi/smapi_battthresh | 105 +++++++++++++++++++++++++++++++++++++++++ systemd/smapi.service | 11 +++++ 3 files changed, 129 insertions(+) create mode 100644 smapi/smapi.conf create mode 100755 smapi/smapi_battthresh create mode 100644 systemd/smapi.service diff --git a/smapi/smapi.conf b/smapi/smapi.conf new file mode 100644 index 0000000..5943e90 --- /dev/null +++ b/smapi/smapi.conf @@ -0,0 +1,13 @@ +# Battery charging threshholds for smapi_battthresh + +# values to be used for 'smapi_battthresh low' +BATTERY_LOW_THRESH_START="50" +BATTERY_LOW_THRESH_STOP="70" + +# values to be used for '/smapi_battthresh high' +BATTERY_HIGH_THRESH_START="95" +BATTERY_HIGH_THRESH_STOP="100" + +# default thresholds 'smapi_battthresh' +BATTERY_THRESH_START="${BATTERY_LOW_THRESH_START}" +BATTERY_THRESH_STOP="${BATTERY_LOW_THRESH_STOP}" diff --git a/smapi/smapi_battthresh b/smapi/smapi_battthresh new file mode 100755 index 0000000..09c743a --- /dev/null +++ b/smapi/smapi_battthresh @@ -0,0 +1,105 @@ +#!/bin/sh +# Copyright (c) 2014 Stefan Huber +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. + +# Author: Stefan Huber + + + +CONFIG_FILE="/etc/smapi.conf" +SMAPI_SYSFS="/sys/devices/platform/smapi" +BATS="BAT0 BAT1" + +load_config() { + if [ -e ${CONFIG_FILE} ]; then + source ${CONFIG_FILE} + else + echo "No config file /etc/smapi.conf found." + exit 1 + fi +} + +set_all() { + local tstart=$1 + local tstop=$2 + local bat + + for bat in ${BATS}; do + echo " setting thresholds for ${bat}: $tstart $tstop" + echo ${tstart} > ${SMAPI_SYSFS}/${bat}/start_charge_thresh + echo ${tstop} > ${SMAPI_SYSFS}/${bat}/stop_charge_thresh + done +} + +set_default() { + echo "Switching to default thesholds" + load_config + set_all ${BATTERY_THRESH_START} ${BATTERY_THRESH_STOP} +} + +set_high() { + echo "Switching to high thesholds" + load_config + set_all ${BATTERY_HIGH_THRESH_START} ${BATTERY_HIGH_THRESH_STOP} +} + +set_low() { + echo "Switching to low thesholds" + load_config + set_all ${BATTERY_LOW_THRESH_START} ${BATTERY_LOW_THRESH_STOP} +} + +info() { + local presence + local tstart + local tstop + local bat + + 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 + echo "${bat}: ${tstart}..${tstop}${presence}" + done +} + +if [ "$#" = "0" ]; then + info +else + case "$1" in + high) + set_high + ;; + low) + set_low + ;; + default) + set_default + ;; + *) + info + ;; + esac +fi diff --git a/systemd/smapi.service b/systemd/smapi.service new file mode 100644 index 0000000..7540f69 --- /dev/null +++ b/systemd/smapi.service @@ -0,0 +1,11 @@ +[Unit] +Description=iptables +Before=network.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/local/bin/smapi_battthresh default + +[Install] +WantedBy=multi-user.target -- 2.39.5