forked from Icenowy/axpd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaxpd.sh
More file actions
executable file
·46 lines (45 loc) · 1.17 KB
/
Copy pathaxpd.sh
File metadata and controls
executable file
·46 lines (45 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /bin/bash
hex2dec(){
echo 'ibase=16; obase=A; '"$1" | bc
}
checkbit(){
[ $(( $1 & $(( 1 << $2 )) )) != 0 ]
}
rmmod -f battery
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
while true
do
rmmod battery 2>/dev/null
echo off > /sys/module/test_power/parameters/ac_online
echo LION > /sys/module/test_power/parameters/battery_technology
source_status_reg=$(i2cget -f -y $ADDR 0x34 0x00)
charger_status_reg=$(i2cget -f -y $ADDR 0x34 0x01)
if checkbit $source_status_reg 4
then
echo on > /sys/module/test_power/parameters/usb_online
if checkbit $charger_status_reg 6
then
echo charging > /sys/module/test_power/parameters/battery_status
else
echo not-charging > /sys/module/test_power/parameters/battery_status
fi
else
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 ]
then
echo $capacity | tee /sys/module/test_power/parameters/battery_capacity
fi
sleep 10
done