Skip to content

Commit f237b0b

Browse files
committed
Support more devices with unconventional battery interfaces
1 parent 5c3c916 commit f237b0b

File tree

3 files changed

+45
-46
lines changed

3 files changed

+45
-46
lines changed

install/batt-info.sh

+29-28
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,36 @@ batt_info() {
2929

3030
# raw battery info from the kernel's battery interface
3131
info="$(
32-
{ cat $batt/uevent; printf STATUS=; cat $battStatus; } \
32+
{ grep . $batt/* 2>/dev/null || :; printf status=; cat $battStatus; } \
3333
| sort -u \
34-
| sed -E -e '/^POWER_SUPPLY_STATUS=/d' \
35-
-e 's/^POWER_SUPPLY_//' \
36-
-e 's/^BATT_VOL=/VOLTAGE_NOW=/' \
37-
-e 's/^BATT_TEMP=/TEMP=/' \
38-
-e '/^(CHARGE_TYPE|NAME)=/d'\
39-
-e "/^CAPACITY=/s/=.*/=$(cat $battCapacity)/"
34+
| sed -E "s|$batt/||;
35+
/^uevent:/d;
36+
s/^batt_vol=/voltage_now=/;
37+
s/^batt_temp=/temp=/;
38+
/^(charge_type|name)=/d;
39+
/^capacity=/s/=.*/=$(cat $battCapacity)/;
40+
s/:/=/"
4041
)"
4142

4243

4344
# determine the correct charging status
4445
not_charging || :
45-
info="$(echo "$info" | sed "/^STATUS=/s/=.*/=$_status/")"
46+
info="$(echo "$info" | sed "/^status=/s/=.*/=$_status/")"
4647

4748

4849
# because MediaTek is weird
4950
[ ! -d /proc/mtk_battery_cmd ] || {
50-
echo "$info" | grep '^CURRENT_NOW=' > /dev/null \
51-
|| info="${info/BATTERYAVERAGECURRENT=/CURRENT_NOW=}"
51+
echo "$info" | grep '^current_now=' > /dev/null \
52+
|| info="${info/batteryaveragecurrent=/current_now=}"
5253
}
5354

5455

5556
# ensure temperature value is correct
56-
info="$(echo "$info" | sed "/^TEMP=/s/=.*/=$(cat $temp)/g" | sort -u)"
57+
info="$(echo "$info" | sed "/^temp=/s/=.*/=$(cat $temp)/g" | sort -u)"
5758

5859

5960
# parse CURRENT_NOW & convert to Amps
60-
currNow=$(echo "$info" | sed -n "s/^CURRENT_NOW=//p" | head -n1)
61+
currNow=$(echo "$info" | sed -n "s/^current_now=//p" | head -n1)
6162
dtr_conv_factor ${currNow#-} ${ampFactor:-$ampFactor_}
6263
currNow=$(calc2 ${currNow:-0} / $factor)
6364

@@ -78,7 +79,7 @@ batt_info() {
7879

7980

8081
# parse VOLTAGE_NOW & convert to Volts
81-
voltNow=$(echo "$info" | sed -n "s/^VOLTAGE_NOW=//p" | head -n1)
82+
voltNow=$(echo "$info" | sed -n "s/^voltage_now=//p" | head -n1)
8283
dtr_conv_factor $voltNow ${voltFactor-}
8384
voltNow=$(calc2 ${voltNow:-0} / $factor)
8485

@@ -91,35 +92,35 @@ batt_info() {
9192
# print raw battery info
9293
${verbose:-true} \
9394
&& echo "$info" \
94-
|| echo "$info" | grep -Ev '^(CURRENT|VOLTAGE)_NOW='
95+
|| echo "$info" | grep -Ev '^(current|voltage)_now='
9596

9697
# print CURRENT_NOW, VOLTAGE_NOW and POWER_NOW
9798
echo "
98-
CURRENT_NOW=$currNow$(print_A 2>/dev/null || :)
99-
VOLTAGE_NOW=$voltNow$(print_V 2>/dev/null || :)
100-
POWER_NOW=$powerNow$(print_W 2>/dev/null || :)"
99+
current_now=$currNow$(print_a 2>/dev/null || :)
100+
voltage_now=$voltNow$(print_v 2>/dev/null || :)
101+
power_now=$powerNow$(print_W 2>/dev/null || :)"
101102

102103

103104
# power supply info
104105
for i in $(online_f); do
105106
if [ -f $i ] && [ $(cat $i) -eq 1 ]; then
106107
i=${i%/*}
107-
POWER_SUPPLY_TYPE=$(cat $i/real_type 2>/dev/null || echo $i | tr [a-z] [A-Z])
108+
power_supply_type=$(cat $i/real_type 2>/dev/null || echo $i)
108109

109110
echo "
110-
CHARGE_TYPE=$POWER_SUPPLY_TYPE"
111+
charge_type=$power_supply_type"
111112

112-
POWER_SUPPLY_AMPS=$(dtr_conv_factor $(cat $i/*current_now | tail -n 1) ${ampFactor:-$ampFactor_})
113+
power_supply_amps=$(dtr_conv_factor $(cat $i/*current_now | tail -n 1) ${ampFactor:-$ampFactor_})
113114

114-
if [ 0${POWER_SUPPLY_AMPS%.*} -gt 0 ]; then
115-
POWER_SUPPLY_VOLTS=$(dtr_conv_factor $(cat $i/voltage_now) ${voltFactor-})
116-
POWER_SUPPLY_WATTS=$(calc2 $POWER_SUPPLY_AMPS \* $POWER_SUPPLY_VOLTS)
117-
CONSUMED_WATTS=$(calc2 $POWER_SUPPLY_WATTS - $powerNow)
115+
if [ 0${power_supply_amps%.*} -gt 0 ]; then
116+
power_supply_volts=$(dtr_conv_factor $(cat $i/voltage_now) ${voltFactor-})
117+
power_supply_watts=$(calc2 $power_supply_amps \* $power_supply_volts)
118+
consumed_watts=$(calc2 $power_supply_watts - $powernow)
118119

119-
echo "POWER_SUPPLY_AMPS=$POWER_SUPPLY_AMPS
120-
POWER_SUPPLY_VOLTS=$POWER_SUPPLY_VOLTS
121-
POWER_SUPPLY_WATTS=$POWER_SUPPLY_WATTS
122-
CONSUMED_WATTS=$CONSUMED_WATTS"
120+
echo "power_supply_amps=$power_supply_amps
121+
power_supply_volts=$power_supply_volts
122+
power_supply_watts=$power_supply_watts
123+
consumed_watts=$consumed_watts"
123124
fi
124125

125126
break

install/batt-interface.sh

+14-16
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,19 @@ status() {
114114
_status=$(set -eu; eval '$battStatusOverride') || :
115115
fi
116116
elif $battStatusWorkaround; then
117-
if [ $_status != Idle ]; then
118-
if [ "$switch" = off ] && { [ -n "${exitCode_-}" ] || ${cyclingSw:-false}; }; then
119-
for i in $(seq $iti); do
120-
curNow=$(cat $currFile)
121-
idle_discharging
122-
if [ $_status = Idle ]; then
123-
[ $i -eq $iti ] || sleep 1
124-
else
125-
[ $sti -eq 0 ] || return1=true
126-
break
127-
fi
128-
done
129-
else
117+
if [ "$switch" = off ] && { [ -n "${exitCode_-}" ] || ${cyclingSw:-false}; }; then
118+
for i in $(seq $iti); do
119+
curNow=$(cat $currFile)
130120
idle_discharging
131-
fi
121+
if [ $_status = Idle ]; then
122+
[ $i -eq $iti ] || sleep 1
123+
else
124+
[ $sti -eq 0 ] || return1=true
125+
break
126+
fi
127+
done
128+
else
129+
idle_discharging
132130
fi
133131
fi
134132

@@ -160,7 +158,7 @@ if ${init:-false}; then
160158
batt=${f2%/*}
161159
else
162160
for batt in maxfg/capacity */capacity; do
163-
if [ -f ${batt%/*}/status ] && [ -n "$(cat ${batt%/*}/uevent 2>/dev/null || :)" ]; then
161+
if [ -f ${batt%/*}/status ]; then
164162
batt=${batt%/*}
165163
break
166164
fi
@@ -187,7 +185,7 @@ if ${init:-false}; then
187185

188186
echo 0 > $TMPDIR/.dummy-curr
189187

190-
for currFile in $batt/current_now bms/current_now battery/?attery?verage?urrent \
188+
for currFile in battery/current_now $batt/current_now bms/current_now battery/?attery?verage?urrent \
191189
/sys/devices/platform/battery/power_supply/battery/?attery?verage?urrent \
192190
${battStatus%/*}/current_now $TMPDIR/.dummy-curr
193191
do

module.prop

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
id=acc
22
domain=vr25
33
name=Advanced Charging Controller (ACC)
4-
version=v2024.4.17-rc
5-
versionCode=202404170
4+
version=v2024.4.26-rc
5+
versionCode=202404260
66
author=VR25
77
description=Extend your battery's service life by controlling charging current, temperature, and voltage. Any root solution is supported. The installation is always "systemless". Works on Android and KaiOS.
88
updateJson=https://raw.githubusercontent.com/VR-25/acc/master/module.json

0 commit comments

Comments
 (0)