Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added monitor support #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions openbee.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local version = {
["major"] = 2,
["minor"] = 1,
["minor"] = 2,
["patch"] = 0
}

Expand All @@ -26,7 +26,9 @@ if config == nil then
["chestSide"] = "top",
["chestDir"] = "up",
["productDir"] = "down",
["analyzerDir"] = "east"
["analyzerDir"] = "east",
["monDir"] = "monitor_0",
["useMonitor"] = "true"
}
saveFile("bee.config", config)
end
Expand Down Expand Up @@ -84,11 +86,45 @@ function setupLog()
return string.format("bee.%d.log", logCount)
end

function monWriteLine(msg)
if config.useMonitor then
mon = peripheral.wrap(config.monDir)
mon.write(msg)
end
if monWriteLineActive == nil or monWriteLineActive == false then
monWriteLineActive = true
end
end

function monNewLine()
if config.useMonitor then
mon = peripheral.wrap(config.monDir)
if monLines == nil then
monLines = 0
end

if monWriteLineActive then
monLines = monLines +1
monWriteLineActive = false
end

monw, monh = mon.getSize()

if monh <= monLines then
mon.scroll(1)
monLines = monh -1
end

mon.setCursorPos(1, monLines+1)
end
end

function log(msg)
msg = msg or ""
logFile.write(tostring(msg))
logFile.flush()
io.write(msg)
monWriteLine(msg)
end

function logLine(...)
Expand All @@ -98,10 +134,12 @@ function logLine(...)
end
logFile.write(msg)
io.write(msg)
monWriteLine(msg)
end
logFile.write("\n")
logFile.flush()
io.write("\n")
monNewLine()
end

function getPeripherals()
Expand Down