Advertisement
GauHelldragon

PowerMon2 v0.7

Jun 6th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("ocs/apis/sensor")
  2. local power = sensor.wrap("left")
  3. local net = peripheral.wrap("back")
  4. local mon = "monitor_0"
  5. if ( power == nil ) then
  6.     print("No sensor!")
  7.     os.exit()
  8. end
  9. if ( net == nil ) then
  10.     print("No network!")
  11.     os.exit()
  12. end
  13.  
  14. -- coordinates of blocks to monitor
  15. local locations = {"-1,-1,0","0,-1,0","1,-1,0","-2,-2,-1"}
  16.  
  17. function displayPercent(percent)
  18.     net.callRemote(mon,"clear")
  19.     net.callRemote(mon,"setCursorPos",2,3)
  20.     --local display = string.format("%.2f",percent)
  21.     local display = string.sub(tostring(percent),1,4) .. "%"
  22.     net.callRemote(mon,"write",display)
  23. end
  24.  
  25.  
  26. function getEnergySpace()
  27.     local location
  28.     local total = 0
  29.     local totalStorage = 0
  30.     for i,location in ipairs(locations) do
  31.         local blockInfo = power.getTargetDetails(location)
  32.         if ( blockInfo == nil ) then
  33.             print("Can't get block info " .. location)
  34.             exit()
  35.         end
  36.         total = total + blockInfo["Stored"]
  37.         totalStorage = totalStorage + blockInfo["Capacity"]
  38.     end
  39.  
  40.     percentTotal = 100 * total / totalStorage
  41.  
  42.     displayPercent(percentTotal)
  43.    
  44.     return percentTotal
  45. end
  46.  
  47.  
  48. while true do
  49.     if ( getEnergySpace() < 95 ) then
  50.         rs.setBundledOutput("right",colors.white)
  51.         os.sleep(2)
  52.     else
  53.         rs.setBundledOutput("right",0)
  54.         os.sleep(10)
  55.     end
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement