changeset 467:2b4ab6b5816c

LED control helper.
author Aleksandr Rybalko <ray@ddteam.net>
date Mon, 24 Sep 2012 14:17:06 +0300
parents 40667c72ca98
children f533387b0dd6
files profiles/lua_web_ui/files/etc/www/lib/led.lua
diffstat 1 files changed, 52 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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 --------
+-----------------------------------