From 25b4d528d797ead9c1bc6a1d73c4cc54c57b3acd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 1 Apr 2012 14:55:49 +0200 Subject: [PATCH] add ac plugin --- contrib/README | 8 ++++++++ contrib/ac.lua | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 contrib/ac.lua diff --git a/contrib/README b/contrib/README index 16716ac..010cfc3 100644 --- a/contrib/README +++ b/contrib/README @@ -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 - diff --git a/contrib/ac.lua b/contrib/ac.lua new file mode 100644 index 0000000..67b3a1e --- /dev/null +++ b/contrib/ac.lua @@ -0,0 +1,35 @@ +--------------------------------------------------- +-- Licensed under the GNU General Public License v2 +-- * (c) 2012, jinleileiking +--------------------------------------------------- + +-- {{{ 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 })