Created
September 21, 2019 00:28
-
-
Save buzztiaan/0c4b7433d8eda2fdcaaa4c779d176d31 to your computer and use it in GitHub Desktop.
Battery discharge and backlight power logging for zipit z2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
now=$(date +%s) | |
dayago=$(( $now - 86400 )) | |
prevstate="banana"; | |
totaldischargetime=0; | |
while read -r line; do | |
state=$(echo $line | cut -d " " -f 1); | |
timestamp=$(echo $line | cut -d " " -f 3); | |
if [ $prevstate == "Discharging" ]; then | |
spenttime=$(( $timestamp - $prevtimestamp )); | |
if [ $timestamp -ge $dayago ]; then | |
totaldischargetime=$(( $totaldischargetime + $spenttime )); | |
fi | |
fi | |
prevstate=$state; | |
prevtimestamp=$timestamp; | |
done < "/root/scripts/PSU.log"; | |
echo -n "Minutes spent discharging last 24hr : "; | |
echo $(( $totaldischargetime / 60 )); | |
totalscreentime=0; | |
while read -r line; do | |
state=$(echo $line | cut -d " " -f 1); | |
timestamp=$(echo $line | cut -d " " -f 2); | |
if [ $state -eq 1 ]; then | |
# screen turned off | |
spenttime=$(( $timestamp - $prevtimestamp )); | |
if [ $timestamp -ge $dayago ]; then | |
totalscreentime=$(( $totalscreentime + $spenttime )); | |
fi | |
fi | |
prevtimestamp=$timestamp; | |
done < "/root/scripts/BL.log"; | |
echo -n "Minutes screen was on last 24hr : "; | |
echo $(( $totalscreentime / 60 )); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
now=$(date +%s) | |
hourago=$(( $now - 3600 )) | |
prevstate="banana"; | |
totaldischargetime=0; | |
while read -r line; do | |
state=$(echo $line | cut -d " " -f 1); | |
timestamp=$(echo $line | cut -d " " -f 3); | |
if [ $prevstate == "Discharging" ]; then | |
spenttime=$(( $timestamp - $prevtimestamp )); | |
if [ $timestamp -ge $hourago ]; then | |
totaldischargetime=$(( $totaldischargetime + $spenttime )); | |
fi | |
fi | |
prevstate=$state; | |
prevtimestamp=$timestamp; | |
done < "/root/scripts/PSU.log"; | |
echo -n "Minutes spent discharging last 1hr : "; | |
echo $(( $totaldischargetime / 60 )); | |
totalscreentime=0; | |
while read -r line; do | |
state=$(echo $line | cut -d " " -f 1); | |
timestamp=$(echo $line | cut -d " " -f 2); | |
if [ $state -eq 1 ]; then | |
# screen turned off | |
spenttime=$(( $timestamp - $prevtimestamp )); | |
if [ $timestamp -ge $hourago ]; then | |
totalscreentime=$(( $totalscreentime + $spenttime )); | |
fi | |
fi | |
prevtimestamp=$timestamp; | |
prevstate=$state; | |
done < "/root/scripts/BL.log"; | |
echo -n "Minutes screen was on last 1hr : "; | |
echo $(( $totalscreentime / 60 )); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
/root/scripts/testPSU.sh >> /root/scripts/PSU.log | |
/root/scripts/testBL.sh >> /root/scripts/BL.log | |
# put testall.sh in /root/scripts/ along with all the others, | |
# then run it fron crontab once a minute |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
blstatusfile="/sys/devices/platform/pxabus/pxabus:display-backlight/backlight/pxabus:display-backlight/bl_power" | |
blstatustemp="/tmp/blstatus" | |
read -r BLSTATUS < $blstatusfile | |
OLDBLSTATUS=$BLSTATUS | |
read -r OLDBLSTATUS < $blstatustemp | |
if [[ $BLSTATUS -ne $OLDBLSTATUS ]]; then | |
echo -n $BLSTATUS | |
echo -n " " | |
date +%s | |
fi | |
echo $BLSTATUS > $blstatustemp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
psustatusfile="/sys/devices/platform/pxabus/40301680.i2c/i2c-1/1-0055/power_supply/Z2/status" | |
psustatustemp="/tmp/psustatus" | |
voltstatusfile="/sys/devices/platform/pxabus/40301680.i2c/i2c-1/1-0055/power_supply/Z2/voltage_now" | |
read -r PSUSTATUS < $psustatusfile | |
read -r VOLTAGE < $voltstatusfile | |
OLDPSUSTATUS=$PSUSTATUS | |
read -r OLDPSUSTATUS < $psustatustemp | |
if [ $PSUSTATUS != $OLDPSUSTATUS ]; then | |
echo -n $PSUSTATUS | |
echo -n " " | |
echo -n $VOLTAGE | |
echo -n " " | |
date +%s | |
fi | |
echo $PSUSTATUS > $psustatustemp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment