ad2a5bd980166e9c39491155ce31be4e4f03d763
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_system / leds.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14 m = Map("system", translate("<abbr title=\"Light Emitting Diode\">LED</abbr> Configuration"), translate("Customizes the behaviour of the device <abbr title=\"Light Emitting Diode\">LED</abbr>s if possible."))
15
16 local sysfs_path = "/sys/class/leds/"
17 local leds = {}
18
19 local fs   = require "nixio.fs"
20 local util = require "nixio.util"
21
22 if fs.access(sysfs_path) then
23         leds = util.consume((fs.dir(sysfs_path)))
24 end
25
26 if #leds == 0 then
27         return m
28 end
29
30
31 s = m:section(TypedSection, "led", "")
32 s.anonymous = true
33 s.addremove = true
34
35 function s.parse(self, ...)
36         TypedSection.parse(self, ...)
37         os.execute("/etc/init.d/led enable")
38 end
39
40
41 s:option(Value, "name", translate("Name"))
42
43
44 sysfs = s:option(ListValue, "sysfs", translate("<abbr title=\"Light Emitting Diode\">LED</abbr> Name"))
45 for k, v in ipairs(leds) do
46         sysfs:value(v)
47 end
48
49 s:option(Flag, "default", translate("Default state")).rmempty = true
50
51
52 trigger = s:option(ListValue, "trigger", translate("Trigger"))
53
54 local triggers = fs.readfile(sysfs_path .. leds[1] .. "/trigger")
55 for t in triggers:gmatch("[%w-]+") do
56         trigger:value(t, translate(t:gsub("-", "")))
57 end 
58
59
60 delayon = s:option(Value, "delayon", translate ("On-State Delay"))
61 delayon:depends("trigger", "timer")
62
63 delayoff = s:option(Value, "delayoff", translate ("Off-State Delay"))
64 delayoff:depends("trigger", "timer")
65
66
67 dev = s:option(ListValue, "dev", translate("Device"))
68 dev.rmempty = true
69 dev:value("")
70 dev:depends("trigger", "netdev")
71 for k, v in pairs(luci.sys.net.devices()) do
72         if v ~= "lo" then
73                 dev:value(v)
74         end
75 end
76
77
78 mode = s:option(MultiValue, "mode", translate("Trigger Mode"))
79 mode.rmempty = true
80 mode:depends("trigger", "netdev")
81 mode:value("link", translate("Link On"))
82 mode:value("tx", translate("Transmit"))
83 mode:value("rx", translate("Receive"))
84
85 return m