[Zrouter-src] ZRouter.org: push to ZRouter profiles/lua_web_ui/files/etc/www/l...

zrouter-src at zrouter.org zrouter-src at zrouter.org
Mon Sep 24 11:23:52 UTC 2012


details:   http://zrouter.org/hg/zrouter//rev/2b4ab6b5816c
changeset: 467:2b4ab6b5816c
user:      Aleksandr Rybalko <ray at ddteam.net>
date:      Mon Sep 24 14:17:06 2012 +0300
description:
LED control helper.

diffstat:

 profiles/lua_web_ui/files/etc/www/lib/led.lua |  52 +++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)

diffs (56 lines):

diff -r 40667c72ca98 -r 2b4ab6b5816c profiles/lua_web_ui/files/etc/www/lib/led.lua
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/profiles/lua_web_ui/files/etc/www/lib/led.lua	Mon Sep 24 14:17:06 2012 +0300
@@ -0,0 +1,52 @@
+-----------------------------------
+----------- Led Class ------------
+-----------------------------------
+Led = {};
+mtLed = {};
+
+function Led:new(name, invert)
+    led = {};
+
+    if type(name) ~= "string" then return nil; end
+    if not invert or invert == "0" or invert == 0 then
+        invert = false;
+    else
+        invert = true;
+    end
+
+    led.name = name;
+    led.path = "/dev/led/" .. name;
+    led.invert = invert;
+
+    return (setmetatable(led, mtLed));
+end
+
+function Led:new_from_env(name)
+
+    local led = os.getenv(name);
+    local invert = os.getenv(name .. "_INVERT");
+    return (Led:new(led, invert));
+end
+
+function Led:set(mode)
+    local f = io.open(self.path, "w");
+
+    if not f then return nil; end
+
+    if mode == 0 and self.invert then
+        mode = 1;
+    elseif mode == 1 and self.invert then
+        mode = 0;
+    end
+
+    f:write(mode);
+
+    f:close();
+
+    return (true);
+end
+
+mtLed.__index = Led;
+-----------------------------------
+-------- End of Led Class --------
+-----------------------------------


More information about the Zrouter-src mailing list