PlowmanPlow

ComputerCraft - Draconic Reactor RF Storage Monitor

Apr 30th, 2017
376
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local statusChannelID = 5
  2.  
  3. -- Find Modem
  4. local modem = peripheral.find("modem", function(n, o) return o.isWireless() end)
  5. if modem == nil then
  6.    error("Could not find a modem. Is one attached?")
  7. end
  8.  
  9. -- Bind the Draconic RF Storage
  10. local decore = peripheral.find("draconic_rf_storage")
  11. if decore == nil then
  12.    error("Could not Draconic RF Storage. Is one attached?")
  13. end
  14.  
  15. function round(num, idp)
  16.   local mult = 10^(idp or 0)
  17.   return math.floor(num * mult + 0.5) / mult
  18. end
  19.  
  20. local function prettyAmt(num)
  21.    if num >= 1000000000000 then
  22.       return (tostring(round(num/1000000000000, 2)) .. "T")
  23.    elseif num >= 1000000000 then
  24.       return (tostring(round(num/1000000000, 2)) .. "B")
  25.    elseif num >= 1000000 then
  26.       return (tostring(round(num/1000000, 2)) .. "M")
  27.    elseif num >= 1000 then
  28.       return (tostring(round(num/1000, 2)) .. "t")
  29.    else
  30.       return tostring(num)
  31.    end
  32. end
  33.  
  34. term.clear()
  35. term.setCursorPos(1,1)
  36. print("Draconic RF Storage Monitor...")
  37. print()
  38. print("DECore Stored: ")
  39. print()
  40. print("Press 'q' to quit.")
  41. print()
  42.  
  43. local pollTimer = os.startTimer(0)
  44. local status = {}
  45. while true do
  46.    local event, p1, p2, p3, p4 = os.pullEvent()
  47.    if event == "key" then
  48.       if p1 == 16 then -- 'q'
  49.          term.setCursorPos(1, 6)
  50.          return
  51.       end
  52.    elseif event == "timer" and p1 == pollTimer then
  53.       -- Check the Solar charged energy cell to determine if the
  54.       --local energyP = (decore.getEnergyStored() / decore.getMaxEnergyStored()) * 100
  55.       --status["DECore Stored RF"] = math.floor(energyP) .. "%"
  56.       local energyP = decore.getEnergyStored()
  57.       status["DECore Stored RF"] = prettyAmt(energyP)
  58.       term.setCursorPos(1,3)
  59.       term.write("DECore Stored RF: " .. status["DECore Stored RF"] .. "         ")
  60.       if modem ~= nil then modem.transmit(statusChannelID, 0, textutils.serialize(status)) end
  61.       pollTimer = os.startTimer(5)
  62.    end
  63. end
RAW Paste Data