Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: rm_you on Aug 20th, 2012  |  syntax: Lua  |  size: 2.63 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. os.unloadAPI("sensors");
  2. os.unloadAPI("sensorsUI");
  3. os.loadAPI("/rom/apis/sensors");
  4. os.loadAPI("/rom/apis/sensorsUI");
  5.  
  6. tArgs={...};
  7. --writeAt=sensorsUI.writeAt
  8. sizeX, sizeY = term.getSize()
  9. side = sensors.getController()
  10. monside,mon =sensorsUI.getMonitor()
  11.  
  12. data = sensors.getSensors(side)
  13. mainSensor = data[1]
  14.  
  15. probes = sensors.getProbes(side,mainSensor)
  16. nukeProbe = probes[2]
  17. storageProbe = probes[3]
  18.  
  19. targets = sensors.getAvailableTargetsforProbe(side,mainSensor,nukeProbe);
  20. nukeTarget = targets[1]
  21.  
  22. local lastHeat = 0
  23. local lastEnergy = 0
  24. local tickRate = 5
  25.  
  26. function readData(side,sSensor,sProbe,sTarget)
  27.         readings = sensors.getSensorReadingAsDict(side,sSensor,sTarget,sProbe);
  28.         return readings;
  29. end
  30.  
  31. function printData(mon, data)
  32.         mon.clear()
  33.         mon.setTextScale(2)
  34.         --line = 1
  35.         --for i,v in pairs(data) do
  36.         --      mon.setCursorPos(1,line)
  37.         --      --print(i .. ": " .. tostring(v))
  38.         --      mon.write(i .. ": " .. tostring(v))
  39.         --      line = line + 1
  40.         --end
  41.        
  42.         heat = data["heat"]
  43.         energy = data["currentEnergy"]
  44.         deltaHeat = (lastHeat - heat) / tickRate
  45.         deltaEnergy = (lastEnergy - energy) / tickRate
  46.         lastHeat = heat
  47.         lastEnergy = energy
  48.  
  49.         mon.setCursorPos(1,1)
  50.         mon.write("********* Reactor **********")
  51.  
  52.         mon.setCursorPos(1,2)
  53.         mon.write("Heat:      " .. heat .. " @ " .. deltaHeat )
  54.         mon.setCursorPos(1,3)
  55.         mon.write("Output:    " .. data["output"])
  56.         mon.setCursorPos(1,4)
  57.         mon.write("----------------------------")
  58.  
  59.         mon.setCursorPos(1,6)
  60.         mon.write("********* Storage **********")
  61.         mon.setCursorPos(1,7)
  62.         mon.write("Current:   " .. energy .. " @ " .. deltaEnergy)
  63.         mon.setCursorPos(1,8)
  64.         mon.write("Max:       " .. data["maxEnergy"])
  65.         mon.setCursorPos(1,9)
  66.         mon.write("----------------------------")
  67. end
  68.  
  69. function getMFSUReadings(side, sSensor, sProbe)
  70.         storageReadings = sensors.getAvailableTargetsforProbe(side,sSensor,sProbe);
  71.         max = 0
  72.         energy = 0
  73.         for key,val in pairs(storageReadings) do
  74.                 --print(key..": "..val)
  75.                 if string.match(val,"MFSU") then
  76.                         readings = sensors.getSensorReadingAsDict(side,sSensor,val,sProbe);
  77.                         max = max + readings["maxStorage"]
  78.                         energy = energy + readings["energy"]
  79.                         if readings["addedToEnergyNet"] ~= true then
  80.                                 print("Warning! MFSU Offline!")
  81.                         end
  82.                 end
  83.         end
  84.         ret = { maxEnergy=max, currentEnergy=energy };
  85.         return ret;
  86. end
  87.  
  88. while true do
  89.         nukeReadings = readData(side,mainSensor,nukeProbe,nukeTarget)
  90.         storageReadings = getMFSUReadings(side,mainSensor,storageProbe)
  91.         allReadings = {}
  92.         for k,v in pairs(nukeReadings) do allReadings[k] = v end
  93.         for k,v in pairs(storageReadings) do allReadings[k] = v end
  94.         printData(mon, allReadings)
  95.         sleep(tickRate)
  96. end