@@ -29,35 +29,36 @@ batt_info() {
29
29
30
30
# raw battery info from the kernel's battery interface
31
31
info=" $(
32
- { cat $batt /uevent ; printf STATUS =; cat $battStatus ; } \
32
+ { grep . $batt /* 2> /dev/null || : ; printf status =; cat $battStatus ; } \
33
33
| 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/:/=/"
40
41
) "
41
42
42
43
43
44
# determine the correct charging status
44
45
not_charging || :
45
- info=" $( echo " $info " | sed " /^STATUS =/s/=.*/=$_status /" ) "
46
+ info=" $( echo " $info " | sed " /^status =/s/=.*/=$_status /" ) "
46
47
47
48
48
49
# because MediaTek is weird
49
50
[ ! -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 =} "
52
53
}
53
54
54
55
55
56
# 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) "
57
58
58
59
59
60
# 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)
61
62
dtr_conv_factor ${currNow# -} ${ampFactor:- $ampFactor_ }
62
63
currNow=$( calc2 ${currNow:- 0} / $factor )
63
64
@@ -78,7 +79,7 @@ batt_info() {
78
79
79
80
80
81
# 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)
82
83
dtr_conv_factor $voltNow ${voltFactor-}
83
84
voltNow=$( calc2 ${voltNow:- 0} / $factor )
84
85
@@ -91,35 +92,35 @@ batt_info() {
91
92
# print raw battery info
92
93
${verbose:- true} \
93
94
&& echo " $info " \
94
- || echo " $info " | grep -Ev ' ^(CURRENT|VOLTAGE)_NOW ='
95
+ || echo " $info " | grep -Ev ' ^(current|voltage)_now ='
95
96
96
97
# print CURRENT_NOW, VOLTAGE_NOW and POWER_NOW
97
98
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 || :) "
101
102
102
103
103
104
# power supply info
104
105
for i in $( online_f) ; do
105
106
if [ -f $i ] && [ $( cat $i ) -eq 1 ]; then
106
107
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 )
108
109
109
110
echo "
110
- CHARGE_TYPE= $POWER_SUPPLY_TYPE "
111
+ charge_type= $power_supply_type "
111
112
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_ } )
113
114
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 )
118
119
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 "
123
124
fi
124
125
125
126
break
0 commit comments