Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function printTurtleData(monitor, turtle)
- local x, y = monitor.getCursorPos()
- monitor.setTextColor(colors.white)
- monitor.write("#" .. turtle.id .. " ")
- x = x + 5
- monitor.setCursorPos(x, y)
- monitor.setTextColor(colors.yellow)
- monitor.write(turtle.label)
- x = x + 11
- monitor.setCursorPos(x, y)
- monitor.setTextColor(colors.white)
- monitor.write(" (" .. turtle.coordinate_x .. "," .. turtle.coordinate_y .. "," .. turtle.coordinate_z .. ") ")
- x = x + 20
- monitor.setCursorPos(x, y)
- monitor.setTextColor(colors.lightBlue)
- monitor.write(turtle.current_script .. " ")
- x = x + 11
- monitor.setCursorPos(x, y)
- if turtle.status == "Error" then
- monitor.setBackgroundColor(colors.red)
- elseif turtle.status == "Running" then
- monitor.setBackgroundColor(colors.green)
- elseif turtle.status == "Idle" then
- monitor.setBackgroundColor(colors.orange)
- else
- monitor.setBackgroundColor(colors.lightBlue)
- end
- monitor.setTextColor(colors.white)
- monitor.write(turtle.status)
- monitor.setBackgroundColor(colors.black)
- x = x + 8
- monitor.setCursorPos(x, y)
- monitor.write(" Fuel: " .. turtle.fuel_lvl)
- monitor.setCursorPos(1, y + 1)
- end
- local function getMonitor()
- local monitor = peripheral.find("monitor")
- if not monitor then
- error("No monitor found", 2)
- end
- return monitor
- end
- local function getApiClient()
- local apiClient = loadfile("api_client")()
- if not apiClient then
- error("Failed to load API client", 2)
- end
- return apiClient.new("http://35.228.225.211:8000")
- end
- local function refresh_monitor()
- local client = getApiClient()
- local monitor = getMonitor()
- while true do
- local turtles = client:get("/turtles")
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- monitor.setTextScale(0.9)
- monitor.setCursorPos(1, 1)
- monitor.write("Turtle Information:")
- monitor.setCursorPos(1, 3)
- for _, turtle in ipairs(turtles) do
- printTurtleData(monitor, turtle)
- end
- sleep(30)
- end
- end
- refresh_monitor()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement