37 lines
605 B
Lua
37 lines
605 B
Lua
|
local backlight = {}
|
||
|
|
||
|
|
||
|
backlight.hooks = {}
|
||
|
backlight.add_hook = function(callback)
|
||
|
backlight.hooks[#backlight.hooks + 1] = callback
|
||
|
end
|
||
|
|
||
|
backlight.exec_hooks = function()
|
||
|
backlight.read(function(status)
|
||
|
for i=1, #backlight.hooks do
|
||
|
backlight.hooks[i](status)
|
||
|
end
|
||
|
end)
|
||
|
end
|
||
|
|
||
|
backlight.read = function(callback)
|
||
|
bin.backlight.get(
|
||
|
function(stdout, stderr, exitreason, exitcode)
|
||
|
callback(tonumber(stdout))
|
||
|
end
|
||
|
)
|
||
|
end
|
||
|
|
||
|
|
||
|
backlight.up = function()
|
||
|
bin.backlight.up()
|
||
|
backlight.exec_hooks()
|
||
|
end
|
||
|
|
||
|
backlight.down = function()
|
||
|
bin.backlight.down()
|
||
|
backlight.exec_hooks()
|
||
|
end
|
||
|
|
||
|
return backlight
|