Adapt boiler display for shared main shaft

This commit is contained in:
2026-07-16 20:50:42 +02:00
parent a91b354295
commit aac7e4f52d
2 changed files with 64 additions and 42 deletions
+57 -35
View File
@@ -1,9 +1,9 @@
-- Create boiler status board for CC:Tweaked.
-- Hardware:
-- * one monitor
-- * one Create Speedometer per boiler
-- * one Create Speedometer on the shared main shaft
-- * one Create Stressometer on the main shaft
-- * optionally one Advanced Peripherals Block Reader per boiler controller
-- * one Advanced Peripherals Block Reader per boiler controller
-- Everything must be connected to the computer, preferably using Wired Modems.
local EXPECTED_BOILERS = 3
@@ -76,39 +76,53 @@ local function findBoilerData(data, visited)
return nil
end
local function readHeatMode(readerName)
if not readerName then return "UNKNOWN" end
local function readBoiler(readerName)
if not readerName then return "MISSING", "UNKNOWN", colors.red end
local ok, data = pcall(peripheral.call, readerName, "getBlockData")
if not ok then return "ERROR" end
if not ok then return "ERROR", "UNKNOWN", colors.red end
local boiler = findBoilerData(data)
if not boiler then return "UNKNOWN" end
if not boiler then return "NO DATA", "UNKNOWN", colors.red end
local passive = getValueIgnoringCase(boiler, { "PassiveHeat", "passive" })
local heat = tonumber(getValueIgnoringCase(boiler,
{ "Heat", "activeHeat", "actualHeat", "boilerLevel", "level" }))
{ "Heat", "activeHeat", "actualHeat" }))
local supply = tonumber(getValueIgnoringCase(boiler,
{ "Supply", "waterSupply", "gatheredSupply" }))
local engines = tonumber(getValueIgnoringCase(boiler,
{ "Engines", "attachedEngines" }))
local active = getValueIgnoringCase(boiler,
{ "Active", "isActive", "prevActive" })
if passive == true or passive == 1 then return "CAMPFIRE" end
if heat and heat >= 18 then return "SUPERHEATED" end
if heat and heat > 0 then return "HEATED" end
return "COLD"
local heatMode
if passive == true or passive == 1 then
heatMode = "CAMPFIRE"
elseif heat and heat >= 18 then
heatMode = "SUPERHEATED"
elseif heat and heat > 0 then
heatMode = "HEATED"
else
heatMode = "COLD"
end
if active == nil then
local hasHeat = heatMode ~= "COLD"
local hasWater = supply == nil or supply > 0
local hasEngines = engines == nil or engines > 0
active = hasHeat and hasWater and hasEngines
end
if active == true or active == 1 then
return "ONLINE", heatMode, colors.lime
end
return "STANDBY", heatMode, colors.orange
end
local function readBoiler(name, readerName)
if not name then
return "MISSING", 0, "UNKNOWN", colors.red
end
local ok, speed = pcall(peripheral.call, name, "getSpeed")
if not ok or type(speed) ~= "number" then
return "ERROR", 0, "UNKNOWN", colors.red
end
speed = math.abs(speed)
if speed < 0.5 then
return "STANDBY", 0, readHeatMode(readerName), colors.orange
end
return "ONLINE", speed, readHeatMode(readerName), colors.lime
local function readMainSpeed(speedometerName)
if not speedometerName then return nil end
local ok, speed = pcall(peripheral.call, speedometerName, "getSpeed")
if not ok or type(speed) ~= "number" then return nil end
return math.abs(speed)
end
local function formatInteger(value)
@@ -147,28 +161,36 @@ local function render()
center(1, "CREATE KRAFTWERK", colors.cyan)
local firstRow = 3
for index = 1, EXPECTED_BOILERS do
local state, speed, heatMode, color = readBoiler(speedometers[index], readers[index])
local state, heatMode, color = readBoiler(readers[index])
local row = firstRow + index - 1
if row <= height then
center(row, ("BOILER %d %-7s %5.1f RPM %s")
:format(index, state, speed, heatMode), color)
center(row, ("BOILER %d %-7s %s")
:format(index, state, heatMode), color)
end
end
local speed = readMainSpeed(speedometers[1])
local capacity, usage, load = readMainShaft(stressometers[1])
if height >= 7 then center(7, "MAIN SHAFT", colors.cyan) end
if height >= 8 then
if speed then
center(8, ("Speed: %.1f RPM"):format(speed), speed > 0 and colors.lime or colors.orange)
else
center(8, "Speedometer nicht gefunden", colors.red)
end
end
if capacity then
if height >= 8 then center(8, "Capacity: " .. formatInteger(capacity) .. " SU", colors.white) end
if height >= 9 then center(9, "Usage: " .. formatInteger(usage) .. " SU", colors.white) end
if height >= 10 then
if height >= 9 then center(9, "Capacity: " .. formatInteger(capacity) .. " SU", colors.white) end
if height >= 10 then center(10, "Usage: " .. formatInteger(usage) .. " SU", colors.white) end
if height >= 11 then
local loadText = ("Load: %.1f %%"):format(load):gsub("%.", ",")
center(10, loadText, load >= 90 and colors.red or load >= 70 and colors.orange or colors.lime)
center(11, loadText, load >= 90 and colors.red or load >= 70 and colors.orange or colors.lime)
end
else
if height >= 8 then center(8, "Stressometer nicht gefunden", colors.red) end
if height >= 9 then center(9, "Stressometer nicht gefunden", colors.red) end
end
if height >= 12 then
if height >= 13 then
center(height, "Nur Anzeige - keine Steuerung", colors.gray)
end