InfOS/Programs/energyControl.lua
Gabriel Moreira Minossi 4c11905281 Capitalizing or encapsulating global variables
Making the linter happy
2021-01-06 13:03:57 -03:00

52 lines
1.2 KiB
Lua

Component = require("component")
local LSC = Component.gt_machine
local engaged = false
local function machine(address)
local machineAddress = Component.get(address)
if (machineAddress ~= nil) then
return Component.proxy(machineAddress)
else
return nil
end
end
local function getPercentage()
local currentEU = math.floor(string.gsub(LSC.getSensorInformation()[2], "([^0-9]+)", "") + 0)
local maxEU = math.floor(string.gsub(LSC.getSensorInformation()[3], "([^0-9]+)", "") + 0)
return currentEU / maxEU
end
local turbineRedstone = {
[1] = machine("928880ed")
}
local function disengage()
for i = 1, #turbineRedstone do
turbineRedstone[i].setOutput(4, 0)
end
engaged = false
end
local function engage()
for i = 1, #turbineRedstone do
turbineRedstone[i].setOutput(4, 15)
end
engaged = true
end
local function checkLevels()
local fill = getPercentage()
if fill < 0.15 then
if not engaged then
engage()
end
elseif fill > 0.95 then
if engaged then
disengage()
end
end
end
disengage()
while true do
checkLevels()
os.sleep(5)
end