Advertisement
Stravides

reactormonitor3.0

Nov 25th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 KB | None | 0 0
  1. os.unloadAPI("ProgressBar")
  2. os.loadAPI("ProgressBar")
  3.  
  4. os.unloadAPI("button")
  5. os.loadAPI("button")
  6. button.setMon("top")
  7.  
  8. function setbuttons()
  9.   button.add("status", "On/Off","toggle",2,4,15,6,colors.red,colors.green,colors.white,function() prepMsg() end)
  10.   button.setState("status",false)
  11.   button.draw()
  12. end
  13.  
  14. rednet.open("bottom")
  15. ProgressBar.SetPeripheral("top")
  16.  
  17. m=peripheral.wrap("top")
  18. m.setTextScale(1)
  19. m.setTextColor(5)
  20.  
  21. function split(str, delim, maxNb)  
  22.   if string.find(str, delim) == nil then
  23.     return { str }
  24.   end
  25.   if maxNb == nil or maxNb <1 then
  26.     maxNb = 0
  27.   end
  28.   local result = {}
  29.   local pat = "(.-)"..delim.."()"
  30.   local nb = 0
  31.   local lastPos
  32.   for part, pos in string.gmatch(str,pat) do
  33.     nb = nb+1
  34.     result[nb]=part
  35.     lastPos=pos
  36.     if nb==maxNb then break end
  37.   end
  38.   if nb ~= maxNb then
  39.     result[nb+1] = string.sub(str,lastPos)
  40.   end
  41.   return result
  42. end
  43.  
  44. function round(val, decimal)
  45.   if (decimal) then
  46.     return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
  47.   else
  48.     return math.floor(val+0.5)
  49.   end
  50. end
  51.  
  52. function writeAt(x,y,text)
  53.   m.setCursorPos(x,y)
  54.   m.write(text)
  55. end
  56.  
  57. function prepMsg
  58.   local coollvl = reactor.getCoolantAmount("")
  59.   local coolmax = reactor.getCoolantAmountMax("")
  60.   local coolpct = coollvl/coolmax
  61.   msg="toggleActive"
  62.   rednet.open("bottom")
  63.   shell.run("clear")
  64.   rednet.send(70,msg) -- Reactor Control Screen
  65. end
  66.  
  67. while true do
  68.   local time= os.time()
  69.   local fTime = textutils.formatTime(time,false)
  70.   local event, id, msg = os.pullEvent("rednet_message")
  71.   local Tab = split(msg,"|",4)
  72.   local pc = round(Tab[3]*100,0)
  73.   local es = round(Tab[4]/100000,0)
  74.   m.clear()
  75.   setbuttons()
  76.   writeAt(22,15,fTime)
  77.   writeAt(2,2,"Reactor Info")
  78.   writeAt(2,4,"Energy Stored")
  79.   writeAt(2,6,"Fuel Level: ")
  80.   writeAt(2,8,"Core Temp:         "..round(Tab[2],1).."C")
  81.   writeAt(2,10,"Status:            "..Tab[1])
  82.   ProgressBar.SetTable("Fuel",100,pc,20,45,6)
  83.   ProgressBar.SetTable("Energy",100,es,20,45,4)
  84.   ProgressBar.DrawToPeripheral()
  85.   sleep(1)
  86. --  ProgressBar.SetCurValue("Test",pc)
  87. --  ProgressBar.DrawToPeripheral()
  88. --  sleep(1)
  89.   button.check() -- This goes into a wait loop and does not come out again....
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement