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.
5 Interface with thinkpad battery information
7 Licensed under GNU General Public License v2
8 * (c) 2013, Conor Heine
12 local first_line = require("lain.helpers").first_line
14 local string = { format = string.format }
15 local tonumber = tonumber
16 local setmetatable = setmetatable
20 local apipath = "/sys/devices/platform/smapi"
22 -- Most are readable values, but some can be written to (not implemented, yet?)
25 charging_max_current = true,
26 charging_max_voltage = true,
31 design_capacity = true,
32 design_voltage = true,
34 first_use_date = true,
35 force_discharge = false,
36 group0_voltage = true,
37 group1_voltage = true,
38 group2_voltage = true,
39 group3_voltage = true,
40 inhibit_charge_minutes = false,
42 last_full_capacity = true,
43 manufacture_date = true,
48 remaining_capacity = true,
49 remaining_charging_time = true,
50 remaining_percent = true,
51 remaining_percent_error = true,
52 remaining_running_time = true,
53 remaining_running_time_now = true,
55 start_charge_thresh = false,
57 stop_charge_thresh = false,
62 function smapi:battery(name)
66 bat.path = apipath .. "/" .. name
68 function bat:get(item)
69 return self.path ~= nil and readable[item] and first_line(self.path .. "/" .. item) or nil
72 function bat:installed()
73 return self:get("installed") == "1"
77 return self:get('state')
80 -- Remaining time can either be time until battery dies or time until charging completes
81 function bat:remaining_time()
82 local time_val = bat_now.status == 'discharging' and 'remaining_running_time' or 'remaining_charging_time'
83 local mins_left = self:get(time_val)
85 if mins_left:find("^%d+") == nil
90 local hrs = math.floor(mins_left / 60)
91 local min = mins_left % 60
92 return string.format("%02d:%02d", hrs, min)
95 function bat:percent()
96 return tonumber(self:get("remaining_percent"))
99 return setmetatable(bat, {__metatable = false, __newindex = false})