Skip to content

Instantly share code, notes, and snippets.

@xtacocorex
Last active July 14, 2018 19:23
Show Gist options
  • Save xtacocorex/17ad3fa728e012168a4fc848bb688ad4 to your computer and use it in GitHub Desktop.
Save xtacocorex/17ad3fa728e012168a4fc848bb688ad4 to your computer and use it in GitHub Desktop.
@Groguard's pocketchip battery script mods
#!/bin/sh
while true
do
###################
#read fuel gauge B9h
BAT_GAUGE_HEX=$(i2cget -y -f 0 0x34 0xb9)
#read power op mode
POWER_OP_MODE=$(i2cget -y -f 0 0x34 0x01)
# get charging indicator
CHARG_IND=$(($(($POWER_OP_MODE&0x40))/64)) # divide by 64 is like shifting rigth 6 times
# output to file
echo $CHARG_IND > /tmp/charging
# bash math -- converts hex to decimal so `bc` won't complain later...
# MSB is 8 bits, LSB is lower 4 bits
BAT_GAUGE_DEC=$(($BAT_GAUGE_HEX))
echo $BAT_GAUGE_DEC% > /tmp/battery
while [ $BAT_GAUGE_DEC -le 20 ]; do
i2cset -f -y 0 0x34 0x93 0x0 # Turn LED Off
sleep 0.50
i2cset -f -y 0 0x34 0x93 0x1 # Turn LED On
sleep 0.50
done
sleep 60
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment