Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions axpd.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
#! /bin/bash
hex2dec(){
echo 'ibase=16; obase=A; '"$1" | bc
}
#!/bin/bash

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shebang with spaces is a lie.

checkbit(){
[ $(( $1 & $(( 1 << $2 )) )) != 0 ]
(( $1 & (1 << $2) ))
}
rmmod -f battery
modprobe i2c-dev
modprobe i2c-dev
modprobe test_power
for i in 4 12
do
if find /sys | grep axp288_charger | grep -q i2c-$i/
then
export ADDR=$i
fi
done
case "$(find /sys -path '*axp288_charger*')" in
(*i2c-12*) export ADDR=12;;
(*i2c-4*) export ADDR=4;;
(*) echo "WTF?"; exit 1;;
esac
while true
do
rmmod battery 2>/dev/null
Expand All @@ -35,12 +30,9 @@ do
echo off > /sys/module/test_power/parameters/usb_online
echo discharging > /sys/module/test_power/parameters/battery_status
fi
hex=$(i2cget -f -y $ADDR 0x34 0xb9 | cut -c 3- | tr a-z A-Z)
capacity=$(expr $(hex2dec $hex) - 128)
if [ $capacity -ge 0 ]
if (( (capacity = $(i2cget -f -y $ADDR 0x34 0xb9) - 128) > 0))
then
echo $capacity | tee /sys/module/test_power/parameters/battery_capacity
fi
sleep 10
done