2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
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
10 http://www.apache.org/licenses/LICENSE-2.0
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."))
16 local sysfs_path = "/sys/class/leds/"
19 local fs = require "nixio.fs"
20 local util = require "nixio.util"
22 if fs.access(sysfs_path) then
23 leds = util.consume((fs.dir(sysfs_path)))
31 s = m:section(TypedSection, "led", "")
35 function s.parse(self, ...)
36 TypedSection.parse(self, ...)
37 os.execute("/etc/init.d/led enable")
41 s:option(Value, "name", translate("Name"))
44 sysfs = s:option(ListValue, "sysfs", translate("<abbr title=\"Light Emitting Diode\">LED</abbr> Name"))
45 for k, v in ipairs(leds) do
49 s:option(Flag, "default", translate("Default state")).rmempty = false
52 trigger = s:option(ListValue, "trigger", translate("Trigger"))
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("-", "")))
60 delayon = s:option(Value, "delayon", translate ("On-State Delay"))
61 delayon:depends("trigger", "timer")
63 delayoff = s:option(Value, "delayoff", translate ("Off-State Delay"))
64 delayoff:depends("trigger", "timer")
67 dev = s:option(ListValue, "_net_dev", translate("Device"))
70 dev:depends("trigger", "netdev")
72 function dev.cfgvalue(self, section)
73 return m.uci:get("system", section, "dev")
76 function dev.write(self, section, value)
77 m.uci:set("system", section, "dev", value)
80 function dev.remove(self, section)
81 local t = trigger:formvalue(section)
82 if t ~= "netdev" and t ~= "usbdev" then
83 m.uci:delete("system", section, "dev")
87 for k, v in pairs(luci.sys.net.devices()) do
94 mode = s:option(MultiValue, "mode", translate("Trigger Mode"))
96 mode:depends("trigger", "netdev")
97 mode:value("link", translate("Link On"))
98 mode:value("tx", translate("Transmit"))
99 mode:value("rx", translate("Receive"))
102 usbdev = s:option(ListValue, "_usb_dev", translate("USB Device"))
103 usbdev:depends("trigger", "usbdev")
104 usbdev.rmempty = true
107 function usbdev.cfgvalue(self, section)
108 return m.uci:get("system", section, "dev")
111 function usbdev.write(self, section, value)
112 m.uci:set("system", section, "dev", value)
115 function usbdev.remove(self, section)
116 local t = trigger:formvalue(section)
117 if t ~= "netdev" and t ~= "usbdev" then
118 m.uci:delete("system", section, "dev")
122 for p in nixio.fs.glob("/sys/bus/usb/devices/[0-9]*/manufacturer") do
123 local id = p:match("%d+-%d+")
124 local mf = nixio.fs.readfile("/sys/bus/usb/devices/" .. id .. "/manufacturer") or "?"
125 local pr = nixio.fs.readfile("/sys/bus/usb/devices/" .. id .. "/product") or "?"
126 usbdev:value(id, "%s (%s - %s)" %{ id, mf, pr })