On Tue, Jul 7, 2009 at 9:06 AM, Giorgio Lando <[email protected]> wrote:
> This is my function:
>
> function batteryInfo(device)
> local fcur =
> io.open("/sys/class/power_supply/"..device.."/energy_now")
> local fcap =
> io.open("/sys/class/power_supply/"..device.."/energy_full")
> local fsta = io.open("/sys/class/power_supply/"..device.."/status")
> local cur = fcur:read()
> local cap = fcap:read()
> local sta = fsta:read()
> local battery = math.floor(cur * 100 / cap)
> if sta:match("Charging") then
> dir = '<span color="green">^</span>'
> battery = "AC ("..battery.."%)"
> elseif sta:match("Discharging") then
> dir = '<span color="red">v</span>'
> if tonumber(battery) < 25 then
> if tonumber(battery) < 10 then
> battery = '<span color="red"
> font-weight="bold">'..battery..'%</span>'
> else
> battery = '<span
> color="red">'..battery..'%</span>'
> end
> else
> battery = battery .. "%"
> end
> else
> dir = "="
> battery = "AC"
> end
> batterywidget.text = ' <span color="yellow">B</span>: ' .. dir ..
> " " .. battery .. " "
> fcur:close()
> fcap:close()
> fsta:close()
> end
>
> My widget definition:
>
> batterywidget = widget({type = "textbox", name = "batterywidget",
> align="right" })
>
> And my timer:
>
> awful.hooks.timer.register(3, function()
> batteryInfo("BAT1")
> end)
>
> --
> To unsubscribe, send mail to [email protected].
>
Nice one Giorgio!
FYI my batt name is C1BE, the curr file is
/sys/class/power_supply/C1BE/charge_now and the full file is
/sys/class/power_supply/C1BE/charge_full
Would be nice if we can find some kind of abstraction (my blatant attempt -
using a command! - was about that), since the code becomes hardware
dependant.
--
Saludos,
Germán
Delivering common sense since 1969 <Epoch Fail!>.
The Nature is not amiable; It treats impartially to all the things. The wise
person is not amiable; He treats all people impartially.