Scope Andesite display to local production data

This commit is contained in:
2026-07-17 01:52:27 +02:00
parent 03a88fb2c5
commit 661becfb45
2 changed files with 21 additions and 76 deletions
+7 -6
View File
@@ -64,10 +64,9 @@ Jeder Block Reader muss direkt auf den Controller-Tank seines Boiler-Multiblocks
## Andesite-Alloy-Produktion ## Andesite-Alloy-Produktion
Der erste lokale Create-Produktionscontroller ueberwacht einen Zink-Nugget-Vault, einen Der erste lokale Create-Produktionscontroller ueberwacht einen Zink-Nugget-Vault, einen
Andesite-Alloy-Vault und die per Clutch getrennte Maschinenwelle. Die beiden Vaults muessen Andesite-Alloy-Vault und die per Clutch geschaltete Produktionsanlage. 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. Der Redstone-Ausgang `left` steuert die Clutch ueber einen Fail-safe-Inverter:
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 Redstone `ON` schaltet die Fackel aus und gibt die Welle frei; bei Redstone `OFF`, Programmabbruch
oder Computer-Ausfall stoppt die Fackel die Welle. oder Computer-Ausfall stoppt die Fackel die Welle.
@@ -80,9 +79,11 @@ create_andesite_display
Der Controller erkennt die Vaults anhand von `create:zinc_nugget` und Der Controller erkennt die Vaults anhand von `create:zinc_nugget` und
`create:andesite_alloy` und speichert ihre Peripheral-Namen. Die Freigabe wird ebenfalls `create:andesite_alloy` und speichert ihre Peripheral-Namen. Die Freigabe wird ebenfalls
gespeichert. Fehlendes Zink, ein voller Ausgang, fehlende Vault-Daten oder eine ueberlastete gespeichert. Fehlendes Zink, ein voller Ausgang oder fehlende Vault-Daten schalten die
Welle schalten die Maschinenwelle ab; nach Behebung wird eine weiterhin freigegebene Anlage Produktionsanlage ab; nach Behebung wird eine weiterhin freigegebene Anlage automatisch
automatisch fortgesetzt. Fuer den automatischen Start: fortgesetzt. Globale RPM-, Kapazitaets- und Stresswerte gehoeren in den spaeteren Create-
Serverraum, da ein Stressometer immer das gesamte zusammenhaengende kinetische Netzwerk misst.
Fuer den automatischen Start:
```lua ```lua
wget https://git.peli-server.de/Dystroyer8/ATM10_CC_Codes/raw/branch/main/create_andesite_startup.lua startup.lua wget https://git.peli-server.de/Dystroyer8/ATM10_CC_Codes/raw/branch/main/create_andesite_startup.lua startup.lua
+14 -70
View File
@@ -2,7 +2,6 @@
-- 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"
@@ -41,14 +40,10 @@ 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.
@@ -102,17 +97,6 @@ local function formatInteger(value)
return table.concat(parts, ".") return table.concat(parts, ".")
end end
local function getValueIgnoringCase(data, wantedKeys)
if type(data) ~= "table" then return nil end
for key, value in pairs(data) do
local lowered = tostring(key):lower()
for _, wanted in ipairs(wantedKeys) do
if lowered == wanted:lower() then return value end
end
end
return nil
end
local function isVault(name) local function isVault(name)
return peripheral.isPresent(name) return peripheral.isPresent(name)
and peripheral.hasType(name, "inventory") and peripheral.hasType(name, "inventory")
@@ -220,61 +204,24 @@ local function discoverVaults()
return savedZinc or getInventory(devices.zinc), savedAlloy or getInventory(devices.alloy) return savedZinc or getInventory(devices.zinc), savedAlloy or getInventory(devices.alloy)
end end
local function discoverStressometer()
for _, name in ipairs(peripheral.getNames()) do
if peripheral.hasType(name, "block_reader") then
local ok, data = pcall(peripheral.call, name, "getBlockData")
if ok and type(data) == "table" and tonumber(getValueIgnoringCase(data, { "Speed" })) then
local network = getValueIgnoringCase(data, { "Network" })
local speed = math.abs(tonumber(getValueIgnoringCase(data, { "Speed" })) or 0)
if type(network) == "table" then
local capacity = tonumber(getValueIgnoringCase(network, { "Capacity" })) or 0
local usage = tonumber(getValueIgnoringCase(network, { "Stress" })) or 0
local load = capacity > 0 and usage / capacity * 100 or 0
return speed, capacity, usage, load
end
return speed, nil, nil, nil
end
end
end
return nil, nil, nil, nil
end
local function evaluate() local function evaluate()
local zincVault, alloyVault = discoverVaults() local zincVault, alloyVault = discoverVaults()
local zinc = countItems(zincVault, ZINC_ITEMS) local zinc = countItems(zincVault, ZINC_ITEMS)
local alloy = countItems(alloyVault, ALLOY_ITEMS) local alloy = countItems(alloyVault, ALLOY_ITEMS)
local speed, capacity, usage, load = discoverStressometer()
local missing = not zincVault or not alloyVault local missing = not zincVault or not alloyVault
local noMaterial = zincVault and zinc <= 0 local noMaterial = zincVault and zinc <= 0
local outputFull = alloyVault and alloyVault.capacity > 0 and alloyVault.total >= alloyVault.capacity local outputFull = alloyVault and alloyVault.capacity > 0 and alloyVault.total >= alloyVault.capacity
local overstressed = capacity and usage and usage > capacity local allowed = not missing and not noMaterial and not outputFull
local allowed = not missing and not noMaterial and not outputFull and not overstressed
local effectiveRunning = requestedRunning and allowed local effectiveRunning = requestedRunning and allowed
local outputChanged = setMachineRunning(effectiveRunning) 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
if missing then status, color = "NO VAULT DATA", colors.red if missing then status, color = "NO VAULT DATA", colors.red
elseif noMaterial then status, color = "WAITING: NO ZINC", colors.orange elseif noMaterial then status, color = "WAITING: NO ZINC", colors.orange
elseif outputFull then status, color = "STANDBY: OUTPUT FULL", colors.orange elseif outputFull then status, color = "STANDBY: OUTPUT FULL", colors.orange
elseif overstressed then status, color = "STOPPED: OVERSTRESSED", colors.red
elseif not speed or speed == 0 then status, color = "STARTING / NO ROTATION", colors.orange
else status, color = "RUNNING", colors.lime end else status, color = "RUNNING", colors.lime end
end end
@@ -283,10 +230,8 @@ local function evaluate()
alloyVault = alloyVault, alloyVault = alloyVault,
zinc = zinc, zinc = zinc,
alloy = alloy, alloy = alloy,
speed = speed, noMaterial = noMaterial,
capacity = capacity, outputFull = outputFull,
usage = usage,
load = load,
status = status, status = status,
statusColor = color, statusColor = color,
effectiveRunning = effectiveRunning, effectiveRunning = effectiveRunning,
@@ -339,21 +284,20 @@ local function render()
drawInventory(4, "ALLOY", data.alloy, data.alloyVault, drawInventory(4, "ALLOY", data.alloy, data.alloyVault,
data.alloyVault and data.alloyVault.total >= data.alloyVault.capacity and colors.orange or colors.lime) data.alloyVault and data.alloyVault.total >= data.alloyVault.capacity and colors.orange or colors.lime)
center(6, "MACHINE SHAFT", colors.cyan) center(6, "LOCAL CONTROL", colors.cyan)
if data.speed ~= nil then if not data.zincVault then
center(7, ("Speed: %.1f RPM"):format(data.speed), data.speed > 0 and colors.lime or colors.orange) center(7, "INPUT: NO DATA", colors.red)
else else
center(7, "Speed: NO DATA", colors.red) center(7, data.noMaterial and "INPUT: EMPTY" or "INPUT: READY",
data.noMaterial and colors.orange or colors.lime)
end end
if data.capacity then if not data.alloyVault then
center(8, "SU: " .. formatInteger(data.usage) .. " / " .. formatInteger(data.capacity), colors.white) center(8, "OUTPUT: NO DATA", colors.red)
local loadText = ("Load: %.1f %%"):format(data.load):gsub("%.", ",")
center(9, loadText, data.load >= 90 and colors.red or data.load >= 70 and colors.orange or colors.lime)
else else
center(8, "Shaft network offline", colors.gray) center(8, data.outputFull and "OUTPUT: FULL" or "OUTPUT: SPACE",
data.outputFull and colors.orange or colors.lime)
end end
center(10, data.status, data.statusColor)
center(11, data.status, data.statusColor)
drawButton(height, data) drawButton(height, data)
center(height, "Touch = Anlage freigeben/stoppen", colors.gray) center(height, "Touch = Anlage freigeben/stoppen", colors.gray)
end end