Skip to content

Commit 400e4c6

Browse files
committed
bat.d/thinkpad: fix discharge regression on X220
Reference: * #793
1 parent f6e2628 commit 400e4c6

File tree

1 file changed

+38
-39
lines changed

1 file changed

+38
-39
lines changed

bat.d/05-thinkpad

+38-39
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ batdrv_select_battery () {
270270
# retval: $_bat_str: BAT0/BAT1;
271271
# $_bt_cfg_bat: config suffix = BAT0/BAT1;
272272
# $_bat_idx: 1/2;
273-
# $_bd_read: directory with battery data sysfiles (for tlp-stat);
274-
# $_bd_reada: directory with battery data sysfiles (ACPI);
273+
# $_bd_read: directory with battery data sysfiles;
274+
# $_bd_readsm: directory with battery data sysfiles (tp-smapi);
275275
# $_bf_start: sysfile for start threshold;
276276
# $_bf_stop: sysfile for stop threshold;
277277
# $_bf_dischg: sysfile for force discharge;
@@ -281,7 +281,7 @@ batdrv_select_battery () {
281281
_bat_idx=0 # no index
282282
_bat_str="" # no bat
283283
_bd_read="" # no directories
284-
_bd_reada=""
284+
_bd_readsm=""
285285
_bf_start=""
286286
_bf_stop=""
287287
_bf_dischg=""
@@ -346,16 +346,15 @@ batdrv_select_battery () {
346346
case "$_bm_read" in
347347
natacpi)
348348
_bd_read="$ACPIBATDIR/$bs"
349-
_bd_reada="$ACPIBATDIR/$bs"
350349
;;
351350

352351
tpsmapi)
353-
_bd_read="$SMAPIBATDIR/$bs"
354-
_bd_reada="$ACPIBATDIR/$bs"
352+
_bd_read="$ACPIBATDIR/$bs"
353+
_bd_readsm="$SMAPIBATDIR/$bs"
355354
;;
356355
esac
357356

358-
echo_debug "bat" "batdrv.${_batdrv_plugin}.select_battery($1): bat_str=$_bat_str; cfg=$_bt_cfg_bat; bat_idx=$_bat_idx; bd_read=$_bd_read; bd_reada=$_bd_reada; bf_start=$_bf_start; bf_stop=$_bf_stop; bf_dischg=$_bf_dischg"
357+
echo_debug "bat" "batdrv.${_batdrv_plugin}.select_battery($1): bat_str=$_bat_str; cfg=$_bt_cfg_bat; bat_idx=$_bat_idx; bd_read=$_bd_read; bd_readsm=$_bd_readsm; bf_start=$_bf_start; bf_stop=$_bf_stop; bf_dischg=$_bf_dischg"
359358
return 0
360359
}
361360

