diff --git a/README.md b/README.md index 7f54726..ad998d0 100644 --- a/README.md +++ b/README.md @@ -67,9 +67,9 @@ Der erste lokale Create-Produktionscontroller ueberwacht einen Zink-Nugget-Vault Andesite-Alloy-Vault und die per Clutch getrennte Maschinenwelle. Die beiden Vaults muessen jeweils direkt ueber einen aktivierten Wired Modem Full Block als Inventory-Peripheral mit dem Computer verbunden sein. Ein Advanced-Peripherals Block Reader zeigt auf das Stressometer der -Maschinenwelle. Der Redstone-Ausgang `left` steuert die Clutch in der aktuellen Installation -direkt: Redstone `ON` stoppt die Welle und Redstone `OFF` gibt sie frei. Die Polaritaet ist im -Programm ueber `OUTPUT_LEVEL_WHEN_RUNNING` konfigurierbar. +Maschinenwelle. Der Redstone-Ausgang `left` steuert die Clutch ueber einen Fail-safe-Inverter: +Redstone `ON` schaltet die Fackel aus und gibt die Welle frei; bei Redstone `OFF`, Programmabbruch +oder Computer-Ausfall stoppt die Fackel die Welle. Installation und erster Start: diff --git a/create_andesite_display.lua b/create_andesite_display.lua index 2d9cd0c..7f4fc55 100644 --- a/create_andesite_display.lua +++ b/create_andesite_display.lua @@ -2,12 +2,12 @@ -- Two Create Item Vaults are discovered by their contents and remembered. local REFRESH_SECONDS = 1 +local SENSOR_SETTLE_SECONDS = 0.15 local MIN_WIDTH = 28 local MIN_HEIGHT = 13 local CLUTCH_OUTPUT_SIDE = "left" --- This installation drives the Clutch directly: powered means stopped. --- Change to true if a redstone-torch inverter is installed later. -local OUTPUT_LEVEL_WHEN_RUNNING = false +-- The external redstone-torch inverter makes output ON release the Clutch. +local OUTPUT_LEVEL_WHEN_RUNNING = true local STATE_FILE = "create_andesite_state.txt" local DEVICE_FILE = "create_andesite_devices.txt" @@ -41,10 +41,14 @@ end local requestedRunning = loadText(STATE_FILE) == "RUNNING" local devices = textutils.unserialize(loadText(DEVICE_FILE) or "") or {} local capacityCache = {} +local lastAppliedRunning = nil local function setMachineRunning(running) local level = running and OUTPUT_LEVEL_WHEN_RUNNING or not OUTPUT_LEVEL_WHEN_RUNNING redstone.setOutput(CLUTCH_OUTPUT_SIDE, level) + local changed = lastAppliedRunning ~= running + lastAppliedRunning = running + return changed end -- Fail safe while peripherals are being discovered. @@ -249,7 +253,20 @@ local function evaluate() local allowed = not missing and not noMaterial and not outputFull and not overstressed local effectiveRunning = requestedRunning and allowed - setMachineRunning(effectiveRunning) + local outputChanged = setMachineRunning(effectiveRunning) + + -- Create updates the kinetic network after the redstone event. Without a + -- short settling period, the first frame after a touch shows the previous + -- state and therefore looks inverted. + if outputChanged then + sleep(SENSOR_SETTLE_SECONDS) + speed, capacity, usage, load = discoverStressometer() + overstressed = capacity and usage and usage > capacity + if overstressed and effectiveRunning then + effectiveRunning = false + setMachineRunning(false) + end + end local status, color = "STOPPED", colors.red if requestedRunning then