From 17de2953ad05e06095f11e8a33a2baf292e0d98f Mon Sep 17 00:00:00 2001 From: Laurie Fisher Date: Fri, 27 Jun 2025 15:31:34 +0100 Subject: [PATCH] test --- behavior.lua | 18 ++++++++++++------ libs/turtleutils.lua | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/behavior.lua b/behavior.lua index 54b77a7..b6d08c0 100644 --- a/behavior.lua +++ b/behavior.lua @@ -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 diff --git a/libs/turtleutils.lua b/libs/turtleutils.lua index 316b5b4..65d8682 100644 --- a/libs/turtleutils.lua +++ b/libs/turtleutils.lua @@ -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)