From 28b3dc04946620269c1788992e28b5adf1f9b814 Mon Sep 17 00:00:00 2001 From: Dystroyer8 Date: Thu, 16 Jul 2026 21:46:33 +0200 Subject: [PATCH] Persist and resume Create production state --- README.md | 12 ++++++++++++ create_boiler_display.lua | 31 ++++++++++++++++++++++++++----- create_boiler_startup.lua | 10 ++++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 create_boiler_startup.lua diff --git a/README.md b/README.md index 71e8224..8e1d453 100644 --- a/README.md +++ b/README.md @@ -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 `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 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`. diff --git a/create_boiler_display.lua b/create_boiler_display.lua index e9e5ca4..13dcf8d 100644 --- a/create_boiler_display.lua +++ b/create_boiler_display.lua @@ -5,6 +5,7 @@ local REFRESH_SECONDS = 1 local MIN_WIDTH = 38 local MIN_HEIGHT = 14 local CLUTCH_OUTPUT_SIDE = "left" +local STATE_FILE = "create_boiler_state.txt" local BOILERS = { { label = "BOILER 1", position = { 11266, 64, 10810 } }, @@ -14,6 +15,26 @@ local BOILERS = { 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") if not monitor then error("Kein Monitor gefunden. Monitor direkt oder per Wired Modem verbinden.", 0) @@ -152,8 +173,7 @@ local function drawClutchButton(height) local width = monitor.getSize() -- With the external redstone-torch inverter, output ON means the clutch is -- unpowered and production runs. Output OFF is the fail-safe stopped state. - local running = redstone.getOutput(CLUTCH_OUTPUT_SIDE) - local label = running and " PRODUCTION: RUNNING " or " PRODUCTION: STOPPED " + local label = productionRunning and " PRODUCTION: RUNNING " or " PRODUCTION: STOPPED " local x = math.max(1, math.floor((width - #label) / 2) + 1) local y = math.max(13, height - 1) @@ -165,15 +185,16 @@ local function drawClutchButton(height) monitor.setBackgroundColor(colors.black) monitor.write((" "):rep(width)) 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.write(label) monitor.setBackgroundColor(colors.black) end local function toggleProduction() - local running = redstone.getOutput(CLUTCH_OUTPUT_SIDE) - redstone.setOutput(CLUTCH_OUTPUT_SIDE, not running) + productionRunning = not productionRunning + redstone.setOutput(CLUTCH_OUTPUT_SIDE, productionRunning) + saveProductionState(productionRunning) end local function render() diff --git a/create_boiler_startup.lua b/create_boiler_startup.lua new file mode 100644 index 0000000..930dfdd --- /dev/null +++ b/create_boiler_startup.lua @@ -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")