Advertisement
rhn

Energy cell power monitor v4 - 1.7.10

rhn
Jun 22nd, 2015
2,524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- For 1.7.10 versions of Thermal Expansion and EnderIO
  2. -- Monitors TE3 Energy cells and EnderIO capacitor banks and output redstone signals once energy storage drops below set limits.
  3. -- Will automatically detect direction of adjacent storage device and (optional) Advanced Monitors. If chosen, monitor format should be 1 high and 2 wide. Now also with wired modem support for both storage and monitors. Directly adjacent devices will take priority over any wired devices.
  4. -- Redstone signal for the engines will be output out the back of the computer.
  5. --More details: http://forum.feed-the-beast.com/threads/rhns-1-6-monster-build-journal-and-guide-collection.42664/page-15#post-718973
  6.  
  7.  
  8. local upper = 0.90 --Upper limit for computer to stop transmitting redstone signal. 0.90=90% full.
  9. local lower = 0.10 --Lower limit for computer to start transmitting redstone signal.
  10.  
  11.  
  12. --Device detection
  13. isError=0
  14.  
  15. function detectDevice(DeviceName)
  16. DeviceSide="none"
  17. for k,v in pairs(redstone.getSides()) do
  18.   if peripheral.getType(v) and string.find(peripheral.getType(v), DeviceName) then
  19.  --if peripheral.getType(v)==DeviceName then
  20.    --if string.find(peripheral.getType(v), DeviceName) then
  21.       DeviceSide = v
  22.       break
  23.    --end
  24.   end
  25. end
  26.   return(DeviceSide)
  27. end
  28.  
  29.  
  30. cell="none"
  31. monitor="none"
  32. local peripheralList = peripheral.getNames()
  33.  
  34. CellSide=detectDevice("tile_thermalexpansion_cell")
  35.  
  36. if CellSide~="none" then
  37.    cell=peripheral.wrap(CellSide)
  38.    print ("TE Energy cell on the " .. CellSide .. " connected.")
  39.    else
  40.     CellSide=detectDevice("tile_blockcapacitorbank_name")
  41.     if CellSide~="none" then
  42.         cell=peripheral.wrap(CellSide)
  43.         print ("EnderIO capacitorbank on the " .. CellSide .. " connected.")
  44.     else
  45.             for Index = 1, #peripheralList do
  46.                 if string.find(peripheralList[Index], "tile_thermalexpansion_cell") then
  47.                     cell=peripheral.wrap(peripheralList[Index])
  48.                     print ("TE Energy cell on wired modem: "..peripheralList[Index].." connected.")
  49.                 elseif string.find(peripheralList[Index], "tile_blockcapacitorbank_name") then
  50.                     cell=peripheral.wrap(peripheralList[Index])
  51.                     print ("EnderIO capacitorbank on wired modem: "..peripheralList[Index].." connected.")
  52.                 end
  53.             end --for
  54.             if cell == "none" then
  55.                 print("No Energy storage found. Halting script!")
  56.                 return
  57.             end
  58.  
  59.     end
  60. end
  61.  
  62.  
  63. MonitorSide=detectDevice("monitor")
  64.  
  65. if MonitorSide~="none" then
  66.       monitor=peripheral.wrap(MonitorSide)
  67.    print ("Monitor on the " .. MonitorSide .. " connected.")
  68.    else
  69.     for Index = 1, #peripheralList do
  70.         if string.find(peripheralList[Index], "monitor") then
  71.             monitor=peripheral.wrap(peripheralList[Index])
  72.             print ("Monitor on wired modem: "..peripheralList[Index].." connected.")
  73.         end
  74.     end --for
  75.     if monitor == "none" then
  76.         print ("Warning - No Monitor attached, continuing without.")
  77.     end
  78. end
  79.  
  80. --Main code
  81. redstone.setOutput("back", false) --Defaulting to off
  82.  
  83. --If monitor is attached, write data on monitor
  84. if monitor ~= "none" then
  85.     monitor.clear()
  86.     monitor.setBackgroundColour((colours.grey))
  87.     monitor.setCursorPos(1,4)
  88.     monitor.write(" ON ")
  89.     monitor.setBackgroundColour((colours.green))
  90.     monitor.setCursorPos(5,4)
  91.     monitor.write(" OFF ")
  92.     monitor.setBackgroundColour((colours.black))
  93. end
  94.  
  95. --Main loop
  96. while true do
  97.     --Get storage values
  98.     eNow = cell.getEnergyStored("unknown")
  99.     eMax = cell.getMaxEnergyStored("unknown")
  100.  
  101.     --Compute ratio
  102.     fill = (eNow / eMax)
  103.  
  104. --If monitor is attached, write data on monitor
  105. if monitor ~= "none" then
  106.  
  107.     if eMax >= 10000000 then
  108.     monitor.setCursorPos(11,2)
  109.     monitor.write("Storage:")
  110.     monitor.setCursorPos(11,3)
  111.     monitor.write(math.ceil(eNow/1000).."kRF")
  112.     monitor.setCursorPos(11,4)
  113.     monitor.write("Of:")
  114.     monitor.setCursorPos(11,5)
  115.     monitor.write(math.ceil(eMax/1000).."kRF")
  116.     else   
  117.     monitor.setCursorPos(11,2)
  118.     monitor.write("Storage:")
  119.     monitor.setCursorPos(11,3)
  120.     monitor.write(math.ceil(eNow))
  121.     monitor.setCursorPos(11,4)
  122.     monitor.write("Of:")
  123.     monitor.setCursorPos(11,5)
  124.     monitor.write(math.ceil(eMax))
  125.     end
  126.  
  127.     monitor.setCursorPos(1,2)
  128.     monitor.write("Engines:")
  129. end
  130.  
  131.     if fill > upper then
  132.         --energylevel is over upper level, turning redstone signal off
  133.         redstone.setOutput("back", false)
  134.  
  135.         if monitor ~= "none" then
  136.             monitor.setBackgroundColour((colours.grey))
  137.             monitor.setCursorPos(1,4)
  138.             monitor.write(" ON ")
  139.             monitor.setBackgroundColour((colours.green))
  140.             monitor.setCursorPos(5,4)
  141.             monitor.write(" OFF ")
  142.             monitor.setBackgroundColour((colours.black))
  143.         end
  144.  
  145.     elseif fill < lower then
  146.         --energy level is below lower limit, turning redstone signal on
  147.         redstone.setOutput("back", true)
  148.        
  149.         if monitor ~= "none" then
  150.             monitor.setBackgroundColour((colours.green))
  151.             monitor.setCursorPos(1,4)
  152.             monitor.write(" ON ")
  153.             monitor.setBackgroundColour((colours.grey))
  154.             monitor.setCursorPos(5,4)
  155.             monitor.write(" OFF ")
  156.             monitor.setBackgroundColour((colours.black))
  157.         end
  158.     end
  159.  
  160.    
  161.     sleep(1)
  162. end --while
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement