2017-09-06 01:21:43 +00:00
|
|
|
if not turtle or turtle.enableGPS then
|
2016-12-11 19:24:52 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-09-05 06:09:31 +00:00
|
|
|
requireInjector(getfenv(1))
|
2017-09-13 03:04:44 +00:00
|
|
|
|
|
|
|
local GPS = require('gps')
|
|
|
|
local Config = require('config')
|
2016-12-11 19:24:52 +00:00
|
|
|
|
2017-05-24 23:48:48 +00:00
|
|
|
function turtle.enableGPS(timeout)
|
2017-07-30 23:53:43 +00:00
|
|
|
if turtle.point.gps then
|
2017-05-24 23:48:48 +00:00
|
|
|
return turtle.point
|
|
|
|
end
|
|
|
|
|
|
|
|
local pt = GPS.getPointAndHeading(timeout)
|
2016-12-11 19:24:52 +00:00
|
|
|
if pt then
|
2017-07-24 02:37:07 +00:00
|
|
|
turtle.setPoint(pt, true)
|
|
|
|
return turtle.point
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function turtle.gotoGPSHome()
|
2017-09-13 03:04:44 +00:00
|
|
|
local config = { }
|
|
|
|
Config.load('gps', config)
|
|
|
|
|
|
|
|
if config.home then
|
2017-05-24 23:48:48 +00:00
|
|
|
if turtle.enableGPS() then
|
2017-09-13 03:04:44 +00:00
|
|
|
turtle.pathfind(config.home)
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function turtle.setGPSHome()
|
2017-09-13 03:04:44 +00:00
|
|
|
local config = { }
|
|
|
|
Config.load('gps', config)
|
|
|
|
|
2017-05-24 23:48:48 +00:00
|
|
|
if turtle.enableGPS() then
|
2017-09-13 03:04:44 +00:00
|
|
|
config.home = turtle.point
|
|
|
|
Config.update('gps', config)
|
2017-06-23 06:04:56 +00:00
|
|
|
turtle.gotoPoint(turtle.point)
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
end
|