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
19 local apipath = "/sys/devices/platform/smapi"
21 -- Most are readable values, but some can be written to (not implemented, yet?)
24 charging_max_current = true,
25 charging_max_voltage = true,
30 design_capacity = true,
31 design_voltage = true,
33 first_use_date = true,
34 force_discharge = false,
35 group0_voltage = true,
36 group1_voltage = true,
37 group2_voltage = true,
38 group3_voltage = true,
39 inhibit_charge_minutes = false,
41 last_full_capacity = true,
42 manufacture_date = true,
47 remaining_capacity = true,
48 remaining_charging_time = true,
49 remaining_percent = true,
50 remaining_percent_error = true,
51 remaining_running_time = true,
52 remaining_running_time_now = true,
54 start_charge_thresh = false,
56 stop_charge_thresh = false,
61 function smapi:battery(name)
65 bat.path = apipath .. "/" .. name
67 function bat:get(item)
68 return self.path ~= nil and readable[item] and first_line(self.path .. "/" .. item) or nil
71 function bat:installed()
72 return self:get("installed") == "1"
76 return self:get('state')
79 -- Remaining time can either be time until battery dies or time until charging completes
80 function bat:remaining_time()
81 local time_val = bat_now.status == 'discharging' and 'remaining_running_time' or 'remaining_charging_time'
82 local mins_left = self:get(time_val)
84 if mins_left:find("^%d+") == nil
89 local hrs = math.floor(mins_left / 60)
90 local min = mins_left % 60
91 return string.format("%02d:%02d", hrs, min)
94 function bat:percent()
95 return tonumber(self:get("remaining_percent"))
98 return setmetatable(bat, {__metatable = false, __newindex = false})