Merge pull request #288 from rguca/voltage_limit

Voltage limit - bugfix
This commit is contained in:
Mentor Palokaj
2024-06-30 21:58:22 +02:00
committed by GitHub

View File

@@ -4,7 +4,7 @@
## Update management
## variables are used by this binary as well at the update script
## ###############
BATTERY_CLI_VERSION="v1.2.4"
BATTERY_CLI_VERSION="v1.2.5"
# Path fixes for unexpected environments
PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
@@ -79,7 +79,7 @@ Usage:
manually set the adapter to (not) charge even when plugged in
eg: battery adapter off
battery calibrate
battery calibrate
calibrate the battery by discharging it to 15%, then recharging it to 100%, and keeping it there for 1 hour
battery charge LEVEL[1-100]
@@ -143,6 +143,13 @@ function valid_percentage() {
fi
}
function valid_voltage() {
if [[ "$1" =~ ^[0-9]+(\.[0-9]+)?V$ ]]; then
return 0
fi
return 1
}
## #################
## SMC Manipulation
## #################
@@ -653,10 +660,10 @@ if [[ "$action" == "maintain" ]]; then
# Check if setting is a voltage
is_voltage=false
if [[ "$setting" =~ ^[0-9]+(\.[0-9]+)?V$ ]]; then
if valid_voltage "$setting"; then
setting="${setting//V/}"
if [[ "$subsetting" =~ ^[0-9]+(\.[0-9]+)?V$ ]]; then
if valid_voltage "$subsetting"; then
subsetting="${subsetting//V/}"
else
subsetting="0.1"
@@ -672,10 +679,9 @@ if [[ "$action" == "maintain" ]]; then
fi
is_voltage=true
fi
# Check if setting is value between 0 and 100
if ! valid_percentage "$setting"; then
elif ! valid_percentage "$setting"; then
log "Called with $setting $action"
# If non 0-100 setting is not a special keyword, exit with an error.
if ! { [[ "$setting" == "stop" ]] || [[ "$setting" == "recover" ]]; }; then
@@ -686,14 +692,12 @@ if [[ "$action" == "maintain" ]]; then
fi
# Start maintenance script
log "Starting battery maintenance at $setting% $subsetting"
nohup $battery_binary maintain_synchronous $setting $subsetting >>$logfile &
if [ "$is_voltage" = true ]; then
log "Starting battery maintenance at ${setting}V ±${subsetting}V"
nohup battery maintain_voltage_synchronous $setting $subsetting >>$logfile &
nohup $battery_binary maintain_voltage_synchronous $setting $subsetting >>$logfile &
else
log "Starting battery maintenance at $setting% $subsetting"
nohup battery maintain_synchronous $setting $subsetting >>$logfile &
nohup $battery_binary maintain_synchronous $setting $subsetting >>$logfile &
fi
# Store pid of maintenance process and setting