diff --git a/halyde/kernel/boot.lua b/halyde/kernel/boot.lua index e95a687..90b5072 100644 --- a/halyde/kernel/boot.lua +++ b/halyde/kernel/boot.lua @@ -70,6 +70,7 @@ require("/halyde/kernel/modload.lua") package.preload("component") package.preload("computer") package.preload("log") +package.preload("event") if not filesystem.exists("/halyde/config/startupapps.json") then filesystem.copy("/halyde/config/generate/startupapps.json", "/halyde/config/startupapps.json") diff --git a/halyde/kernel/evmgr.lua b/halyde/kernel/evmgr.lua deleted file mode 100644 index e9bf8f4..0000000 --- a/halyde/kernel/evmgr.lua +++ /dev/null @@ -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 diff --git a/halyde/kernel/modules/evmgr.lua b/halyde/kernel/modules/evmgr.lua new file mode 100644 index 0000000..4930c94 --- /dev/null +++ b/halyde/kernel/modules/evmgr.lua @@ -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 diff --git a/halyde/kernel/tsched.lua b/halyde/kernel/tsched.lua index d865b7a..bde0d07 100644 --- a/halyde/kernel/tsched.lua +++ b/halyde/kernel/tsched.lua @@ -39,33 +39,6 @@ local function runTasks() 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...") local handle, data, tmpdata = filesystem.open("/halyde/config/startupapps.json", "r"), "", nil repeat