2015-01-16 22:38:38 +00:00
-- Copyright 2008 Steven Barth <steven@midlink.org>
-- Licensed to the public under the Apache License 2.0.
2008-08-07 00:57:20 +00:00
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 "
2017-01-30 14:50:08 +00:00
local nu = require " nixio.util "
local util = require " luci.util "
2009-07-19 00:24:58 +00:00
if fs.access ( sysfs_path ) then
2017-01-30 14:50:08 +00:00
leds = nu.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
2011-04-25 19:56:10 +00:00
s : option ( Flag , " default " , translate ( " Default state " ) ) . rmempty = false
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 ( " - " , " " ) ) )
2011-04-25 19:56:10 +00:00
end
2008-08-07 11:45:19 +00:00
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
2018-11-09 10:03:36 +00:00
dev = s : option ( Value , " _net_dev " , translate ( " Device " ) )
2008-08-07 00:57:20 +00:00
dev.rmempty = true
dev : value ( " " )
dev : depends ( " trigger " , " netdev " )
2011-04-25 19:54:32 +00:00
function dev . cfgvalue ( self , section )
return m.uci : get ( " system " , section , " dev " )
end
function dev . write ( self , section , value )
m.uci : set ( " system " , section , " dev " , value )
end
function dev . remove ( self , section )
local t = trigger : formvalue ( section )
if t ~= " netdev " and t ~= " usbdev " then
m.uci : delete ( " system " , section , " dev " )
end
end
2008-08-07 00:57:20 +00:00
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
2011-04-25 19:54:32 +00:00
usbdev = s : option ( ListValue , " _usb_dev " , translate ( " USB Device " ) )
usbdev : depends ( " trigger " , " usbdev " )
usbdev.rmempty = true
usbdev : value ( " " )
function usbdev . cfgvalue ( self , section )
return m.uci : get ( " system " , section , " dev " )
end
function usbdev . write ( self , section , value )
m.uci : set ( " system " , section , " dev " , value )
end
function usbdev . remove ( self , section )
local t = trigger : formvalue ( section )
if t ~= " netdev " and t ~= " usbdev " then
m.uci : delete ( " system " , section , " dev " )
end
end
2017-01-25 23:08:43 +00:00
2017-01-30 14:50:08 +00:00
usbport = s : option ( MultiValue , " port " , translate ( " USB Ports " ) )
2017-01-25 23:08:43 +00:00
usbport : depends ( " trigger " , " usbport " )
usbport.rmempty = true
usbport.widget = " checkbox "
2017-01-30 14:50:08 +00:00
usbport.cast = " table "
2017-01-25 23:08:43 +00:00
usbport.size = 1
2017-01-30 14:50:08 +00:00
function usbport . valuelist ( self , section )
local port , ports = nil , { }
for port in util.imatch ( m.uci : get ( " system " , section , " port " ) ) do
local b , n = port : match ( " ^usb(%d+)-port(%d+)$ " )
if not ( b and n ) then
b , n = port : match ( " ^(%d+)-(%d+)$ " )
end
if b and n then
ports [ # ports + 1 ] = " usb%u-port%u " % { tonumber ( b ) , tonumber ( n ) }
end
end
return ports
end
function usbport . validate ( self , value )
return type ( value ) == " string " and { value } or value
end
2011-04-25 19:54:32 +00:00
for p in nixio.fs . glob ( " /sys/bus/usb/devices/[0-9]*/manufacturer " ) do
local id = p : match ( " %d+-%d+ " )
2011-05-09 12:51:01 +00:00
local mf = nixio.fs . readfile ( " /sys/bus/usb/devices/ " .. id .. " /manufacturer " ) or " ? "
local pr = nixio.fs . readfile ( " /sys/bus/usb/devices/ " .. id .. " /product " ) or " ? "
2011-04-25 19:54:32 +00:00
usbdev : value ( id , " %s (%s - %s) " % { id , mf , pr } )
end
2017-01-30 14:50:08 +00:00
for p in nixio.fs . glob ( " /sys/bus/usb/devices/*/usb[0-9]*-port[0-9]* " ) do
local bus , port = p : match ( " usb(%d+)-port(%d+) " )
2017-01-25 23:08:43 +00:00
if bus and port then
usbport : value ( " usb%u-port%u " % { tonumber ( bus ) , tonumber ( port ) } ,
" Hub %u, Port %u " % { tonumber ( bus ) , tonumber ( port ) } )
end
end
2017-12-21 14:04:00 +00:00
port_mask = s : option ( Value , " port_mask " , translate ( " Switch Port Mask " ) )
port_mask : depends ( " trigger " , " switch0 " )
2009-07-19 00:24:58 +00:00
return m