From 523c170f56c3d468e3308d21acf5308861252186 Mon Sep 17 00:00:00 2001 From: Alexander Klein Date: Wed, 4 Jan 2023 00:18:35 +0100 Subject: [PATCH] added imported to PointAccuracy --- lib/Navigation/route.cpp | 43 ++++++++++++++++++++++++++++++++++------ lib/Navigation/route.h | 6 +++++- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/lib/Navigation/route.cpp b/lib/Navigation/route.cpp index b1d8797..e90c2ce 100644 --- a/lib/Navigation/route.cpp +++ b/lib/Navigation/route.cpp @@ -28,6 +28,14 @@ Point::Point(Coordinates coords, uint32_t horizontalAccuracy) { this->init(horizontalAccuracy); } +Point::Point(Coordinates coords, bool imported) { + this->coordinates = coords; + if (imported) + this->init(UINT32_MAX); + else + this->init(0); +} + Point::Point() { this->coordinates.lat = 0; this->coordinates.lon = 0; @@ -80,17 +88,22 @@ int16_t Point::courseTo(const Point &point) const { void Point::init(uint32_t horizontalAccuracy) { this->creationTime = millis(); - if (horizontalAccuracy > 9999) + + if (horizontalAccuracy == UINT32_MAX) + this->accuracy = PointAccuracy::imported; + else if (horizontalAccuracy > 9999) this->accuracy = PointAccuracy::fourDigOfCM; else if (horizontalAccuracy > 999) this->accuracy = PointAccuracy::threeDigOfCM; else if (horizontalAccuracy > 99) this->accuracy = PointAccuracy::twoDigOfCM; + else + this->accuracy = PointAccuracy::oneDigOfCM; } Route::Route() { - + } void Route::addPointToRoute(Point point) { @@ -99,25 +112,40 @@ void Route::addPointToRoute(Point point) { void Route::clear() { this->points.clear(); + this->currentPoint = 0; + this->started = false; } Point Route::startRoute() { - if (this->points.size() < 1) - return Point(0, 0); + if (this->points.size() < 1) { + this->started = false; + return Point(); + } + this->it = this->points.begin(); this->currentPoint = 1; + this->started = true; return *this->it; } Point Route::endRoute() { - if (this->points.size() < 1) - return Point(0, 0); + if (this->points.size() < 1) { + this->started = false; + return Point(); + } + this->it = this->points.end(); + // TODO: Understand why i have to decrement the iterator first to get realy the last element. + this->it--; this->currentPoint = this->points.size(); + this->started = true; return *this->it; } Point Route::getNextPoint() { + if (!this->started) + return Point(); + if (this->it != this->points.end()) { this->it++; this->currentPoint++; @@ -130,6 +158,9 @@ Point Route::getNextPoint() { } Point Route::getPreviousPoint() { + if (!this->started) + return Point(); + if (this->it != this->points.begin()) { this->it--; this->currentPoint--; diff --git a/lib/Navigation/route.h b/lib/Navigation/route.h index 2cbf3cd..0968502 100644 --- a/lib/Navigation/route.h +++ b/lib/Navigation/route.h @@ -44,7 +44,8 @@ class Point{ fourDigOfCM, threeDigOfCM, twoDigOfCM, - oneDigOfCM + oneDigOfCM, + imported }; @@ -57,6 +58,7 @@ class Point{ Point(double lat, double lon, uint32_t horizontalAccuracy = 0); Point(int32_t lat, int32_t lon, uint32_t horizontalAccuracy = 0); Point(Coordinates coords, uint32_t horizontalAccuracy = 0); + Point(Coordinates coords, bool imported); Point(); /** @@ -155,9 +157,11 @@ class Route { * @return RouteInfo */ RouteInfo getRouteInfo(); + bool getStarted() const { return this->started; } private: uint16_t currentPoint = 0; + bool started = false; std::list points; std::list::iterator it;