mirror of
https://github.com/linuxboot/heads.git
synced 2025-03-14 08:16:44 +00:00
fix show system info battery display in case there is more than 1 battery
show health and charge state for each battery Signed-off-by: gaspar-ilom <gasparilom@riseup.net>
This commit is contained in:
parent
cb8d23c45a
commit
60faa5f05c
@ -1221,17 +1221,21 @@ fromhex_plain() {
|
||||
}
|
||||
|
||||
print_battery_health() {
|
||||
if [ -d /sys/class/power_supply/BAT* ]; then
|
||||
battery_health=$(awk "BEGIN {printf \"%d\", ($(cat /sys/class/power_supply/BAT*/charge_full)/$(cat /sys/class/power_supply/BAT*/charge_full_design)*100)}")
|
||||
echo "$battery_health"
|
||||
fi
|
||||
for battery in /sys/class/power_supply/BAT*; do
|
||||
if [[ -d "${battery}" ]]; then
|
||||
battery_health=$(awk "BEGIN {printf \"%d\", ($(cat "${battery}/charge_full")/$(cat "${battery}/charge_full_design")*100)}")
|
||||
echo "$(basename "${battery}") ${battery_health}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
print_battery_charge() {
|
||||
if [ -d /sys/class/power_supply/BAT* ]; then
|
||||
battery_charge=$(awk "BEGIN {printf \"%d\", ($(cat /sys/class/power_supply/BAT*/charge_now)/$(cat /sys/class/power_supply/BAT*/charge_full)*100)}")
|
||||
echo "$battery_charge"
|
||||
fi
|
||||
for battery in /sys/class/power_supply/BAT*; do
|
||||
if [[ -d "${battery}" ]]; then
|
||||
battery_charge=$(awk "BEGIN {printf \"%d\", ($(cat "${battery}/charge_now")/$(cat "${battery}/charge_full")*100)}")
|
||||
echo "$(basename "${battery}") ${battery_charge}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
generate_random_mac_address() {
|
||||
|
@ -165,11 +165,7 @@ file_selector() {
|
||||
|
||||
show_system_info() {
|
||||
TRACE_FUNC
|
||||
battery_charge="$(print_battery_charge)"
|
||||
battery_health="$(print_battery_health)"
|
||||
if [ -n "$battery_charge" ] && [ -n "$battery_health" ]; then
|
||||
battery_status="\nBattery charge: $battery_charge%\nBattery health: $battery_health%\n"
|
||||
fi
|
||||
battery_status=$(paste <(print_battery_charge) <(print_battery_health) | awk '{printf "\\nBattery %s charge: %s%\\nBattery %s health: %s%", substr($1,4), $2, substr($3,4), $4}; END { if (NR!=0) printf "\\n"}')
|
||||
|
||||
memtotal=$(cat /proc/meminfo | grep 'MemTotal' | tr -s ' ' | cut -f2 -d ' ')
|
||||
memtotal=$((${memtotal} / 1024 / 1024 + 1))
|
||||
|
Loading…
x
Reference in New Issue
Block a user