Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local computer = require("computer")
- local math = require("math")
- local term = require("term")
- local event = require("event")
- local running = true
- --Addresses of Engine Control Units
- local ecuAddress =
- {
- "cd1ae864-e5aa-42b0-abfc-d7134e5da40f",
- "b12af19b-3357-43c6-99a5-287a0f21256d",
- "fa2cbaa6-776c-4f75-baaa-e740e64fb765",
- "27a756ad-8b67-4551-85d0-8a654b96f5e1"
- }
- --Address of RF Battery (will find automatically by default)
- local batAddress = component.list("RFBattery")()
- --Maximum power output of one generation unit in RF
- local maxOutput = 129052
- --Create ECU Proxy Table (contains component proxy, engine state, and RF output values per engine state)
- local ecu = {}
- for i = 1, #ecuAddress do
- ecu[component.proxy(ecuAddress[i])] = {curState = 0, stateOpt = {["0"] = 0, ["1"] = maxOutput / 16, ["2"] = maxOutput / 4, ["3"] = maxOutput / 2, ["4"] = maxOutput / 1}}
- end
- --Create RF Battery Proxy Table (contains component proxy, Last RF Value, Last Tick, Current RF Value, and Storage Percent)
- local bat =
- {
- proxy = component.proxy(batAddress),
- lastRF = 0,
- curRF = 0,
- curTick = 0,
- lastTick = 0,
- io = 0,
- pRF = 0
- }
- --Sync ECU State and stored state to full power
- for proxy, _ in pairs(ecu) do
- proxy.setECU(4)
- ecu[proxy].curState = 4
- end
- --Shutdown function
- function shutDown()
- running = false
- term.clear()
- return false
- end
- --Press any key to stop
- event.listen("key_down", shutDown)
- --Function to get current tick since startup
- function tick()
- local t = (computer.uptime() * 20)
- return t
- end
- --Function to set ECU state and update current state
- function ecuCon(proxy, state)
- proxy.setECU(state)
- ecu[proxy].curState = state
- end
- --Returns I/O rate of RF to/from RF Battery
- function updateBat()
- bat.curTick = tick()
- --For more accuracy we take a reading every 5 seconds
- if (bat.curTick - bat.lastTick) >= 100 then
- bat.lastRF = bat.curRF
- bat.curRF = bat.proxy.getFullStoredEnergy()
- bat.io = math.floor((bat.curRF - bat.lastRF) / (bat.curTick - bat.lastTick))
- bat.lastTick = bat.curTick
- end
- return bat.io
- end
- for proxy, _ in pairs(ecu) do
- for state,output in pairs(ecu[proxy].stateOpt) do
- print("Output: " .. output)
- end
- end
- for proxy, _ in pairs(ecu) do
- print(ecu[proxy].curState)
- end
- --[[
- while running do
- term.clear()
- local deltaRF = updateBat()
- print("Stored RF: " .. bat.curRF)
- print("Delta RF: " .. deltaRF)
- for proxy, _ in pairs(ecu) do
- ecuCon(proxy, 4)
- end
- os.sleep(0.1)
- end
- ]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement