Fix direct clutch output polarity
This commit is contained in:
@@ -5,6 +5,9 @@ local REFRESH_SECONDS = 1
|
||||
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
|
||||
local STATE_FILE = "create_andesite_state.txt"
|
||||
local DEVICE_FILE = "create_andesite_devices.txt"
|
||||
|
||||
@@ -39,8 +42,13 @@ local requestedRunning = loadText(STATE_FILE) == "RUNNING"
|
||||
local devices = textutils.unserialize(loadText(DEVICE_FILE) or "") or {}
|
||||
local capacityCache = {}
|
||||
|
||||
local function setMachineRunning(running)
|
||||
local level = running and OUTPUT_LEVEL_WHEN_RUNNING or not OUTPUT_LEVEL_WHEN_RUNNING
|
||||
redstone.setOutput(CLUTCH_OUTPUT_SIDE, level)
|
||||
end
|
||||
|
||||
-- Fail safe while peripherals are being discovered.
|
||||
redstone.setOutput(CLUTCH_OUTPUT_SIDE, false)
|
||||
setMachineRunning(false)
|
||||
|
||||
local monitor = peripheral.find("monitor")
|
||||
if not monitor then
|
||||
@@ -241,7 +249,7 @@ local function evaluate()
|
||||
local allowed = not missing and not noMaterial and not outputFull and not overstressed
|
||||
local effectiveRunning = requestedRunning and allowed
|
||||
|
||||
redstone.setOutput(CLUTCH_OUTPUT_SIDE, effectiveRunning)
|
||||
setMachineRunning(effectiveRunning)
|
||||
|
||||
local status, color = "STOPPED", colors.red
|
||||
if requestedRunning then
|
||||
@@ -336,7 +344,7 @@ end
|
||||
local function safeRender()
|
||||
local ok, reason = pcall(render)
|
||||
if not ok then
|
||||
redstone.setOutput(CLUTCH_OUTPUT_SIDE, false)
|
||||
setMachineRunning(false)
|
||||
monitor.setBackgroundColor(colors.black)
|
||||
monitor.clear()
|
||||
center(1, "CONTROLLER ERROR", colors.red)
|
||||
@@ -371,5 +379,5 @@ local function run()
|
||||
end
|
||||
|
||||
local ok, reason = pcall(run)
|
||||
redstone.setOutput(CLUTCH_OUTPUT_SIDE, false)
|
||||
setMachineRunning(false)
|
||||
if not ok then error(reason, 0) end
|
||||
|
||||
Reference in New Issue
Block a user