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
end
-- Position and status reporting coroutine
local function reportStatusLoop()
while true do
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("Manual (%d,%d,%d)", x, y, z)
local message = currentStatus .. " @ " .. posText
if statusCallback then
statusCallback(currentStatus .. " @ " .. posText)
statusCallback(message)
else
logger.log("Status: " .. message)
end
logger.log("Status: " .. currentStatus .. " | " .. posText)
sleep(5)
end
end
function M.run()
-- Register the status setter so turtleutils can call M.setStatus
-- So turtleutils can update the status
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)
coroutine.resume(reporter)
@ -58,7 +65,6 @@ function M.run()
sleep(0.5)
end
-- Allow reporter coroutine to yield and resume
if coroutine.status(reporter) == "suspended" then
coroutine.resume(reporter)
end

View File

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