5074a73396570f6c0ee9b6fc079a2df302b367c1
[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("leds"), translate("leds_desc"))
15
16 local sysfs_path = "/sys/class/leds/"
17 local leds = {}
18
19 if luci.fs.access(sysfs_path) then
20 for k, v in pairs(luci.fs.dir(sysfs_path)) do
21 if v ~= "." and v ~= ".." then
22 table.insert(leds, v)
23 end
24 end
25 end
26
27 if #leds == 0 then
28 return m
29 end
30
31
32 s = m:section(TypedSection, "led", "")
33 s.anonymous = true
34 s.addremove = true
35
36 function s.parse(self, ...)
37 TypedSection.parse(self, ...)
38 os.execute("/etc/init.d/led enable")
39 end
40
41
42 s:option(Value, "name")
43
44
45 sysfs = s:option(ListValue, "sysfs")
46 for k, v in ipairs(leds) do
47 sysfs:value(v)
48 end
49
50 s:option(Flag, "default").rmempty = true
51
52
53 trigger = s:option(ListValue, "trigger")
54
55 local triggers = luci.fs.readfile(sysfs_path .. leds[1] .. "/trigger")
56 for t in triggers:gmatch("[%w-]+") do
57 trigger:value(t, translate("system_led_trigger_" .. t:gsub("-", "")))
58 end
59
60
61 delayon = s:option(Value, "delayon")
62 delayon:depends("trigger", "timer")
63
64 delayoff = s:option(Value, "delayoff")
65 delayoff:depends("trigger", "timer")
66
67
68 dev = s:option(ListValue, "dev")
69 dev.rmempty = true
70 dev:value("")
71 dev:depends("trigger", "netdev")
72 for k, v in pairs(luci.sys.net.devices()) do
73 if v ~= "lo" then
74 dev:value(v)
75 end
76 end
77
78
79 mode = s:option(MultiValue, "mode")
80 mode.rmempty = true
81 mode:depends("trigger", "netdev")
82 mode:value("link", translate("system_led_mode_link"))
83 mode:value("tx", translate("system_led_mode_tx"))
84 mode:value("rx", translate("system_led_mode_rx"))
85
86 return m