2008-08-07 00:57:20 +00:00
--[[
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth < steven @ midlink.org >
Licensed under the Apache License , Version 2.0 ( the " License " ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : // www.apache . org / licenses / LICENSE - 2.0
$ Id $
] ] --
2009-10-31 15:54:11 +00:00
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. " ) )
2008-08-07 00:57:20 +00:00
2008-08-07 11:45:19 +00:00
local sysfs_path = " /sys/class/leds/ "
local leds = { }
2009-07-19 00:24:58 +00:00
local fs = require " nixio.fs "
local util = require " nixio.util "
if fs.access ( sysfs_path ) then
leds = util.consume ( ( fs.dir ( sysfs_path ) ) )
2008-08-07 11:45:19 +00:00
end
if # leds == 0 then
return m
end
2008-08-07 00:57:20 +00:00
s = m : section ( TypedSection , " led " , " " )
s.anonymous = true
s.addremove = true
2008-08-07 11:45:19 +00:00
function s . parse ( self , ... )
TypedSection.parse ( self , ... )
os.execute ( " /etc/init.d/led enable " )
end
2008-08-07 00:57:20 +00:00
2010-07-01 09:52:27 +00:00
s : option ( Value , " name " , translate ( " Name " ) )
2008-08-07 00:57:20 +00:00
2008-08-07 11:45:19 +00:00
2010-07-01 09:52:27 +00:00
sysfs = s : option ( ListValue , " sysfs " , translate ( " <abbr title= \" Light Emitting Diode \" >LED</abbr> Name " ) )
2008-08-07 11:45:19 +00:00
for k , v in ipairs ( leds ) do
sysfs : value ( v )
2008-08-07 00:57:20 +00:00
end
2010-07-01 09:52:27 +00:00
s : option ( Flag , " default " , translate ( " Default state " ) ) . rmempty = true
2008-08-07 00:57:20 +00:00
2008-08-07 11:45:19 +00:00
2010-07-01 09:52:27 +00:00
trigger = s : option ( ListValue , " trigger " , translate ( " Trigger " ) )
2008-08-07 11:45:19 +00:00
2009-07-19 00:24:58 +00:00
local triggers = fs.readfile ( sysfs_path .. leds [ 1 ] .. " /trigger " )
2008-08-07 11:45:19 +00:00
for t in triggers : gmatch ( " [%w-]+ " ) do
2009-11-01 13:19:57 +00:00
trigger : value ( t , translate ( t : gsub ( " - " , " " ) ) )
2008-08-07 11:45:19 +00:00
end
2010-07-01 09:52:27 +00:00
delayon = s : option ( Value , " delayon " , translate ( " On-State Delay " ) )
2008-08-07 11:45:19 +00:00
delayon : depends ( " trigger " , " timer " )
2010-07-01 09:52:27 +00:00
delayoff = s : option ( Value , " delayoff " , translate ( " Off-State Delay " ) )
2008-08-07 11:45:19 +00:00
delayoff : depends ( " trigger " , " timer " )
2008-08-07 00:57:20 +00:00
2010-07-01 09:52:27 +00:00
dev = s : option ( ListValue , " dev " , translate ( " Device " ) )
2008-08-07 00:57:20 +00:00
dev.rmempty = true
dev : value ( " " )
dev : depends ( " trigger " , " netdev " )
for k , v in pairs ( luci.sys . net.devices ( ) ) do
if v ~= " lo " then
dev : value ( v )
end
end
2008-08-07 11:45:19 +00:00
2010-07-01 09:52:27 +00:00
mode = s : option ( MultiValue , " mode " , translate ( " Trigger Mode " ) )
2008-08-07 00:57:20 +00:00
mode.rmempty = true
mode : depends ( " trigger " , " netdev " )
2009-10-31 15:54:11 +00:00
mode : value ( " link " , translate ( " Link On " ) )
mode : value ( " tx " , translate ( " Transmit " ) )
mode : value ( " rx " , translate ( " Receive " ) )
2008-08-07 11:45:19 +00:00
2009-07-19 00:24:58 +00:00
return m