Persist and resume Create production state
This commit is contained in:
@@ -44,6 +44,18 @@ Zwischen Ausgang und Clutch sitzt eine Redstone-Fackel als Fail-safe-Inverter: A
|
|||||||
bedeutet `PRODUCTION: RUNNING`; Ausgang `OFF`, Programmabbruch oder Computerneustart bedeutet
|
bedeutet `PRODUCTION: RUNNING`; Ausgang `OFF`, Programmabbruch oder Computerneustart bedeutet
|
||||||
`PRODUCTION: STOPPED`. Die Verbindung kann direkt oder ueber Create Redstone Links erfolgen.
|
`PRODUCTION: STOPPED`. Die Verbindung kann direkt oder ueber Create Redstone Links erfolgen.
|
||||||
|
|
||||||
|
Der gewuenschte Zustand wird nach jeder Touch-Bedienung in `create_boiler_state.txt` gespeichert.
|
||||||
|
Beim naechsten Programmstart wird er wiederhergestellt. Fuer automatischen Start nach einem
|
||||||
|
Computer- oder Weltneustart kann das Startprogramm als `startup.lua` installiert werden:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
wget https://git.peli-server.de/Dystroyer8/ATM10_CC_Codes/raw/branch/main/create_boiler_startup.lua startup.lua
|
||||||
|
reboot
|
||||||
|
```
|
||||||
|
|
||||||
|
Waehrend der Computer aus ist, bleibt die Hardware durch den Fackel-Inverter abgeschaltet. Erst
|
||||||
|
nach erfolgreichem Programmstart wird ein zuvor gespeicherter RUNNING-Zustand wieder aktiviert.
|
||||||
|
|
||||||
Die Boiler werden nicht anhand wechselnder Peripheral-Namen, sondern fest ueber ihre
|
Die Boiler werden nicht anhand wechselnder Peripheral-Namen, sondern fest ueber ihre
|
||||||
Controller-Koordinaten `11266/64/10810`, `11260/64/10810` und `11252/64/10810` zugeordnet.
|
Controller-Koordinaten `11266/64/10810`, `11260/64/10810` und `11252/64/10810` zugeordnet.
|
||||||
Fehlt ein Reader, bleibt dadurch exakt die betroffene Boiler-Zeile auf `MISSING / NO READER`.
|
Fehlt ein Reader, bleibt dadurch exakt die betroffene Boiler-Zeile auf `MISSING / NO READER`.
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ local REFRESH_SECONDS = 1
|
|||||||
local MIN_WIDTH = 38
|
local MIN_WIDTH = 38
|
||||||
local MIN_HEIGHT = 14
|
local MIN_HEIGHT = 14
|
||||||
local CLUTCH_OUTPUT_SIDE = "left"
|
local CLUTCH_OUTPUT_SIDE = "left"
|
||||||
|
local STATE_FILE = "create_boiler_state.txt"
|
||||||
|
|
||||||
local BOILERS = {
|
local BOILERS = {
|
||||||
{ label = "BOILER 1", position = { 11266, 64, 10810 } },
|
{ label = "BOILER 1", position = { 11266, 64, 10810 } },
|
||||||
@@ -14,6 +15,26 @@ local BOILERS = {
|
|||||||
|
|
||||||
local clutchButton = { x1 = 0, x2 = 0, y = 0 }
|
local clutchButton = { x1 = 0, x2 = 0, y = 0 }
|
||||||
|
|
||||||
|
local function loadProductionState()
|
||||||
|
if not fs.exists(STATE_FILE) then return false end
|
||||||
|
local handle = fs.open(STATE_FILE, "r")
|
||||||
|
if not handle then return false end
|
||||||
|
local saved = handle.readAll()
|
||||||
|
handle.close()
|
||||||
|
return saved == "RUNNING"
|
||||||
|
end
|
||||||
|
|
||||||
|
local function saveProductionState(running)
|
||||||
|
local handle = fs.open(STATE_FILE, "w")
|
||||||
|
if not handle then return false end
|
||||||
|
handle.write(running and "RUNNING" or "STOPPED")
|
||||||
|
handle.close()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local productionRunning = loadProductionState()
|
||||||
|
redstone.setOutput(CLUTCH_OUTPUT_SIDE, productionRunning)
|
||||||
|
|
||||||
local monitor = peripheral.find("monitor")
|
local monitor = peripheral.find("monitor")
|
||||||
if not monitor then
|
if not monitor then
|
||||||
error("Kein Monitor gefunden. Monitor direkt oder per Wired Modem verbinden.", 0)
|
error("Kein Monitor gefunden. Monitor direkt oder per Wired Modem verbinden.", 0)
|
||||||
@@ -152,8 +173,7 @@ local function drawClutchButton(height)
|
|||||||
local width = monitor.getSize()
|
local width = monitor.getSize()
|
||||||
-- With the external redstone-torch inverter, output ON means the clutch is
|
-- With the external redstone-torch inverter, output ON means the clutch is
|
||||||
-- unpowered and production runs. Output OFF is the fail-safe stopped state.
|
-- unpowered and production runs. Output OFF is the fail-safe stopped state.
|
||||||
local running = redstone.getOutput(CLUTCH_OUTPUT_SIDE)
|
local label = productionRunning and " PRODUCTION: RUNNING " or " PRODUCTION: STOPPED "
|
||||||
local label = running and " PRODUCTION: RUNNING " or " PRODUCTION: STOPPED "
|
|
||||||
local x = math.max(1, math.floor((width - #label) / 2) + 1)
|
local x = math.max(1, math.floor((width - #label) / 2) + 1)
|
||||||
local y = math.max(13, height - 1)
|
local y = math.max(13, height - 1)
|
||||||
|
|
||||||
@@ -165,15 +185,16 @@ local function drawClutchButton(height)
|
|||||||
monitor.setBackgroundColor(colors.black)
|
monitor.setBackgroundColor(colors.black)
|
||||||
monitor.write((" "):rep(width))
|
monitor.write((" "):rep(width))
|
||||||
monitor.setCursorPos(x, y)
|
monitor.setCursorPos(x, y)
|
||||||
monitor.setBackgroundColor(running and colors.lime or colors.red)
|
monitor.setBackgroundColor(productionRunning and colors.lime or colors.red)
|
||||||
monitor.setTextColor(colors.black)
|
monitor.setTextColor(colors.black)
|
||||||
monitor.write(label)
|
monitor.write(label)
|
||||||
monitor.setBackgroundColor(colors.black)
|
monitor.setBackgroundColor(colors.black)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function toggleProduction()
|
local function toggleProduction()
|
||||||
local running = redstone.getOutput(CLUTCH_OUTPUT_SIDE)
|
productionRunning = not productionRunning
|
||||||
redstone.setOutput(CLUTCH_OUTPUT_SIDE, not running)
|
redstone.setOutput(CLUTCH_OUTPUT_SIDE, productionRunning)
|
||||||
|
saveProductionState(productionRunning)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function render()
|
local function render()
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
-- Install this file as startup.lua on the Create control computer.
|
||||||
|
-- It resumes the persisted production state through create_boiler_display.lua.
|
||||||
|
|
||||||
|
if not fs.exists("create_boiler_display.lua") then
|
||||||
|
printError("create_boiler_display.lua fehlt")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
sleep(1)
|
||||||
|
shell.run("create_boiler_display.lua")
|
||||||
Reference in New Issue
Block a user