add ac plugin
This commit is contained in:
parent
adf4492b43
commit
25b4d528d7
|
@ -18,6 +18,14 @@ could also depend on Lua libraries that are not distributed with the
|
|||
core Lua distribution. Ease of installation and use does not
|
||||
necessarily have to apply to contributed widgets.
|
||||
|
||||
vicious.contrib.ac
|
||||
- provide status about the power supply (AC)
|
||||
- takes the AC device as an argument, i.e "AC" or "ACAD"
|
||||
- the device is linked under /sys/class/power_supply/ and should
|
||||
have a file called "online"
|
||||
- if AC is connected, $1 returns "On", if not it returns "Off",
|
||||
if AC doesn't exist, $1 is "N/A"
|
||||
|
||||
vicious.contrib.batacpi
|
||||
-
|
||||
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
---------------------------------------------------
|
||||
-- Licensed under the GNU General Public License v2
|
||||
-- * (c) 2012, jinleileiking <jinleileiking@gmail.com>
|
||||
---------------------------------------------------
|
||||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local setmetatable = setmetatable
|
||||
local string = { format = string.format }
|
||||
local helpers = require("vicious.helpers")
|
||||
local math = {
|
||||
min = math.min,
|
||||
floor = math.floor
|
||||
}
|
||||
-- }}}
|
||||
|
||||
module("vicious.contrib.ac")
|
||||
|
||||
-- {{{ AC widget type
|
||||
local function worker(format, warg)
|
||||
local ac = helpers.pathtotable("/sys/class/power_supply/"..warg)
|
||||
|
||||
local state = ac.online
|
||||
if state == nil then
|
||||
return {"N/A"}
|
||||
elseif state == "1\n" then
|
||||
return {"On"}
|
||||
else
|
||||
return {"Off"}
|
||||
end
|
||||
end
|
||||
-- }}}
|
||||
|
||||
|
||||
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
|
Loading…
Reference in New Issue