This commit is contained in:
Laurie Fisher 2025-06-27 15:31:34 +01:00
parent 890bfad815
commit 17de2953ad
Signed by: PinkEyedOrphan
GPG Key ID: 7F827B68147AEE76
2 changed files with 13 additions and 7 deletions

View File

@ -18,7 +18,6 @@ function M.setStatusCallback(fn)
statusCallback = fn statusCallback = fn
end end
-- Position and status reporting coroutine
local function reportStatusLoop() local function reportStatusLoop()
while true do while true do
local x, y, z, gpsActive = tutil.getPosition() local x, y, z, gpsActive = tutil.getPosition()
@ -26,20 +25,28 @@ local function reportStatusLoop()
string.format("GPS (%d,%d,%d)", x, y, z) or string.format("GPS (%d,%d,%d)", x, y, z) or
string.format("Manual (%d,%d,%d)", x, y, z) string.format("Manual (%d,%d,%d)", x, y, z)
local message = currentStatus .. " @ " .. posText
if statusCallback then if statusCallback then
statusCallback(currentStatus .. " @ " .. posText) statusCallback(message)
else
logger.log("Status: " .. message)
end end
logger.log("Status: " .. currentStatus .. " | " .. posText)
sleep(5) sleep(5)
end end
end end
function M.run() function M.run()
-- Register the status setter so turtleutils can call M.setStatus -- So turtleutils can update the status
tutil.setStatusCallback(M.setStatus) tutil.setStatusCallback(M.setStatus)
-- Start reporting coroutine -- Fallback: also log to file
M.setStatusCallback(function(status)
logger.log("Status update: " .. status)
end)
-- Start position + status reporting
local reporter = coroutine.create(reportStatusLoop) local reporter = coroutine.create(reportStatusLoop)
coroutine.resume(reporter) coroutine.resume(reporter)
@ -58,7 +65,6 @@ function M.run()
sleep(0.5) sleep(0.5)
end end
-- Allow reporter coroutine to yield and resume
if coroutine.status(reporter) == "suspended" then if coroutine.status(reporter) == "suspended" then
coroutine.resume(reporter) coroutine.resume(reporter)
end end

View File

@ -102,7 +102,7 @@ local function refuelIfNeeded()
string.format("Travelled: (%d,%d,%d)", x, y, z) string.format("Travelled: (%d,%d,%d)", x, y, z)
if statusCallback then if statusCallback then
statusCallback("out_of_fuel " .. posText) statusCallback("out_of_fuel - " .. posText)
end end
logger.log("No fuel. Waiting for fuel... Location: " .. posText) logger.log("No fuel. Waiting for fuel... Location: " .. posText)