Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Load APIs
- local component = require("component")
- local math = require("math")
- local term = require("term")
- local event = require("event")
- --Enter Engine Control Unit address(es) below (ex: {"address1", "address2"} or {"address3"}
- local ecuAddress = {"ba3fb1a8-0804-460d-9d4c-08f0a53339d7", "18d07964-e76c-48c3-83a8-b68d478270e1"}
- --Enter ONE ME Controller Address below (ex: {"address1"}
- local meAddress = {"bc4cc21f-9a05-406d-8620-ab427b5dbaed"}
- --Enter the maximum power output of ONE engine in watts
- local powMax = 67108864
- --Enter the number of watts in one AE Energy Unit. Use network tool
- --to guesstimate this number.
- wattAE = 1040
- --Do not edit below this line
- running = true
- local numECU = #ecuAddress
- local me = component.proxy(meAddress[1])
- local ecu = {}
- curGen = 0
- totalGen = 0
- powNeed = 0
- function shutDown()
- running = false
- term.clear()
- return false
- end
- event.listen("key_down", shutDown)
- --Create a table of ECU Proxies
- for i = 1, numECU do
- ecu[component.proxy(ecuAddress[i])] = {curState = 0, stateOpt = {powMax / 16, powMax / 4, powMax / 2, powMax}}
- end
- --Sync ECU power setting and saved states
- for proxy, _ in pairs(ecu) do
- proxy.setECU(4)
- ecu[proxy].curState = 4
- end
- --Main Loop
- while running do
- term.clear()
- eUse = math.floor(me.getAvgPowerUsage() * wattAE)
- powNeed = math.abs((powNeed - eUse))
- for proxy, _ in pairs(ecu) do
- if powNeed > 0 then
- if powNeed > powMax then
- proxy.setECU(4)
- ecu[proxy].curState = 4
- else
- for state, output in ipairs(ecu[proxy].stateOpt) do
- if (output - powNeed) > 0 then
- proxy.setECU(state)
- ecu[proxy].curState = state
- break
- end
- end
- end
- powNeed = (powNeed - ecu[proxy].stateOpt[ecu[proxy].curState])
- else
- proxy.setECU(0)
- ecu[proxy].curState = 0
- end
- print(ecu[proxy].curState)
- end
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement