Skip to content

Commit

Permalink
bat.d/macbook: align tlp-stat -b output
Browse files Browse the repository at this point in the history
* Update docs for function parameters, prerequisites
* Fix debug output
  • Loading branch information
linrunner committed Mar 1, 2024
1 parent 471df97 commit eff16dd
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions bat.d/60-macbook
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ batdrv_init () {
_bt_def_stop=100

# iterate batteries and check for native kernel ACPI
# note: atm we assume only one battery called "macsmc-battery
# note: assume only one battery called "macsmc-battery"
local bd bs
local done=0
local bat_glob="macsmc-battery"
Expand Down Expand Up @@ -157,8 +157,9 @@ batdrv_select_battery () {
# retval: $_bat_str: macsmc-battery;
# $_bt_cfg_bat: config parameter suffix (BAT0);
# $_bd_read: directory with battery data sysfiles;
# $_bf_start: sysfile for stop threshold;
# $_bf_start: sysfile for start threshold;
# $_bf_stop: sysfile for stop threshold;
# $_bf_dischg: sysfile for force-discharge;

# prerequisite: batdrv_init()

Expand Down Expand Up @@ -232,7 +233,7 @@ batdrv_read_threshold () {
esac
if [ -n "$out" ]; then
printf "%s" "$out"
echo_debug "bat" "batdrv.${_batdrv_plugin}.read_threshold($1).simulate: bm_thresh=$_bm_thresh; bf=$bf; out=$out; rc=$rc"
echo_debug "bat" "batdrv.${_batdrv_plugin}.read_threshold($1, $2).simulate: bm_thresh=$_bm_thresh; bf=$bf; out=$out; rc=$rc"
return 0
fi

Expand Down Expand Up @@ -269,7 +270,7 @@ batdrv_read_threshold () {
rc=4
fi

echo_debug "bat" "batdrv.${_batdrv_plugin}.read_threshold($1): bm_thresh=$_bm_thresh; bf=$bf; out=$out; rc=$rc"
echo_debug "bat" "batdrv.${_batdrv_plugin}.read_threshold($1, $2): bm_thresh=$_bm_thresh; bf=$bf; out=$out; rc=$rc"
return $rc
}

Expand Down Expand Up @@ -390,15 +391,18 @@ batdrv_chargeonce () {
# function not implemented
# global param: $_batdrv_plugin
# prerequisite: batdrv_init()

echo_debug "bat" "batdrv.${_batdrv_plugin}.charge_once.not_implemented"
return 255
}

batdrv_apply_configured_thresholds () {
# apply configured stop thresholds from configuration to all batteries
# - called for bg tasks tlp init [re]start/auto and tlp start
# output parameter errors only
# global param: $_batdrv_plugin
# prerequisite: batdrv_init()

if [ "$X_BAT_PLUGIN_SIMULATE" = "$_batdrv_plugin" ]; then
if batdrv_select_battery BAT0; then
batdrv_write_thresholds "$START_CHARGE_THRESH_BAT0" "$STOP_CHARGE_THRESH_BAT0" 1 1; rc=$?
Expand Down Expand Up @@ -462,21 +466,26 @@ batdrv_read_force_discharge () {
batdrv_write_force_discharge () {
# function not implemented
# global param: $_batdrv_plugin
# prerequisite: batdrv_init() echo_debug "bat" "batdrv.${_batdrv_plugin}.write_force_discharge.not_implemented"
# prerequisite: batdrv_init()

echo_debug "bat" "batdrv.${_batdrv_plugin}.write_force_discharge.not_implemented"
return 255
}

batdrv_cancel_force_discharge () {
# function not implemented
# global param: $_batdrv_plugin
# prerequisite: batdrv_init()echo_debug "bat" "batdrv.${_batdrv_plugin}.cancel_force_discharge.not_implemented"
# prerequisite: batdrv_init()

echo_debug "bat" "batdrv.${_batdrv_plugin}.cancel_force_discharge.not_implemented"
return 255
}

batdrv_force_discharge_active () {
# function not implemented
# global param: $_batdrv_plugin
# prerequisite: batdrv_init()

echo_debug "bat" "batdrv.${_batdrv_plugin}.force_discharge_active.not_implemented"
return 255
}
Expand All @@ -498,6 +507,7 @@ batdrv_show_battery_data () {
# $1: 1=verbose
# global param: $_batteries, $_batdrv_kmod, $_bd_read, $_bf_start, $_bf_stop, $_bf_dischg
# prerequisite: batdrv_init()

local verbose=${1:-0}

printf "+++ Battery Care\n"
Expand Down Expand Up @@ -586,12 +596,12 @@ batdrv_show_battery_data () {
# --- show battery features: thresholds, force_discharge
local lf=0
if [ "$_bm_thresh" = "natacpi" ]; then
printf "%-59s = %6s [%%]\n" "$_bf_start" "$(batdrv_read_threshold start 1)"
printf "%-59s = %6s [%%]\n" "$_bf_stop" "$(batdrv_read_threshold stop 1)"
printf "%-69s = %6s [%%]\n" "$_bf_start" "$(batdrv_read_threshold start 1)"
printf "%-69s = %6s [%%]\n" "$_bf_stop" "$(batdrv_read_threshold stop 1)"
lf=1
fi
if [ "$_bm_dischg" = "natacpi" ]; then
printf "%-59s = %6s\n" "$_bf_dischg" "$(batdrv_read_force_discharge 1)"
printf "%-69s = %6s\n" "$_bf_dischg" "$(batdrv_read_force_discharge 1)"
lf=1
fi
[ $lf -gt 0 ] && printf "\n"
Expand Down Expand Up @@ -623,5 +633,6 @@ batdrv_show_battery_data () {

batdrv_recommendations () {
# no recommendations

return 0
}

0 comments on commit eff16dd

Please sign in to comment.