turtle gps rework

This commit is contained in:
kepler155c@gmail.com 2019-02-22 03:52:47 -05:00
parent fc46239f44
commit 4485a751bd
4 changed files with 6 additions and 65 deletions

View File

@ -2,7 +2,6 @@ local GPS = { }
local device = _G.device
local gps = _G.gps
local turtle = _G.turtle
function GPS.locate(timeout, debug)
local pt = { }
@ -34,60 +33,6 @@ function GPS.getPoint(timeout, debug)
return pt
end
function GPS.getHeading(timeout, destructive)
if not turtle then
return
end
local apt = GPS.locate(timeout)
if not apt then
return false, 'GPS not available'
end
local heading = turtle.point.heading
while true do
if not turtle.inspect() and turtle.forward() then
break
end
turtle.turnRight()
if turtle.getHeading() == heading then
if destructive then
turtle.dig()
if turtle.forward() then
break
end
end
return false, 'GPS.getPoint: Unable to move forward'
end
end
local bpt = GPS.locate()
if not bpt then
return false, 'GPS not available'
end
if apt.x < bpt.x then
return 0
elseif apt.z < bpt.z then
return 1
elseif apt.x > bpt.x then
return 2
end
return 3
end
function GPS.getPointAndHeading(timeout, destructive)
local heading = GPS.getHeading(timeout, destructive)
if heading then
local pt = GPS.getPoint()
if pt then
pt.heading = heading
end
return pt
end
end
-- from stock gps API
local function trilaterate(A, B, C)
local a2b = B.position - A.position

View File

@ -45,6 +45,10 @@ function UI.Checkbox:focus()
self:draw()
end
function UI.Checkbox:setValue(v)
self.value = v
end
function UI.Checkbox:reset()
self.value = false
end

View File

@ -23,6 +23,8 @@ local config = Config.load('network', { })
if UI.term.width >= 30 then
table.insert(gridColumns, { heading = 'Fuel', key = 'fuel', width = 5 })
end
if UI.term.width >= 40 then
table.insert(gridColumns, { heading = 'Uptime', key = 'uptime' })
end

View File

@ -3,7 +3,6 @@ if not _G.turtle then
end
local Pathing = require('pathfind')
local GPS = require('gps')
local Point = require('point')
local synchronized = require('sync').sync
local Util = require('util')
@ -1241,15 +1240,6 @@ function turtle.inspectDownAt(pt) return _actionDownAt(actionsAt.inspect,
function turtle.inspectForwardAt(pt) return _actionForwardAt(actionsAt.inspect, pt) end
function turtle.inspectUpAt(pt) return _actionUpAt(actionsAt.inspect, pt) end
-- [[ GPS ]] --
function turtle.enableGPS(timeout, destructive)
local pt = GPS.getPointAndHeading(timeout, destructive)
if pt then
turtle.setPoint(pt, true)
return turtle.point
end
end
-- deprecate
function turtle.addFeatures(...)
for _,feature in pairs({ ... }) do