turned evmgr into a module
modules that require getting events will need to have "evmgr" as a dependency
This commit is contained in:
@@ -70,6 +70,7 @@ require("/halyde/kernel/modload.lua")
|
|||||||
package.preload("component")
|
package.preload("component")
|
||||||
package.preload("computer")
|
package.preload("computer")
|
||||||
package.preload("log")
|
package.preload("log")
|
||||||
|
package.preload("event")
|
||||||
|
|
||||||
if not filesystem.exists("/halyde/config/startupapps.json") then
|
if not filesystem.exists("/halyde/config/startupapps.json") then
|
||||||
filesystem.copy("/halyde/config/generate/startupapps.json", "/halyde/config/startupapps.json")
|
filesystem.copy("/halyde/config/generate/startupapps.json", "/halyde/config/startupapps.json")
|
||||||
|
|||||||
@@ -1,65 +0,0 @@
|
|||||||
_G.evmgr = {}
|
|
||||||
_G.evmgr.eventQueue = {}
|
|
||||||
local maxEventQueueLength = 10 -- increase if events start getting dropped
|
|
||||||
|
|
||||||
local computer = require("computer")
|
|
||||||
|
|
||||||
local ctrlDown = false
|
|
||||||
local altDown = false
|
|
||||||
local shiftDown = false
|
|
||||||
|
|
||||||
function _G._PUBLIC.keyboard.getCtrlDown()
|
|
||||||
return ctrlDown
|
|
||||||
end
|
|
||||||
function _G._PUBLIC.keyboard.getAltDown()
|
|
||||||
return altDown
|
|
||||||
end
|
|
||||||
function _G._PUBLIC.keyboard.getShiftDown()
|
|
||||||
return shiftDown
|
|
||||||
end
|
|
||||||
|
|
||||||
--local ocelot = component.proxy(component.list("ocelot")())
|
|
||||||
|
|
||||||
while true do
|
|
||||||
local args
|
|
||||||
repeat
|
|
||||||
args = {computer.uptime(), computer.pullSignal(0)}
|
|
||||||
if args and args[2] then
|
|
||||||
table.insert(evmgr.eventQueue, args)
|
|
||||||
if _PUBLIC.keyboard then
|
|
||||||
if args[2] == "key_down" then
|
|
||||||
local keycode = args[5]
|
|
||||||
local key = _PUBLIC.keyboard.keys[keycode]
|
|
||||||
if key == "lcontrol" then
|
|
||||||
ctrlDown = true
|
|
||||||
elseif key == "lmenu" then
|
|
||||||
altDown = true
|
|
||||||
elseif key == "lshift" then
|
|
||||||
shiftDown = true
|
|
||||||
elseif key == "c" and ctrlDown and altDown then
|
|
||||||
if print then
|
|
||||||
print("\n\27[91mCoroutine "..tostring(#tsched.tasks).." killed.")
|
|
||||||
end
|
|
||||||
table.remove(tsched.tasks, #tsched.tasks)
|
|
||||||
end
|
|
||||||
elseif args[2] == "key_up" then
|
|
||||||
local keycode = args[5]
|
|
||||||
local key = _PUBLIC.keyboard.keys[keycode]
|
|
||||||
if key == "lcontrol" then
|
|
||||||
ctrlDown = false
|
|
||||||
elseif key == "lmenu" then
|
|
||||||
altDown = false
|
|
||||||
elseif key == "lshift" then
|
|
||||||
shiftDown = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
while #evmgr.eventQueue > maxEventQueueLength do
|
|
||||||
--ocelot.log("Queue length breach, removing first signal")
|
|
||||||
table.remove(evmgr.eventQueue, 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
until not args or not args[1]
|
|
||||||
--ocelot.log("done")
|
|
||||||
coroutine.yield()
|
|
||||||
end
|
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
local module = {}
|
||||||
|
|
||||||
|
module.dependencies = { "tsched", "keyboard" }
|
||||||
|
|
||||||
|
function module.check()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local process
|
||||||
|
|
||||||
|
function module.init()
|
||||||
|
_G.evmgr = {}
|
||||||
|
_G.evmgr.eventQueue = {}
|
||||||
|
local maxEventQueueLength = 10 -- increase if events start getting dropped
|
||||||
|
|
||||||
|
local computer = require("computer")
|
||||||
|
|
||||||
|
local ctrlDown = false
|
||||||
|
local altDown = false
|
||||||
|
local shiftDown = false
|
||||||
|
|
||||||
|
function _G._PUBLIC.keyboard.getCtrlDown()
|
||||||
|
return ctrlDown
|
||||||
|
end
|
||||||
|
function _G._PUBLIC.keyboard.getAltDown()
|
||||||
|
return altDown
|
||||||
|
end
|
||||||
|
function _G._PUBLIC.keyboard.getShiftDown()
|
||||||
|
return shiftDown
|
||||||
|
end
|
||||||
|
|
||||||
|
_, process = _PUBLIC.tsched.addTask(function()
|
||||||
|
while true do
|
||||||
|
local args
|
||||||
|
repeat
|
||||||
|
args = { computer.uptime(), computer.pullSignal(0) }
|
||||||
|
if args and args[2] then
|
||||||
|
table.insert(evmgr.eventQueue, args)
|
||||||
|
if _PUBLIC.keyboard then
|
||||||
|
if args[2] == "key_down" then
|
||||||
|
local keycode = args[5]
|
||||||
|
local key = _PUBLIC.keyboard.keys[keycode]
|
||||||
|
if key == "lcontrol" then
|
||||||
|
ctrlDown = true
|
||||||
|
elseif key == "lmenu" then
|
||||||
|
altDown = true
|
||||||
|
elseif key == "lshift" then
|
||||||
|
shiftDown = true
|
||||||
|
elseif key == "c" and ctrlDown and altDown then
|
||||||
|
if print then
|
||||||
|
print("\n\27[91mCoroutine " .. tostring(#tsched.tasks) .. " killed.")
|
||||||
|
end
|
||||||
|
table.remove(tsched.tasks, #tsched.tasks)
|
||||||
|
end
|
||||||
|
elseif args[2] == "key_up" then
|
||||||
|
local keycode = args[5]
|
||||||
|
local key = _PUBLIC.keyboard.keys[keycode]
|
||||||
|
if key == "lcontrol" then
|
||||||
|
ctrlDown = false
|
||||||
|
elseif key == "lmenu" then
|
||||||
|
altDown = false
|
||||||
|
elseif key == "lshift" then
|
||||||
|
shiftDown = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
while #evmgr.eventQueue > maxEventQueueLength do
|
||||||
|
--ocelot.log("Queue length breach, removing first signal")
|
||||||
|
table.remove(evmgr.eventQueue, 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
until not args or not args[1]
|
||||||
|
--ocelot.log("done")
|
||||||
|
coroutine.yield()
|
||||||
|
end
|
||||||
|
end, "evmgr")
|
||||||
|
end
|
||||||
|
|
||||||
|
function module.exit()
|
||||||
|
_G.evmgr = nil
|
||||||
|
_PUBLIC.tsched.removeTask(process.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
return module
|
||||||
@@ -39,33 +39,6 @@ local function runTasks()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function taskFunction()
|
|
||||||
local result, errorMessage = xpcall(function()
|
|
||||||
if not filesystem.exists("/halyde/kernel/evmgr.lua") then
|
|
||||||
error("No such file: /halyde/kernel/evmgr.lua")
|
|
||||||
end
|
|
||||||
local handle, data, tmpdata = filesystem.open("/halyde/kernel/evmgr.lua"), "", nil
|
|
||||||
repeat
|
|
||||||
tmpdata = handle:read(math.huge or math.maxinteger)
|
|
||||||
data = data .. (tmpdata or "")
|
|
||||||
until not tmpdata
|
|
||||||
handle:close()
|
|
||||||
assert(load(data, "=/halyde/kernel/evmgr.lua"))()
|
|
||||||
end, function(errorMessage)
|
|
||||||
return errorMessage .. "\n \n" .. debug.traceback()
|
|
||||||
end, "/halyde/kernel/evmgr.lua")
|
|
||||||
if not result then
|
|
||||||
if print then
|
|
||||||
gpu.freeAllBuffers()
|
|
||||||
print("\n\27[91m" .. errorMessage)
|
|
||||||
else
|
|
||||||
error(errorMessage)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
_PUBLIC.tsched.addTask(taskFunction, "evmgr")
|
|
||||||
package.preload("event")
|
|
||||||
|
|
||||||
log.kernel.info("Starting startup apps...")
|
log.kernel.info("Starting startup apps...")
|
||||||
local handle, data, tmpdata = filesystem.open("/halyde/config/startupapps.json", "r"), "", nil
|
local handle, data, tmpdata = filesystem.open("/halyde/config/startupapps.json", "r"), "", nil
|
||||||
repeat
|
repeat
|
||||||
|
|||||||
Reference in New Issue
Block a user