convert luci.fs users to nixio.fs api
[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 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")
42
43
44 sysfs = s:option(ListValue, "sysfs")
45 for k, v in ipairs(leds) do
46 sysfs:value(v)
47 end
48
49 s:option(Flag, "default").rmempty = true
50
51
52 trigger = s:option(ListValue, "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("system_led_trigger_" .. t:gsub("-", "")))
57 end
58
59
60 delayon = s:option(Value, "delayon")
61 delayon:depends("trigger", "timer")
62
63 delayoff = s:option(Value, "delayoff")
64 delayoff:depends("trigger", "timer")
65
66
67 dev = s:option(ListValue, "dev")
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")
79 mode.rmempty = true
80 mode:depends("trigger", "netdev")
81 mode:value("link", translate("system_led_mode_link"))
82 mode:value("tx", translate("system_led_mode_tx"))
83 mode:value("rx", translate("system_led_mode_rx"))
84
85 return m