Advertisement
gelatine87

energyStorageWiFiempfanger

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