From 7e5c8f1b6b07b22a2a7afed64cc5747c736d2eb2 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Thu, 15 Jun 2017 12:34:20 +0300 Subject: [PATCH] - Added scripts to show the battery charge percent on the PocketCHIP. --- Documents/bin/pocketchip-battery | 8 ++++++++ Documents/bin/update-voltage | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100755 Documents/bin/pocketchip-battery create mode 100755 Documents/bin/update-voltage diff --git a/Documents/bin/pocketchip-battery b/Documents/bin/pocketchip-battery new file mode 100755 index 0000000..6a66cfc --- /dev/null +++ b/Documents/bin/pocketchip-battery @@ -0,0 +1,8 @@ +#!/bin/sh +set -eu + +current="$(cat /usr/lib/pocketchip-batt/voltage)" + +. "$HOME/.local/voltage" + +echo $(( 100 * (current - min) / (max - min) )) diff --git a/Documents/bin/update-voltage b/Documents/bin/update-voltage new file mode 100755 index 0000000..83e3f49 --- /dev/null +++ b/Documents/bin/update-voltage @@ -0,0 +1,34 @@ +#!/bin/sh +set -eu +# To install, add the folowing lines to your crontab: +# PATH="~/Documents/bin:/usr/local/bin:/usr/bin:/bin" +# */5 * * * * update-voltage + +filepath="$HOME/.local/voltage" + +update_voltage () { + echo "min=$1" > "$filepath" + echo "max=$2" >> "$filepath" +} + +current="$(cat /usr/lib/pocketchip-batt/voltage)" + +mkdir -p "$(dirname "$filepath" )" + +if [ ! -f "$filepath" ] +then + update_voltage "$current" "$current" + exit 0 +fi + +. "$filepath" + +if [ "$current" -gt "$max" ] +then + max="$current" + update_voltage "$min" "$max" +elif [ "$current" -lt "$min" ] +then + min="$current" + update_voltage "$min" "$max" +fi -- GitLab