The changes now look OK.
pfr I got a beep once rendomly at 4% will keep testing.
Right. Note that warning-under
and critical-under
are 10% and 1% of the original design capacity. As the battery ages, and the last full capacity decreases, these percentages will creep upwards. envstat
will tell you what the current values are.
pfr How does calling a separate script keep it cleaner?
Well, you can use the same line in sensor_battery
:
test -x /usr/local/bin/alarm.sh && /usr/local/bin/alarm.sh ${2}
and take different actions based on the event. Then, if you want to take more actions later, you can just edit your script instead of fiddling with the system ones.
For instance, let's say you want to sound a klaxon alarm (I'm not saying you should--just hypothetically). Here, you would:
$ youtube-dl -f 140 https://www.youtube.com/watch?v=39rw7dgX1wo
$ ffmpeg -loglevel error -i Submarine\ Dive\ Alarm-39rw7dgX1wo.m4a -t 8 klaxon.wav
and, in the script, you would call:
audioplay /some/path/klaxon.wav
And, if a klaxon blaring is missed, email the user:
mail -s 'Battery critical alert' me <<\EoF
Battery is critical. Shutdown system now.
Alaaaaarm! Awooga! Awooga! Awooga!
EoF
Also, pop-up a message:
xmessage -fn lucidasans-bold-24 -bg Red -fg Ivory -center \
$'Battery is critical.\nShutdown NOW!'
If those are missed, blink the screen:
#!/bin/sh
N=${1:-3}
i=1
cmd_off="/opt/intel_backlight/bin/intel_backlight 0"
cmd_on="/opt/intel_backlight/bin/intel_backlight 86"
while [ $i -le $N ]
do >/dev/null $cmd_off; sleep .75
>/dev/null $cmd_on; sleep .5
i=$((i + 1))
done
Or, in extreme cases, fill the whole screen red:
xterm -fa 'Bitstream Vera Sans Mono:style=Bold' -fs 48 \
-fullscreen -bg Red -fg Ivory -e '
tput blink civis
printf "Battery critical\nShutdown NOW!!!\n" | centre.awk
read x'
centre.awk:
#!/usr/bin/awk -f
{
if (length > MAX)
MAX = length
L[NR] = $0
}
END {
system("tput clear")
cmd = "stty -f /dev/stderr size"
cmd | getline
close(cmd)
if (($1 + 0 < NR) || ($2 + 0 < MAX))
exit 1
row = ($1 - NR) / 2
col = ($2 - MAX) / 2
for (i = 1; i <= NR; i++) {
cmd = sprintf("tput cup %d %d", row++, col)
system(cmd)
printf("%s", L[i])
}
}
Endless possibilities...