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].

Reply via email to