Commit ef944b41 authored by Slobodan Todorov's avatar Slobodan Todorov
Browse files

Add option to choose which battery status to get

When ACPI returns multiple batteries, and not all of them related to laptop
battery, this option can be used to specify which battery to be used for
status information. Example of this is Logitech Unifying Receiver, returning
battery information for keyboard/mouse.
parent f89a4274
......@@ -339,6 +339,8 @@ __lp_source_config() {
)
fi
LP_BATTERY_ID=${LP_BATTERY_ID:-0}
# Debugging flags
LP_DEBUG_TIME=${LP_DEBUG_TIME:-0}
......@@ -2343,6 +2345,17 @@ case "$LP_OS" in
(( LP_ENABLE_BATT )) || return 5
local acpi
acpi="$(acpi --battery 2>/dev/null)"
# Check if we want a battery other than the default one
if [[ $LP_BATTERY_ID -gt 0 ]]; then
while IFS=$'\n' read -r line; do
# Find the desired battery by it's ID
if [[ $line =~ Battery\ $LP_BATTERY_ID ]]; then
acpi=$line # Use only desired battery output
fi
done <<<"$acpi"
fi
# Extract the battery load value in percent
# First, remove the beginning of the line...
lp_battery="${acpi#Battery *, }"
......
......@@ -20,6 +20,13 @@
# Recommended value is 75
LP_BATTERY_THRESHOLD=75
# Use particular battery IDwhen multiple batteries are reported by ACPI
# and the default one is wrong.
# Example of such behaviour is when using Logitech Unified Receiver
# and ACPI reports keyboard and mouse batteries first, and laptop battery last
# Run acpi --battery and use Battery # for this value.
LP_BATTERY_ID=0
# Display the load average over the past minute when above this threshold.
# This value is scaled per CPU, so on a quad-core machine, the load average
# would need to be 2.40 or greater to be displayed.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment