Created
March 28, 2012 16:26
-
-
Save Mic92/2227970 to your computer and use it in GitHub Desktop.
vicious.contrib.ac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From d917bb927d7a57ff3644dcc61de25b491d4f182e Mon Sep 17 00:00:00 2001 | |
From: jinleileiking <jinleileiking@gmail.com> | |
Date: Thu, 29 Mar 2012 20:36:22 +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 <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 }) | |
-- | |
1.7.9.5 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment