Post #2723325
2026-05-20 16:41 UTC
I mean, you can take x samples in y time abd average them, but else?
About that, maybe script it nad then display the data in Verve plugin? Iβve created one a few years back but currently donβt use the laptop much, so a bug with calculating the remaining time remains.
#!/bin/sh
#
# pretty-print battery-info and time on shell
# Author: Daniel Frei
# last change: 09.01.2025
battery_path=/sys/class/power_supply/BAT0
timeout1=10
timeout2=5
error() { printf '%s:\t%s\n' "error" "$1" >&2; [ -n "$2" ] && exit "$2"; } # complain to STDERR and exit if given code
# while true; do
# ππ
# reading uevent line for line, because f** idiots and whitespaces in int
while read line; do
IFS='='
set -- $line
case "$1" in
"POWER_SUPPLY_NAME") bat_name="$2"
;; "POWER_SUPPLY_STATUS") bat_state="$2"
;; "POWER_SUPPLY_TYPE") bat_type="$2" # = Battery
;; "POWER_SUPPLY_CAPACITY_LEVEL") bat_warn="$2"
;; "POWER_SUPPLY_CAPACITY") bat_perc="$2"
;; "POWER_SUPPLY_ENERGY_NOW") bat_chrg=$(($2 / 1000))
;; "POWER_SUPPLY_ENERGY_FULL") bat_full=$(($2 / 1000))
;; "POWER_SUPPLY_ENERGY_FULL_DESIGN") bat_chrg_des=$(($2 / 1000))
;; "POWER_SUPPLY_VOLTAGE_NOW") bat_volt=$(($2 / 1000))
;; esac
done < "$battery_path"/uevent
tt_empty=$(((bat_full - bat_now) / bat_volt)) # TODO
tt_full=$(((bat_full + bat_now) / bat_volt)) # TODO
bat_ttef="${tt_empty:-"$tt_full"}h"
# printf 'tt_empty: %s\n' "$tt_empty"
[ -n "$bat_state" ] || [ "$bat_type" = "battery" ] || error "Device has no battery"
fgcol="$(tput setaf 2)" # green
reset="$(tput sgr0)"
symbol="π"
# conditionals
if [ "$bat_state" = "Discharging" ]; then
fgcol="$(tput setaf 1)" # red
symbol="πͺ«"
fi
if [ "$bat_warn" != "Normal" ]; then
fgcol="$(tput setaf 1)" # red
symbol="β "
envwarn "Battery ${bat_name}: ${bat_warn}"
fi
# override bat_ttef only every 2nd time
# if $flipflop; then
string="${fgcol}${bat_perc}%${reset}/${bat_ttef}"
# sleep $timeout1
# flipflop=false
# else
# symbol="π"
# string=" $(date +%R)"
# sleep $timeout2
# flipflop=true
# fi
_time="$(date +%R)"
tput sc # save cursor position
tput cup 0 $(($(tput cols)-20)) # set cursor position
printf "%s %s / %s π\n" "$string" "$symbol" "$_time"
tput rc # reset cursor position
# done
Replies (0)
No replies.