#!/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