initialize
This commit is contained in:
commit
5b23ea99fd
43 changed files with 2336 additions and 0 deletions
58
apricot/node/logger.lua
Normal file
58
apricot/node/logger.lua
Normal file
|
@ -0,0 +1,58 @@
|
|||
local logger = {}
|
||||
logger.init = function(monitor_wrap, scale)
|
||||
local self = {}
|
||||
|
||||
local monitor = monitor_wrap or peripheral.find("monitor")
|
||||
if not monitor then
|
||||
monitor = term
|
||||
else monitor.setTextScale(scale or 0.5)
|
||||
end
|
||||
local log_colours = {
|
||||
['log'] = colours.white,
|
||||
['info'] = colours.lightBlue,
|
||||
['warn'] = colours.yellow,
|
||||
['err'] = colours.red,
|
||||
['success'] = colours.lime
|
||||
}
|
||||
|
||||
local function move_line()
|
||||
monitor.setCursorPos(1, select(2, monitor.getCursorPos()) + 1)
|
||||
if select(2, monitor.getCursorPos()) >= select(2, monitor.getSize()) then
|
||||
monitor.scroll(1)
|
||||
monitor.setCursorPos(1, select(2, monitor.getCursorPos()) - 1)
|
||||
end
|
||||
end
|
||||
|
||||
local function write_msg(message, msg_colour)
|
||||
local time_str = os.date('%Y-%b-%d %H:%M:%S')
|
||||
local msg_formatted = "[" .. time_str .. "] " .. message
|
||||
|
||||
monitor.setTextColour(msg_colour)
|
||||
monitor.write(msg_formatted)
|
||||
move_line()
|
||||
end
|
||||
|
||||
function self.log(msg)
|
||||
write_msg(msg, log_colours['log'])
|
||||
end
|
||||
|
||||
function self.info(msg)
|
||||
write_msg('INFO: ' .. msg, log_colours['info'])
|
||||
end
|
||||
|
||||
function self.warning(msg)
|
||||
write_msg('WARNING: ' .. msg, log_colours['warn'])
|
||||
end
|
||||
|
||||
function self.error(msg)
|
||||
write_msg('ERROR: ' .. msg, log_colours['err'])
|
||||
end
|
||||
|
||||
function self.success(msg)
|
||||
write_msg('SUCCESS: ' .. msg, log_colours['success'])
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
return logger
|
19
apricot/node/modems.lua
Normal file
19
apricot/node/modems.lua
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
local modems = {peripheral.find("modem")}
|
||||
local logger = require('logger').init()
|
||||
|
||||
logger.info("Powering up!")
|
||||
for modem_i, modem in pairs(modems) do
|
||||
modem.closeAll()
|
||||
modem.open(1)
|
||||
-- for i = (128 * (modem_i - 1)),((128 * modem_i) - 1) do
|
||||
-- modem.open(i)
|
||||
-- end
|
||||
logger.success("Modem " .. modem_i .. " opened ports " .. (128 * (modem_i - 1)) .. " - " .. ((128 * modem_i) - 1))
|
||||
end
|
||||
|
||||
local event, side, channel, replyChannel, message, distance
|
||||
while true do
|
||||
event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
|
||||
logger.info(channel .. " " .. replyChannel .. " " .. tostring(message) .. " " .. distance )
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue