Add touch control for test clutch

This commit is contained in:
2026-07-16 21:24:51 +02:00
parent 2eea78980e
commit 484b6a5117
2 changed files with 57 additions and 4 deletions
+50 -4
View File
@@ -4,7 +4,10 @@
local EXPECTED_BOILERS = 3
local REFRESH_SECONDS = 1
local MIN_WIDTH = 38
local MIN_HEIGHT = 11
local MIN_HEIGHT = 14
local CLUTCH_OUTPUT_SIDE = "right"
local clutchButton = { x1 = 0, x2 = 0, y = 0 }
local monitor = peripheral.find("monitor")
if not monitor then
@@ -131,6 +134,32 @@ local function formatInteger(value)
return table.concat(parts, ".")
end
local function drawClutchButton(height)
local width = monitor.getSize()
local signal = redstone.getOutput(CLUTCH_OUTPUT_SIDE)
local label = signal and " CLUTCH SIGNAL: ON " or " CLUTCH SIGNAL: OFF "
local x = math.max(1, math.floor((width - #label) / 2) + 1)
local y = math.max(13, height - 1)
clutchButton.x1 = x
clutchButton.x2 = math.min(width, x + #label - 1)
clutchButton.y = y
monitor.setCursorPos(1, y)
monitor.setBackgroundColor(colors.black)
monitor.write((" "):rep(width))
monitor.setCursorPos(x, y)
monitor.setBackgroundColor(signal and colors.orange or colors.gray)
monitor.setTextColor(colors.black)
monitor.write(label)
monitor.setBackgroundColor(colors.black)
end
local function toggleClutchSignal()
local signal = redstone.getOutput(CLUTCH_OUTPUT_SIDE)
redstone.setOutput(CLUTCH_OUTPUT_SIDE, not signal)
end
local function render()
local _, height = monitor.getSize()
local boilers, networks = discoverReaders()
@@ -157,13 +186,14 @@ local function render()
center(9, "Reader auf Speed-/Stressometer", colors.orange)
end
if height >= 13 then center(height, "Nur Anzeige - keine Steuerung", colors.gray) end
drawClutchButton(height)
center(height, "Touch = Redstone umschalten", colors.gray)
monitor.setTextColor(colors.white)
monitor.setBackgroundColor(colors.black)
term.setCursorPos(1, 1)
end
while true do
local function safeRender()
local ok, reason = pcall(render)
if not ok then
monitor.setBackgroundColor(colors.black)
@@ -171,5 +201,21 @@ while true do
center(1, "ANZEIGEFEHLER", colors.red)
center(3, tostring(reason), colors.orange)
end
sleep(REFRESH_SECONDS)
end
safeRender()
local refreshTimer = os.startTimer(REFRESH_SECONDS)
while true do
local event, first, second, third = os.pullEvent()
if event == "timer" and first == refreshTimer then
safeRender()
refreshTimer = os.startTimer(REFRESH_SECONDS)
elseif event == "monitor_touch" then
local x, y = second, third
if y == clutchButton.y and x >= clutchButton.x1 and x <= clutchButton.x2 then
toggleClutchSignal()
safeRender()
end
end
end