Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ldb2")
- os.loadAPI("rnc")
- local MaxWait = 2 * 60 * 1000 --mls
- local db = "turtle"
- mon = peripheral.find("monitor")
- tms = peripheral.find("timeSensor")
- function dtf(str)
- return string.format("%.2d",str)
- end
- function formatTime(v_time)
- return "[" ..
- dtf(v_time.hour) .. ":" ..
- dtf(v_time.minute) .. ":" ..
- dtf(v_time.second) .. "]"
- end
- local function heading(text)
- w,h = mon.getSize()
- mon.setCursorPos((w - string.len(text))/2+1, 1)
- mon.setTextColor(colors.white)
- mon.write(text)
- end
- local function clearLine()
- w,h = mon.getSize()
- x,y = mon.getCursorPos()
- mon.setCursorPos(1,y)
- for i = 1, w do
- mon.setCursorPos(i,y)
- mon.write(" ")
- end
- mon.setCursorPos(x,y)
- end
- mon.clear()
- heading("Turtle Monitor")
- local started = 1
- local function WriteAll()
- vlist = ldb2.list(db)
- heading("Turtle Monitor")
- for i=1, table.getn(vlist) do
- tmp = ldb2.get(db, vlist[i])
- if tmp.re == 1 or started == 1 then
- mon.setCursorPos(1, i+2)
- clearLine()
- mon.setTextColor(colors.white)
- mon.write(tmp.time .. " ")
- if tmp.timestamp < tms.getTime() - MaxWait then
- mon.setTextColor(colors.red)
- mon.write(tmp.name)
- else
- mon.setTextColor(colors.lime)
- mon.write(tmp.name)
- end
- mon.setTextColor(colors.white)
- mon.write(" > ")
- mon.setTextColor(colors.lightGray)
- mon.write("D:" .. tmp.depth .. " | " .. tmp.state .. " | " .. tmp.detail)
- tmp.re = 0
- ldb2.set(db, vlist[i], tmp)
- end
- end
- started = 0
- end
- local tm = tms.getTime()
- rnc.setTimeOut(1)
- while true do
- msg = rnc.resive()
- if msg ~= nil then
- msg.time = formatTime(tms.getDate())
- msg.timestamp = tms.getTime()
- msg.re = 1
- ldb2.set(db, msg.name, msg)
- end
- WriteAll()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement