Synchronize stress readings after clutch changes
This commit is contained in:
@@ -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
|
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
|
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
|
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
|
Maschinenwelle. Der Redstone-Ausgang `left` steuert die Clutch ueber einen Fail-safe-Inverter:
|
||||||
direkt: Redstone `ON` stoppt die Welle und Redstone `OFF` gibt sie frei. Die Polaritaet ist im
|
Redstone `ON` schaltet die Fackel aus und gibt die Welle frei; bei Redstone `OFF`, Programmabbruch
|
||||||
Programm ueber `OUTPUT_LEVEL_WHEN_RUNNING` konfigurierbar.
|
oder Computer-Ausfall stoppt die Fackel die Welle.
|
||||||
|
|
||||||
Installation und erster Start:
|
Installation und erster Start:
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
-- Two Create Item Vaults are discovered by their contents and remembered.
|
-- Two Create Item Vaults are discovered by their contents and remembered.
|
||||||
|
|
||||||
local REFRESH_SECONDS = 1
|
local REFRESH_SECONDS = 1
|
||||||
|
local SENSOR_SETTLE_SECONDS = 0.15
|
||||||
local MIN_WIDTH = 28
|
local MIN_WIDTH = 28
|
||||||
local MIN_HEIGHT = 13
|
local MIN_HEIGHT = 13
|
||||||
local CLUTCH_OUTPUT_SIDE = "left"
|
local CLUTCH_OUTPUT_SIDE = "left"
|
||||||
-- This installation drives the Clutch directly: powered means stopped.
|
-- The external redstone-torch inverter makes output ON release the Clutch.
|
||||||
-- Change to true if a redstone-torch inverter is installed later.
|
local OUTPUT_LEVEL_WHEN_RUNNING = true
|
||||||
local OUTPUT_LEVEL_WHEN_RUNNING = false
|
|
||||||
local STATE_FILE = "create_andesite_state.txt"
|
local STATE_FILE = "create_andesite_state.txt"
|
||||||
local DEVICE_FILE = "create_andesite_devices.txt"
|
local DEVICE_FILE = "create_andesite_devices.txt"
|
||||||
|
|
||||||
@@ -41,10 +41,14 @@ end
|
|||||||
local requestedRunning = loadText(STATE_FILE) == "RUNNING"
|
local requestedRunning = loadText(STATE_FILE) == "RUNNING"
|
||||||
local devices = textutils.unserialize(loadText(DEVICE_FILE) or "") or {}
|
local devices = textutils.unserialize(loadText(DEVICE_FILE) or "") or {}
|
||||||
local capacityCache = {}
|
local capacityCache = {}
|
||||||
|
local lastAppliedRunning = nil
|
||||||
|
|
||||||
local function setMachineRunning(running)
|
local function setMachineRunning(running)
|
||||||
local level = running and OUTPUT_LEVEL_WHEN_RUNNING or not OUTPUT_LEVEL_WHEN_RUNNING
|
local level = running and OUTPUT_LEVEL_WHEN_RUNNING or not OUTPUT_LEVEL_WHEN_RUNNING
|
||||||
redstone.setOutput(CLUTCH_OUTPUT_SIDE, level)
|
redstone.setOutput(CLUTCH_OUTPUT_SIDE, level)
|
||||||
|
local changed = lastAppliedRunning ~= running
|
||||||
|
lastAppliedRunning = running
|
||||||
|
return changed
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Fail safe while peripherals are being discovered.
|
-- 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 allowed = not missing and not noMaterial and not outputFull and not overstressed
|
||||||
local effectiveRunning = requestedRunning and allowed
|
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
|
local status, color = "STOPPED", colors.red
|
||||||
if requestedRunning then
|
if requestedRunning then
|
||||||
|
|||||||
Reference in New Issue
Block a user