William Morgan <wmorgan-ruby-talk / masanjin.net> wrote:
> I'm working on a predictive battery monitor in Ruby.
back when I was starting in Ruby one of the first small tries was...
(fix code first, terminal is eating some chars)
run with no window decoration
not very pretty, but does the job till today :-)
Martin
--------------------------------------------------------------------------
$stdout.sync = true
def resize (w,h) # resize terminal
printf("\033[8;#{h};#{w}t")
end
def readme
r1 = IO.readlines("/proc/acpi/battery/BAT1/state").grep(/remaining/)
r1 = /\s*(\d*)\smWh/.match(r1[0])[1].to_s if r1.size == 1
return r1
end
resize (10,1)
r = IO.readlines("/proc/acpi/battery/BAT1/state")
if /present.+no/ === r[0] then
printf("\n no batt ")
sleep 3
exit 1
end
or1 = readme
printf("\n%s 000",or1.rjust(5).tr(" ","0"))
nr1 = readme
loop do
nr1 = readme
if (nr1 != or1)
if or1.to_i <3000 then
'xgamma -gamma 0.3' # <---- fix me!
sleep 0.3
'xgamma -gamma 1.0' # <---- fix me!
end
printf("\n%s %s",nr1.rjust(5).tr(" ","0"),(or1.to_i-nr1.to_i).to_s.rjust(3).tr(" ","0"))
or1 = nr1
end
sleep 15
end