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
|
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
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user