]> git.sthu.org Git - shutils.git/commitdiff
Adding smapi set battery scripts
authorStefan Huber <shuber@sthu.org>
Sat, 4 Jan 2014 09:04:09 +0000 (10:04 +0100)
committerStefan Huber <shuber@sthu.org>
Sat, 4 Jan 2014 09:04:09 +0000 (10:04 +0100)
smapi/smapi.conf [new file with mode: 0644]
smapi/smapi_battthresh [new file with mode: 0755]
systemd/smapi.service [new file with mode: 0644]

diff --git a/smapi/smapi.conf b/smapi/smapi.conf
new file mode 100644 (file)
index 0000000..5943e90
--- /dev/null
@@ -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 (executable)
index 0000000..09c743a
--- /dev/null
@@ -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 <shuber@sthu.org>
+
+
+
+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 (file)
index 0000000..7540f69
--- /dev/null
@@ -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