mirror of https://github.com/kepler155c/opus
fix recorder
This commit is contained in:
parent
be51935662
commit
982894a5f1
|
@ -61,19 +61,20 @@ local function nextUID()
|
||||||
return Event.uid - 1
|
return Event.uid - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
function Event.on(type, fn)
|
function Event.on(event, fn)
|
||||||
local event = Event.types[type]
|
|
||||||
if not event then
|
local handlers = Event.types[event]
|
||||||
event = { }
|
if not handlers then
|
||||||
Event.types[type] = event
|
handlers = { }
|
||||||
|
Event.types[event] = handlers
|
||||||
end
|
end
|
||||||
|
|
||||||
local handler = {
|
local handler = {
|
||||||
uid = nextUID(),
|
uid = nextUID(),
|
||||||
event = type,
|
event = event,
|
||||||
fn = fn,
|
fn = fn,
|
||||||
}
|
}
|
||||||
event[handler.uid] = handler
|
handlers[handler.uid] = handler
|
||||||
setmetatable(handler, { __index = Routine })
|
setmetatable(handler, { __index = Routine })
|
||||||
|
|
||||||
return handler
|
return handler
|
||||||
|
@ -88,14 +89,15 @@ end
|
||||||
local function addTimer(interval, recurring, fn)
|
local function addTimer(interval, recurring, fn)
|
||||||
|
|
||||||
local timerId = os.startTimer(interval)
|
local timerId = os.startTimer(interval)
|
||||||
|
local handler
|
||||||
|
|
||||||
return Event.on('timer', function(t, id)
|
handler = Event.on('timer', function(t, id)
|
||||||
if timerId == id then
|
if timerId == id then
|
||||||
fn(t, id)
|
fn(t, id)
|
||||||
if recurring then
|
if recurring then
|
||||||
timerId = os.startTimer(interval)
|
timerId = os.startTimer(interval)
|
||||||
else
|
else
|
||||||
Event.off(t)
|
Event.off(handler)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
@ -160,26 +162,22 @@ function Event.exitPullEvents()
|
||||||
os.sleep(0)
|
os.sleep(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function processHandlers(e, ...)
|
local function processHandlers(event)
|
||||||
|
|
||||||
local event = Event.types[e]
|
local handlers = Event.types[event]
|
||||||
if event then
|
if handlers then
|
||||||
|
for _,h in pairs(handlers) do
|
||||||
local keys = Util.keys(event)
|
if not h.co then
|
||||||
for _,key in pairs(keys) do
|
|
||||||
|
|
||||||
local h = event[key]
|
|
||||||
if h and not h.co then
|
|
||||||
-- callbacks are single threaded (only 1 co per handler)
|
-- callbacks are single threaded (only 1 co per handler)
|
||||||
h.co = coroutine.create(h.fn)
|
h.co = coroutine.create(h.fn)
|
||||||
Event.routines[h.uid] = h
|
Event.routines[h.uid] = h
|
||||||
h:resume(h, ...)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function processRoutines(...)
|
local function processRoutines(...)
|
||||||
|
|
||||||
local keys = Util.keys(Event.routines)
|
local keys = Util.keys(Event.routines)
|
||||||
for _,key in ipairs(keys) do
|
for _,key in ipairs(keys) do
|
||||||
local r = Event.routines[key]
|
local r = Event.routines[key]
|
||||||
|
@ -194,7 +192,7 @@ function Event.pullEvent(eventType)
|
||||||
while true do
|
while true do
|
||||||
local e = { os.pullEventRaw() }
|
local e = { os.pullEventRaw() }
|
||||||
|
|
||||||
processHandlers(table.unpack(e))
|
processHandlers(e[1])
|
||||||
processRoutines(table.unpack(e))
|
processRoutines(table.unpack(e))
|
||||||
|
|
||||||
if Event.terminate or e[1] == 'terminate' then
|
if Event.terminate or e[1] == 'terminate' then
|
||||||
|
|
|
@ -41,7 +41,9 @@ local function showHelp(name)
|
||||||
UI.term:reset()
|
UI.term:reset()
|
||||||
shell.run('help ' .. name)
|
shell.run('help ' .. name)
|
||||||
print('Press enter to return')
|
print('Press enter to return')
|
||||||
read()
|
repeat
|
||||||
|
local _, k = os.pullEvent('key_up')
|
||||||
|
until k == keys.enter
|
||||||
end
|
end
|
||||||
|
|
||||||
function page:eventHandler(event)
|
function page:eventHandler(event)
|
||||||
|
|
|
@ -71,28 +71,23 @@ if #filename == 0 then
|
||||||
end
|
end
|
||||||
|
|
||||||
print('Initializing...')
|
print('Initializing...')
|
||||||
fs.mount('.recGif', 'ramfs', 'directory')
|
|
||||||
fs.mount('.recGif/GIF', 'urlfs', 'http://pastebin.com/raw/5uk9uRjC')
|
|
||||||
fs.mount('.recGif/package', 'urlfs', 'http://pastebin.com/raw/cUYTGbpb')
|
|
||||||
|
|
||||||
-- don't pollute global env
|
-- don't pollute global env
|
||||||
local function loadAPI(filename, env)
|
-- convert these to require style apis
|
||||||
|
local function loadAPI(url, env)
|
||||||
local apiEnv = Util.shallowCopy(env)
|
local apiEnv = Util.shallowCopy(env)
|
||||||
apiEnv.shell = nil
|
apiEnv.shell = nil
|
||||||
apiEnv.multishell = nil
|
apiEnv.multishell = nil
|
||||||
setmetatable(apiEnv, { __index = _G })
|
setmetatable(apiEnv, { __index = _G })
|
||||||
local fn = loadfile(filename, apiEnv)
|
local fn = Util.loadUrl(url, apiEnv)
|
||||||
fn()
|
fn()
|
||||||
return apiEnv
|
return apiEnv
|
||||||
end
|
end
|
||||||
|
|
||||||
package = loadAPI('.recGif/package', getfenv(1))
|
bbpack = loadAPI('http://pastebin.com/raw/PdrJjb5S', getfenv(1))
|
||||||
GIF = loadAPI('.recGif/GIF', getfenv(1))
|
GIF = loadAPI('http://pastebin.com/raw/5uk9uRjC', getfenv(1))
|
||||||
|
|
||||||
local oldDir = shell.dir()
|
Util.runUrl(getfenv(1), 'http://pastebin.com/raw/cUYTGbpb', 'get', 'Y0eLUPtr')
|
||||||
shell.setDir('.recGif')
|
|
||||||
shell.run("package get Y0eLUPtr")
|
|
||||||
shell.setDir(oldDir)
|
|
||||||
|
|
||||||
local function snooze()
|
local function snooze()
|
||||||
local myEvent = tostring({})
|
local myEvent = tostring({})
|
||||||
|
@ -239,7 +234,7 @@ snooze()
|
||||||
|
|
||||||
-- Load font data:
|
-- Load font data:
|
||||||
do
|
do
|
||||||
local ascii, counter = GIF.toPaintutils(GIF.flattenGIF(GIF.loadGIF(".recGif/ascii.gif"))), 0
|
local ascii, counter = GIF.toPaintutils(GIF.flattenGIF(GIF.loadGIF("ascii.gif"))), 0
|
||||||
local newFont, ybump, xbump = #ascii ~= #ascii[1], 0, 0
|
local newFont, ybump, xbump = #ascii ~= #ascii[1], 0, 0
|
||||||
charW, charH, chars = newFont and #ascii[1] / 16 or #ascii[1] * 3 / 64, #ascii / 16, {}
|
charW, charH, chars = newFont and #ascii[1] / 16 or #ascii[1] * 3 / 64, #ascii / 16, {}
|
||||||
|
|
||||||
|
@ -534,6 +529,6 @@ buffer = nil
|
||||||
|
|
||||||
GIF.saveGIF(image, filename)
|
GIF.saveGIF(image, filename)
|
||||||
|
|
||||||
fs.unmount('.recGif')
|
fs.delete('ascii.gif')
|
||||||
|
|
||||||
print("Encode complete")
|
print("Encode complete")
|
||||||
|
|
|
@ -6,7 +6,7 @@ require = requireInjector(getfenv(1))
|
||||||
local GPS = require('gps')
|
local GPS = require('gps')
|
||||||
|
|
||||||
function turtle.enableGPS(timeout)
|
function turtle.enableGPS(timeout)
|
||||||
if turtle.point.gps == 'GPS' then
|
if turtle.point.gps then
|
||||||
return turtle.point
|
return turtle.point
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue