Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local statusChannelID = 5
- -- Find Modem
- local modem = peripheral.find("modem", function(n, o) return o.isWireless() end)
- -- Find TE Tank
- local tank = peripheral.find("thermalexpansion_tank")
- if tank == nil then
- error("Could not bind to TE Tank. Is one attached?")
- end
- term.clear()
- term.setCursorPos(1,1)
- print("TE Tank Monitor...")
- print()
- print("Tank Contents: ")
- print("Fill Percentage: ")
- print()
- if ( modem == nil ) then
- print("Modem not present. No status reports.")
- else
- print("Modem present. Status reports sent on channel " .. statusChannelID)
- end
- print()
- print("Press 'q' to quit")
- local status = {}
- local pollTimer = os.startTimer(0)
- while true do
- local event, p1, p2, p3, p4 = os.pullEvent()
- if event == "key" then
- if p1 == keys.q then
- term.setCursorPos(1,11)
- return
- end
- elseif event == "timer" and p1 == pollTimer then
- local info = tank.getTankInfo()
- local maxCapacity = info[1].capacity
- local curCapacity = info[1].contents.amount
- local fillP = math.floor((curCapacity/maxCapacity) * 100)
- local tankLabel = "Fluid " .. info[1].contents.rawName
- status[tankLabel] = fillP .. "%"
- if modem ~= nil then modem.transmit(statusChannelID, 0, textutils.serialize(status)) end
- term.setCursorPos(16, 3)
- term.write(info[1].contents.rawName .. " ")
- term.setCursorPos(18, 4)
- term.write(fillP .. "% ")
- pollTimer = os.startTimer(5)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement