Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
ms "pfeifer.dev/mapd/settings"
)

const mapLoadRetryDelay = time.Second

func main() {
ms.Settings.Default() // set defaults so settings not already in param are defaulted
settingsLoaded := ms.Settings.Load() // try loading settings before cli
Expand All @@ -24,6 +26,7 @@ func main() {

state := State{}
state.Init()
var lastMapLoadAttempt time.Time

extendedState := ExtendedState{
Pub: cereal.NewPublisher("mapdExtendedOut", cereal.MapdExtendedOutCreator),
Expand Down Expand Up @@ -92,10 +95,12 @@ func main() {
if gpsSuccess {
state.DistanceSinceLastPosition = 0
state.Position = m.PosFromLocation(location)
box := state.Data.Box()
pos := m.PosFromLocation(location)
if len(state.Data.Ways()) == 0 || !box.PosInside(pos) {
box := state.Data.Box()
mapLoadTime := time.Now()
if !box.PosInside(pos) || (!state.Data.Loaded && mapLoadTime.Sub(lastMapLoadAttempt) >= mapLoadRetryDelay) {
state.Data, err = maps.FindWaysAroundPosition(pos)
lastMapLoadAttempt = mapLoadTime
if err != nil {
slog.Debug("", "error", errors.Wrap(err, "Could not find ways around location"))
continue
Expand Down
Loading