View Single Post
Posts: 7 | Thanked: 6 times | Joined on Apr 2010 @ outOnTheFields
#170
make a file,
nano /home/user/MyDocs/tmp/batteryCheck.sh
paste this in
x=$(hal-device | grep -E 'voltage.current.+[[:digit:]]{4}' | awk '{printf "%4.0f",$3}')
if [ $x -ge 4050 ];then
echo $x | awk '{printf "%1.3fV - %3.1f", $1 / 1000, 85 + ($1 - 4050) / 12}{print "%"}'
exit 0;fi
if [ $x -ge 3900 -a $x -lt 4050 ];then
echo $x | awk '{printf "%1.3fV - %3.1f", $1 / 1000, 70 + ($1 - 3900) / 10}{print "%"}'
exit 0;fi
if [ $x -ge 3800 -a $x -lt 3900 ];then
echo $x | awk '{printf "%1.3fV - %3.1f", $1 / 1000, 50 + ($1 - 3800) / 5}{print "%"}'
exit 0;fi
if [ $x -ge 3660 -a $x -lt 3800 ];then
echo $x | awk '{printf "%1.3fV - %3.1f", $1 / 1000, 15 + ($1 - 3660) / 4}{print "%"}'
exit 1;fi
if [ $x -ge 3600 -a $x -lt 3660 ];then
echo $x | awk '{printf "%1.3fV - %3.1f", $1 / 1000, 5 + ($1 - 3600) / 6}{print "%"}'
exit 2;fi
if [ $x -lt 3600 ];then
echo $x | awk '{printf "%1.3fV - %3.1f", $1 / 1000, ($1 - 3300) / 60}{print "%"}'
exit 3;fi
save, exit nano
change file permission; set "executable"
chmod +x /home/user/MyDocs/tmp/batteryCheck.sh
and run the script with
sh /home/user/MyDocs/tmp/batteryCheck.sh
if you want, you can put this script into the usr/bin with
cp /home/user/MyDocs/tmp/batteryCheck.sh /usr/bin/
and launch via
batteryCheck
in terminal.

I hope that is what you wanted.
-M.

Forgot this:
if you wnat just percentage, then use this code instead of the first one:
x=$(hal-device | grep -E 'voltage.current.+[[:digit:]]{4}' | awk '{printf "%4.0f",$3}')
if [ $x -ge 4050 ];then
echo $x | awk '{printf "%3.1f", $1 / 1000, 85 + ($1 - 4050) / 12}{print "%"}'
exit 0;fi
if [ $x -ge 3900 -a $x -lt 4050 ];then
echo $x | awk '{printf "%3.1f", $1 / 1000, 70 + ($1 - 3900) / 10}{print "%"}'
exit 0;fi
if [ $x -ge 3800 -a $x -lt 3900 ];then
echo $x | awk '{printf "%3.1f", $1 / 1000, 50 + ($1 - 3800) / 5}{print "%"}'
exit 0;fi
if [ $x -ge 3660 -a $x -lt 3800 ];then
echo $x | awk '{printf "%3.1f", $1 / 1000, 15 + ($1 - 3660) / 4}{print "%"}'
exit 1;fi
if [ $x -ge 3600 -a $x -lt 3660 ];then
echo $x | awk '{printf "%3.1f", $1 / 1000, 5 + ($1 - 3600) / 6}{print "%"}'
exit 2;fi
if [ $x -lt 3600 ];then
echo $x | awk '{printf "%3.1f", $1 / 1000, ($1 - 3300) / 60}{print "%"}'
exit 3;fi
this one results in 18.0% instead of 4.011V - 92.3%

Last edited by miskooldfield; 2011-01-18 at 18:22.
 

The Following 2 Users Say Thank You to miskooldfield For This Useful Post: