From c26e70add1f8663153fa3095205abe0e8ab2e900 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 18 Sep 2014 16:37:09 -0300 Subject: Initial import --- README.md | 0 TODO.md | 0 battery | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ limbat | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 README.md create mode 100644 TODO.md create mode 100755 battery create mode 100755 limbat diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..e69de29 diff --git a/battery b/battery new file mode 100755 index 0000000..0fe1aeb --- /dev/null +++ b/battery @@ -0,0 +1,65 @@ +#!/bin/bash +# +# See http://blog.lick-me.org/2013/08/yet-another-battery-widget-awesome-3-5-1/ +# + +# Returns battery charge as a percentage. +# Thanks http://blmath.wordpress.com/2010/03/19/bash-function-to-get-battery-charge/ +function battery_charge { + now=`cat /sys/class/power_supply/BAT0/energy_now` + full=`cat /sys/class/power_supply/BAT0/energy_full` + out=`echo $now/$full*100 | bc -l | cut -c 1-5` + + echo $out | sed -e 's/\./,/g' + #echo "Charge: "$out"%" +} + +# Returns battery capacity as a percentage. +# Thanks http://blmath.wordpress.com/2010/03/19/bash-function-to-get-battery-charge/ +function battery_capacity { + design=`cat /sys/class/power_supply/BAT0/energy_full_design` + current=`cat /sys/class/power_supply/BAT0/energy_full` + out=`echo $current/$design*100 | bc -l | cut -c 1-5` + + echo $out | sed -e 's/\./,/g' + #echo "Capacity: "$out"%" +} + +# Basic parameters +healthy='#859900' +low='#b58900' +discharge='#dc322f' + +# Abort if no battery is available +if [ ! -e "/sys/class/power_supply/BAT0" ]; then + exit +fi + +# Get battery status +if [ -e "/sys/class/power_supply/BAT0/charge" ]; then + charge=`cat /sys/class/power_supply/BAT0/charge` +else + charge="`battery_charge`" +fi + +# Set battery level indication +if ((`echo $charge | cut -d ',' -f 1` <= 25)); then + chargeColor=$low +else + chargeColor=$healthy +fi + +# Get battery status +status=`cat /sys/class/power_supply/BAT0/status` + +# Set battery status indication +if [[ "$status" = "Discharging" ]]; then + statusColor=$discharge + status="▼" +else + statusColor=$healthy + status="▲" +fi + +# Output +echo "$charge% $status" diff --git a/limbat b/limbat new file mode 100755 index 0000000..c3489f7 --- /dev/null +++ b/limbat @@ -0,0 +1,67 @@ +#!/bin/sh +# +# See http://www.thinkwiki.org/wiki/Battery +# http://www.thinkwiki.org/wiki/Tp_smapi +# + +function usage() { + echo "Usage: ${0} [--help | option]" + echo "Options are:" + echo " show show current charge thresholds." + echo " limit start charging at 30% and stop at 85%." + echo " normal start charging at 96% and stop at 100%." + exit ${1} +} + +# validate command line options +if [[ (${#} -eq 1 \ + && "${1}" != "--help" \ + && "${1}" != "normal" \ + && "${1}" != "limit" \ + && ${1} != "show") ]]; then + usage 1 +fi + +# show help +if [ "${1}" == "--help" ]; then + usage 0 +fi + +# get action +action="show" +if [ "${1}" != "" ]; then + action=${1} +fi + +# battery interface location +BAT="/sys/devices/platform/smapi/BAT0" + +function show_thresholds() { + echo -n "Low threshold: " + cat $BAT/start_charge_thresh + echo -n "High threshold: " + cat $BAT/stop_charge_thresh +} + +function set_thresholds() { + START_THRESH=${1} + STOP_THRESH=${2} + sudo sh -c "echo ${START_THRESH} > $BAT/start_charge_thresh" + sudo sh -c "echo ${STOP_THRESH} > $BAT/stop_charge_thresh" +} + +# do your thang +sudo modprobe tp_smapi + +THRESHOLDS="" +if [ "${action}" == "normal" ]; then + THRESHOLDS="96 100" +elif [ "${action}" == "limit" ]; then + THRESHOLDS="30 85" +fi + +if [ ! -z "${THRESHOLDS}" ]; then + set_thresholds ${THRESHOLDS} +fi + +show_thresholds -- cgit v1.2.3