Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.find("monitor") or error("No monitor found", 0)
- local modem = peripheral.find("modem") or error("No modem found", 0)
- local modemChan = 12
- local last = nil
- local monY = 2
- local logFile = nil
- local logDir = "/mine-logs/"
- function resetMon()
- local topLine
- if (last == nil) then
- topLine = "Open on "..modemChan.." | Last Completion: NONE"
- else
- topLine = "Open on "..modemChan.." | Last Completion: "..textutils.formatTime(last)
- end
- mon.clear()
- mon.setTextScale(0.5)
- mon.setTextColor(colors.cyan)
- mon.setCursorPos(1,1)
- mon.write(topLine)
- mon.setTextColor(colors.white)
- mon.setCursorPos(1,2)
- monY = 2
- end
- function mwrite(mess, tc, skipLog)
- if (tc == nil) then
- tc = colors.white
- end
- if (skipLog == nil) then
- skipLog = false
- end
- mon.setCursorPos(1, monY)
- mon.setTextColor(tc)
- mon.write(mess)
- print(mess)
- monY = monY + 1
- if not skipLog then
- mineLog(mess)
- end
- end
- function startLog()
- if not fs.exists(logDir) then
- fs.makeDir(logDir)
- end
- local logs = fs.list(logDir)
- local logCount = #logs
- local filename = (logCount + 1)..".txt"
- local filePath = logDir .. filename
- logFile = fs.open(filePath, "w")
- mwrite("Logging to: "..filePath, colors.red, true)
- logFile.writeLine("### START OF LOG ###")
- logFile.writeLine(textutils.formatTime(os.time("utc")))
- end
- function mineLog(mess)
- if logFile == nil then
- startLog()
- end
- logFile.writeLine(mess)
- logFile.flush()
- end
- function completeLog()
- mineLog(textutils.formatTime(os.time("utc")))
- mineLog("### END OF LOG ###")
- logFile.close()
- logFile = nil
- end
- print("App running...")
- modem.open(12)
- while true do
- resetMon()
- startLog()
- mwrite("Waiting for message...")
- local e, s, c, rc, m, d
- repeat e, s, c, rc, m, d = os.pullEvent("modem_message")
- until c == 12 and m == "s"
- resetMon()
- mwrite("Mine running...")
- local q = false
- while not q do
- repeat e, s, c, rc, m, d = os.pullEvent("modem_message")
- until c == 12
- if (rc == 0 and m == "d") then
- break
- else
- mwrite(m, colors.orange)
- end
- end
- last = os.time("utc")
- resetMon()
- mwrite("Mine completed!")
- completeLog()
- end
Advertisement
Add Comment
Please, Sign In to add comment