gelatine87

energyStorageWiFisender

Aug 2nd, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.89 KB | None | 0 0
  1. ----------------------------------
  2. --   Elite's DE Energy Reader  --
  3. --Motified from Hypnotized's code--
  4. -----------------------------------
  5.  
  6. --Send everything to the Monitor--
  7. mon = peripheral.wrap("right")
  8. p = peripheral.wrap("draconic_rf_storage_10")
  9. term.redirect(mon)
  10.  
  11. -- Set Refresh Rate
  12. local t = {}
  13.  
  14. local refreshRate = 1
  15. local prevEnergyStored = 0
  16. local diff = 0
  17.  
  18. local function comma_value(amount)
  19.   local formatted = amount
  20.   local k = 0
  21.   while true do
  22.     formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
  23.     if (k == 0) then
  24.       break
  25.     end
  26.   end
  27.   return formatted
  28. end
  29.  
  30.  
  31. --TitleBar
  32. function titleBar()
  33.   term.setCursorPos(1,1)
  34.   term.setBackgroundColor(colors.blue)
  35.   term.setTextColor(colors.lightGray)
  36.   term.clearLine()
  37.   term.setCursorPos(2,1)
  38.   print("Draconic Evo Energy Monitor")
  39. end
  40.  
  41.  
  42. while true do
  43.   local energyStored = p.getEnergyStored()
  44.   local maxEnergyStored = p.getMaxEnergyStored()
  45.   local percent = energyStored/maxEnergyStored*100
  46.   diff = (energyStored - prevEnergyStored)/(refreshRate*20)
  47.  
  48.   t[0] = energyStored
  49.   t[1] = maxEnergyStored
  50.   t[2] = percent
  51.   t[3] = diff
  52.  
  53.   local msg = textutils.serialize(t)
  54.   rednet.open("bottom")
  55.   rednet.broadcast(msg)
  56.  
  57.   --Print Stuff to the screen
  58.   term.clear()
  59.   titleBar()
  60.   term.setBackgroundColor(colors.black)
  61.   term.setCursorPos(1,3)
  62.   term.setTextColor(colors.red)
  63.   print("    Max Energy: "..comma_value(maxEnergyStored))
  64.   term.setCursorPos(1,5)
  65.   term.setTextColor(colors.green)
  66.   print("Current Energy: "..comma_value(energyStored).." ")
  67.   term.setCursorPos(1,6)
  68.   print("                ("..percent.."%)")
  69.   print()
  70.   if (diff > 0) then
  71.     print("     Avg. RF/t: +"..comma_value(diff))
  72.   else
  73.     term.setTextColor(colors.red)
  74.     print("     Avg. RF/t: "..comma_value(diff))
  75.   end
  76.   prevEnergyStored = energyStored
  77.   os.sleep(refreshRate)
  78. end
Add Comment
Please, Sign In to add comment