test
This commit is contained in:
parent
890bfad815
commit
17de2953ad
18
behavior.lua
18
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
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user