@@ -825,12 +824,12 @@ batdrv_force_discharge_active () { # check if battery is in 'force-discharge' st
825824
# prerequisite: batdrv_init(), batdrv_select_battery()
826825

827826
# battery readings to be returned to caller as retvals (and for trace output)
828-
_bat_en="$(perl -e 'printf ("%d", '"$(read_sysval "$_bd_reada/energy_now")"' / 1000.0 );')"
827+
_bat_en="$(perl -e 'printf ("%d", '"$(read_sysval "$_bd_read/energy_now")"' / 1000.0 );')"
829828
_bat_soc="$(batdrv_calc_soc)"
830-
_bat_pwr="$(perl -e 'printf ("%d", '"$(read_sysval "$_bd_reada/power_now")"' / 1000.0 );')"
831-
_bat_volt="$(perl -e 'printf ("%d", '"$(read_sysval "$_bd_reada/voltage_now")"' / 1000.0 );')"
829+
_bat_pwr="$(perl -e 'printf ("%d", '"$(read_sysval "$_bd_read/power_now")"' / 1000.0 );')"
830+
_bat_volt="$(perl -e 'printf ("%d", '"$(read_sysval "$_bd_read/voltage_now")"' / 1000.0 );')"
832831

833-
_bat_st="$(read_sysf "$_bd_reada/status")"
832+
_bat_st="$(read_sysf "$_bd_read/status")"
834833
_bat_fd="$(batdrv_read_force_discharge 0)"
835834
if [ "$_bat_en" -le "$_bat_target_en" ]; then
836835
# target soc reached
@@ -900,9 +899,9 @@ batdrv_discharge () {
900899
return $_bat_dischg_rc
901900
fi
902901
fi
903-
ef="$(perl -e 'printf ("%d", '"$(read_sysval "$_bd_reada/energy_full")"' / 1000.0 );')"
902+
ef="$(perl -e 'printf ("%d", '"$(read_sysval "$_bd_read/energy_full")"' / 1000.0 );')"
904903
_bat_target_en="$(perl -e 'printf ("%d", '"$ef"' * '"$target_soc"' / 100.0)')"
905-
en="$(perl -e 'printf ("%d", '"$(read_sysval "$_bd_reada/energy_now")"' / 1000.0 );')"
904+
en="$(perl -e 'printf ("%d", '"$(read_sysval "$_bd_read/energy_now")"' / 1000.0 );')"
906905
if [ "$_bat_target_en" -ge "$en" ]; then
907906
echo_debug "bat" "batdrv.${_batdrv_plugin}.discharge.target_below_soc($_bat_str): target=$target_soc; soc=$soc"
908907
cprintf "" "Error: target level (%s%%) is too high compared to the actual charge level (%s%%) of battery %s.\n" "$target_soc" "$soc" "$_bat_str" 1>&2
@@ -1014,7 +1013,7 @@ batdrv_show_battery_data () {
10141013
# output battery status
10151014
# $1: 1=verbose
10161015
# global params: $_batdrv_plugin, $_batteries, $_batdrv_kmod, $_natacpi, $_tpsmapi,
1017-
# $_bm_thresh, $_bm_dischg, $_bd_read, $_bf_start, $_bf_stop, $_bf_dischg
1016+
# $_bm_thresh, $_bm_dischg, $_bd_read, $_bd_readsm, $_bf_start, $_bf_stop, $_bf_dischg
10181017
# prerequisite: batdrv_init()
10191018
local verbose="${1:-0}"
10201019

@@ -1133,43 +1132,43 @@ batdrv_show_battery_data () {
11331132
;; # natacpi
11341133

11351134
tpsmapi) # ThinkPad with active tp-smapi
1136-
printparm "%-59s = ##%s##" "$_bd_read/manufacturer"
1137-
printparm "%-59s = ##%s##" "$_bd_read/model"
1138-
printparm "%-59s = ##%s##" "$_bd_read/manufacture_date"
1139-
printparm "%-59s = ##%s##" "$_bd_read/first_use_date"
1140-
printparm "%-59s = ##%6d##" "$_bd_read/cycle_count"
1135+
printparm "%-59s = ##%s##" "$_bd_readsm/manufacturer"
1136+
printparm "%-59s = ##%s##" "$_bd_readsm/model"
1137+
printparm "%-59s = ##%s##" "$_bd_readsm/manufacture_date"
1138+
printparm "%-59s = ##%s##" "$_bd_readsm/first_use_date"
1139+
printparm "%-59s = ##%6d##" "$_bd_readsm/cycle_count"
11411140

1142-
if [ -f "$_bd_read/temperature" ]; then
1141+
if [ -f "$_bd_readsm/temperature" ]; then
11431142
# shellcheck disable=SC2046
1144-
perl -e 'printf ("%-59s = %6d [°C]\n", "'"$_bd_read/temperature"'", '$(read_sysval "$_bd_read/temperature")' / 1000.0);'
1143+
perl -e 'printf ("%-59s = %6d [°C]\n", "'"$_bd_readsm/temperature"'", '$(read_sysval "$_bd_readsm/temperature")' / 1000.0);'
11451144
fi
11461145

1147-
printparm "%-59s = ##%6d## [mWh]" "$_bd_read/design_capacity"
1148-
printparm "%-59s = ##%6d## [mWh]" "$_bd_read/last_full_capacity"
1149-
printparm "%-59s = ##%6d## [mWh]" "$_bd_read/remaining_capacity"
1146+
printparm "%-59s = ##%6d## [mWh]" "$_bd_readsm/design_capacity"
1147+
printparm "%-59s = ##%6d## [mWh]" "$_bd_readsm/last_full_capacity"
1148+
printparm "%-59s = ##%6d## [mWh]" "$_bd_readsm/remaining_capacity"
11501149
if [ "$verbose" -eq 1 ]; then
1151-
printparm "%-59s = ##%6d## [%%]" "$_bd_read/remaining_percent"
1150+
printparm "%-59s = ##%6d## [%%]" "$_bd_readsm/remaining_percent"
11521151
fi
1153-
printparm "%-59s = ##%6s## [min]" "$_bd_read/remaining_running_time_now"
1154-
printparm "%-59s = ##%6s## [min]" "$_bd_read/remaining_charging_time"
1155-
printparm "%-59s = ##%6d## [mW]" "$_bd_read/power_now"
1156-
printparm "%-59s = ##%6d## [mW]" "$_bd_read/power_avg"
1157-
print_batstate "$_bd_read/state"
1152+
printparm "%-59s = ##%6s## [min]" "$_bd_readsm/remaining_running_time_now"
1153+
printparm "%-59s = ##%6s## [min]" "$_bd_readsm/remaining_charging_time"
1154+
printparm "%-59s = ##%6d## [mW]" "$_bd_readsm/power_now"
1155+
printparm "%-59s = ##%6d## [mW]" "$_bd_readsm/power_avg"
1156+
print_batstate "$_bd_readsm/state"
11581157
printf "\n"
11591158
if [ "$verbose" -eq 1 ]; then
1160-
printparm "%-59s = ##%6s## [mV]" "$_bd_read/design_voltage"
1161-
printparm "%-59s = ##%6s## [mV]" "$_bd_read/voltage"
1162-
printparm "%-59s = ##%6s## [mV]" "$_bd_read/group0_voltage"
1163-
printparm "%-59s = ##%6s## [mV]" "$_bd_read/group1_voltage"
1164-
printparm "%-59s = ##%6s## [mV]" "$_bd_read/group2_voltage"
1165-
printparm "%-59s = ##%6s## [mV]" "$_bd_read/group3_voltage"
1159+
printparm "%-59s = ##%6s## [mV]" "$_bd_readsm/design_voltage"
1160+
printparm "%-59s = ##%6s## [mV]" "$_bd_readsm/voltage"
1161+
printparm "%-59s = ##%6s## [mV]" "$_bd_readsm/group0_voltage"
1162+
printparm "%-59s = ##%6s## [mV]" "$_bd_readsm/group1_voltage"
1163+
printparm "%-59s = ##%6s## [mV]" "$_bd_readsm/group2_voltage"
1164+
printparm "%-59s = ##%6s## [mV]" "$_bd_readsm/group3_voltage"
11661165
printf "\n"
11671166
fi
11681167

11691168
# store values for charge / capacity calculation below
1170-
ed=$(read_sysval "$_bd_read/design_capacity")
1171-
ef=$(read_sysval "$_bd_read/last_full_capacity")
1172-
en=$(read_sysval "$_bd_read/remaining_capacity")
1169+
ed=$(read_sysval "$_bd_readsm/design_capacity")
1170+
ef=$(read_sysval "$_bd_readsm/last_full_capacity")
1171+
en=$(read_sysval "$_bd_readsm/remaining_capacity")
11731172
efsum=$((efsum + ef))
11741173
ensum=$((ensum + en))
11751174
;; # tp-smapi

0 commit comments

Comments
 (0)