View Single Post
Posts: 7 | Thanked: 6 times | Joined on Apr 2010 @ outOnTheFields
#163
Originally Posted by dr_frost_dk View Post
--------------------------- Battery Meter --------------------

Heres the Beecon buffer import file and the CODE
Code:
x=$(hal-device | grep voltage.current | 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
...
I'm not sure if this is true for all of you, but "grep voltage.current" will result in two lines for me:

Code:
battery.voltage.current = 4  (0x4)  (int)
battery.voltage.current = 4011  (0xfab)  (int)
and that was resulting in non working script for me (voltage showing as 44,011, percentage as 3257,8, etc..code was putting those two numbers together, and it was making the $1 reference incorrect). I'm not saying, that this is the best solution, and some of the coders out there might find a better way, but i've replaced
Code:
 grep battery.voltage
with
Code:
 grep -E 'voltage.current.+[[:digit:]]{4}'
and that fixed the input/output for me.

I hope this helps someone.

-M.
BTW: thanks for the nice piece of work here.
 

The Following User Says Thank You to miskooldfield For This Useful Post: