All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
4 Licensed under GNU General Public License v2
5 * (c) 2013, Luke Bonham
6 * (c) 2010-2012, Peter Hofmann
10 local newtimer = require("lain.helpers").newtimer
11 local first_line = require("lain.helpers").first_line
13 local naughty = require("naughty")
14 local wibox = require("wibox")
16 local math = { floor = math.floor }
17 local string = { format = string.format }
19 local setmetatable = setmetatable
25 local function worker(args)
26 local args = args or {}
27 local timeout = args.timeout or 30
28 local battery = args.battery or "BAT0"
29 local settings = args.settings or function() end
31 bat.widget = wibox.widget.textbox('')
34 status = "not present",
41 local present = first_line("/sys/class/power_supply/"
47 local rate = first_line("/sys/class/power_supply/"
50 local ratev = first_line("/sys/class/power_supply/"
53 local rem = first_line("/sys/class/power_supply/"
56 local tot = first_line("/sys/class/power_supply/"
59 bat_now.status = first_line("/sys/class/power_supply/"
64 if bat_now.status == "Charging"
66 time_rat = (tot - rem) / rate
67 elseif bat_now.status == "Discharging"
72 local hrs = math.floor(time_rat)
73 local min = (time_rat - hrs) * 60
75 bat_now.time = string.format("%02d:%02d", hrs, min)
76 bat_now.perc = (rem / tot) * 100
77 bat_now.watt = string.format("%.2fW", (rate * ratev) / 1e12)
79 -- notifications for low and critical states
82 bat.id = naughty.notify({
83 text = "shutdown imminent",
84 title = "battery nearly exhausted",
85 position = "top_right",
94 bat.id = naughty.notify({
95 text = "plug the cable",
96 title = "battery low",
97 position = "top_right",
106 bat_now.perc = string.format("%d", bat_now.perc)
113 newtimer("bat", timeout, bat.update)
118 return setmetatable(bat, { __call = function(_, ...) return worker(...) end })