auto output mode - bumps target when saturation >90/95%
This commit is contained in:
+37
-4
@@ -14,6 +14,7 @@ local version = 0.3
|
||||
local autoInputGate = 1
|
||||
local curInputGate = 222000
|
||||
local targetOutput
|
||||
local autoOutputGate = 0
|
||||
|
||||
local mon, monitor, monX, monY
|
||||
|
||||
@@ -153,6 +154,7 @@ function save_config()
|
||||
sw.writeLine(autoInputGate)
|
||||
sw.writeLine(curInputGate)
|
||||
sw.writeLine(targetOutput or 0)
|
||||
sw.writeLine(autoOutputGate or 0)
|
||||
sw.close()
|
||||
end
|
||||
|
||||
@@ -161,6 +163,7 @@ function load_config()
|
||||
autoInputGate = tonumber(sr.readLine())
|
||||
curInputGate = tonumber(sr.readLine())
|
||||
targetOutput = tonumber(sr.readLine())
|
||||
autoOutputGate = tonumber(sr.readLine())
|
||||
sr.close()
|
||||
end
|
||||
|
||||
@@ -171,6 +174,9 @@ end
|
||||
if not targetOutput or targetOutput == 0 then
|
||||
targetOutput = fluxgate.getSignalLowFlow()
|
||||
end
|
||||
if not autoOutputGate then
|
||||
autoOutputGate = 0
|
||||
end
|
||||
|
||||
save_config()
|
||||
|
||||
@@ -229,6 +235,8 @@ function reactorControl()
|
||||
drawTerminalText(1, i, "Input Gate", inputFluxgate.getSignalLowFlow())
|
||||
i = i + 1
|
||||
drawTerminalText(1, i, "Target Output", targetOutput)
|
||||
i = i + 1
|
||||
drawTerminalText(1, i, "Auto Output", autoOutputGate == 1 and "ON" or "OFF")
|
||||
|
||||
-- Reactor Control Logic
|
||||
if emergencyCharge then
|
||||
@@ -363,13 +371,18 @@ function buttonControls()
|
||||
local sLength2 = (sLength+12+(string.len("Reboot"))+1)
|
||||
button.setButton("reboot", "Reboot", rebootSystem, sLength+12, 28, sLength2, 30, 0, 0, colors.blue)
|
||||
|
||||
local sLength3 = 4+(string.len("Back")+1)
|
||||
button.setButton("back", "Back", buttonMain, 4, 32, sLength3, 34, 0, 0, colors.blue)
|
||||
local autoLabel = autoOutputGate == 1 and "Auto Out:ON" or "Auto Out:OFF"
|
||||
local sLength3 = sLength2 + 11 + string.len(autoLabel)
|
||||
button.setButton("autoOut", autoLabel, toggleAutoOutput, sLength2+11, 28, sLength3, 30, 0, 0, autoOutputGate == 1 and colors.green or colors.red)
|
||||
|
||||
local sLength4 = 4+(string.len("Back")+1)
|
||||
button.setButton("back", "Back", buttonMain, 4, 32, sLength4, 34, 0, 0, colors.blue)
|
||||
|
||||
button.screen()
|
||||
end
|
||||
|
||||
function changeOutputValue(num, val)
|
||||
autoOutputGate = 0
|
||||
if val == 1 then
|
||||
targetOutput = math.min(targetOutput + num, 2000000000)
|
||||
else
|
||||
@@ -385,6 +398,12 @@ function changeOutputValue(num, val)
|
||||
save_config()
|
||||
end
|
||||
|
||||
function toggleAutoOutput()
|
||||
autoOutputGate = autoOutputGate == 1 and 0 or 1
|
||||
updateReactorInfo()
|
||||
save_config()
|
||||
end
|
||||
|
||||
|
||||
function outputMenu()
|
||||
if currentMenu == "output" then return end
|
||||
@@ -481,6 +500,19 @@ function updateReactorInfo()
|
||||
|
||||
if not ri then return end
|
||||
|
||||
if ri.status == "running" and autoOutputGate == 1 then
|
||||
local satPercent = getPercentage(ri.energySaturation, ri.maxEnergySaturation)
|
||||
local currentOutput = fluxgate.getSignalLowFlow()
|
||||
|
||||
if satPercent > 95 then
|
||||
local boost = math.max(10000, math.floor(currentOutput * 0.05))
|
||||
targetOutput = math.min(targetOutput + boost, 2000000000)
|
||||
elseif satPercent > 90 then
|
||||
local boost = math.max(5000, math.floor(currentOutput * 0.02))
|
||||
targetOutput = math.min(targetOutput + boost, 2000000000)
|
||||
end
|
||||
end
|
||||
|
||||
drawUpdatedText(4, 4, "Status:", reactorStatus(ri.status)[1], reactorStatus(ri.status)[2], colors.white)
|
||||
drawUpdatedText(4, 5, "Generation:", f.format_int(ri.generationRate).." rf/t", colors.lime, colors.yellow)
|
||||
|
||||
@@ -488,12 +520,13 @@ function updateReactorInfo()
|
||||
drawUpdatedText(4, 7, "Temperature:", f.format_int(ri.temperature).."C", tempColor, colors.lightGray)
|
||||
|
||||
local currentFlow = fluxgate.getSignalLowFlow()
|
||||
local autoTag = autoOutputGate == 1 and " [AUTO]" or " [MAN]"
|
||||
local outputText
|
||||
if currentFlow ~= targetOutput then
|
||||
local dir = currentFlow < targetOutput and " +" or " -"
|
||||
outputText = f.format_int(currentFlow).." > "..f.format_int(targetOutput).." rf/t"..dir
|
||||
outputText = f.format_int(currentFlow).." > "..f.format_int(targetOutput).." rf/t"..dir..autoTag
|
||||
else
|
||||
outputText = f.format_int(currentFlow).." rf/t"
|
||||
outputText = f.format_int(currentFlow).." rf/t"..autoTag
|
||||
end
|
||||
drawUpdatedText(4, 9, "Output:", outputText, colors.lightBlue, colors.cyan)
|
||||
drawUpdatedText(4, 10, "Input:", f.format_int(inputFluxgate.getSignalLowFlow()).." rf/t", colors.lightBlue, colors.cyan)
|
||||
|
||||
Reference in New Issue
Block a user