Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor")
- DTData = {}
- LowFuelMode = 10
- TankLevel = 0
- function initPeripherals()
- local peripheralList = peripheral.getNames()
- for i=1,#peripheralList do
- -- Sensor Tanks
- if peripheral.getType(peripheralList[i]) == "sensor" then
- sensor = peripheral.wrap(peripheralList[i])
- end
- -- Modem
- if peripheral.getType(peripheralList[i]) == "modem" then
- modem = peripheral.wrap(peripheralList[i])
- end
- end
- end
- function initTanks()
- Data = {}
- Data = sensor.getTargets()
- for k,v in pairs(Data) do
- if v.Tanks[1].Name == "tritium" and v.Name == "Dynamic Valve" then
- T = k
- elseif v.Tanks[1].Name == "deuterium" and v.Name == "Dynamic Valve" then
- D = k
- end
- end
- end
- function getData()
- local T0 = sensor.getTargetDetails(T)
- DTData["T"] = T0.Tanks[1]
- local D0 = sensor.getTargetDetails(D)
- DTData["D"] = D0.Tanks[1]
- for k,v in pairs(DTData) do
- if v["PercentFull"] < LowFuelMode then
- v["TankLevel"] = 1
- elseif v["PercentFull"] >= LowFuelMode and v["PercentFull"] < 25 then
- v["TankLevel"] = 2
- elseif v["PercentFull"] >= 25 and v["PercentFull"] < 50 then
- v["TankLevel"] = 3
- elseif v["PercentFull"] >= 50 and v["PercentFull"] < 75 then
- v["TankLevel"] = 4
- elseif v["PercentFull"] >= 75 then
- v["TankLevel"] = 5
- end
- if v["Name"] == nil then
- v["Name"] = "No Fluid"
- v["RawName"] = "No Fluid"
- v["Flow"] = 0
- v["TankLevel"] = 0
- end
- end
- end
- function getFlow()
- for k,v in pairs(DTData) do
- getData()
- local A01 = DTData[k]["Amount"]
- sleep(0.05)
- getData()
- local A02 = DTData[k]["Amount"]
- DTData[k]["Flow"] = A02 -A01
- end
- end
- initPeripherals()
- initTanks()
- getData()
- while true do
- getFlow()
- print(textutils.serialise(DTData["D"]))
- print(textutils.serialise(DTData["T"]))
- sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment