Start with Capture Route

This commit is contained in:
2022-01-31 21:12:11 +01:00
parent ab4ceb8b09
commit d356b28ffb
24 changed files with 327 additions and 320 deletions
+15 -28
View File
@@ -23,29 +23,24 @@ void Menu::addEntry(MenuAction* entry) {
void Menu::printMenu() {
if (this->lcd) {
MenuAction* selectedEntry = *(this->it);
lcd->clear();
lcd->setCursor(0, 0);
lcd->print("-> ");
lcd->print(selectedEntry->getName());
lcd->print((**this->it).getName());
lcd->setCursor(0, 1);
std::list<MenuAction*>::iterator iter = this->it;
iter++;
if (iter != this->entrys.end()) {
selectedEntry = *iter;
lcd->print(selectedEntry->getName());
} else {
selectedEntry = *this->entrys.begin();
lcd->print(selectedEntry->getName());
}
lcd->print((**iter).getName());
} else
lcd->print((*this->entrys.begin())->getName());
} else {
std::cout << std::endl;
for (std::list<MenuAction*>::iterator iter = this->entrys.begin(); iter != this->entrys.end(); iter++) {
MenuAction* selectedEntry = *(iter);
if (this->it == iter)
std::cout << " " << selectedEntry->getName() << std::endl;
std::cout << " " << (**iter).getName() << std::endl;
else
std::cout << selectedEntry->getName() << std::endl;
std::cout << (**iter).getName() << std::endl;
}
}
this->inSubmenu = false;
@@ -53,8 +48,7 @@ void Menu::printMenu() {
void Menu::down() {
if (this->inSubmenu) {
MenuAction* selectedEntry = *(this->it);
selectedEntry->getMenu()->down();
(**this->it).getMenu()->down();
return;
}
@@ -70,8 +64,7 @@ void Menu::down() {
void Menu::up() {
if (this->inSubmenu) {
MenuAction* selectedEntry = *(this->it);
selectedEntry->getMenu()->up();
(**this->it).getMenu()->up();
return;
}
std::list<MenuAction*>::iterator iter = this->entrys.end();
@@ -86,25 +79,21 @@ void Menu::up() {
}
void Menu::right() {
// TODO: find out why i cannot call runAction() directly from the iterator
MenuAction* selectedEntry = *(this->it);
if (this->inSubmenu) {
selectedEntry->getMenu()->right();
(**this->it).getMenu()->right();
return;
}
if (selectedEntry->getIsMenu()) {
if ((**this->it).getIsMenu()) {
this->inSubmenu = true;
selectedEntry->getMenu()->setParentMenu(this);
(**this->it).getMenu()->setParentMenu(this);
}
selectedEntry->runAction();
(**this->it).runAction();
}
void Menu::left() {
if (this->inSubmenu) {
MenuAction* selectedEntry = *(this->it);
selectedEntry->getMenu()->left();
(**this->it).getMenu()->left();
return;
}
@@ -114,8 +103,7 @@ void Menu::left() {
void Menu::yes() {
if (this->inSubmenu) {
MenuAction* selectedEntry = *(this->it);
selectedEntry->getMenu()->yes();
(**this->it).getMenu()->yes();
return;
}
@@ -124,8 +112,7 @@ void Menu::yes() {
void Menu::no() {
if (this->inSubmenu) {
MenuAction* selectedEntry = *(this->it);
selectedEntry->getMenu()->no();
(**this->it).getMenu()->no();
return;
}
-2
View File
@@ -1,2 +0,0 @@
#include "coordinate.h"
-31
View File
@@ -1,31 +0,0 @@
/**
* @file coordinate.h
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @version 0.1
* @date 2022-01-10
*
* @copyright Copyright (c) 2022
*
*/
#ifndef COORDINATE_H
#define COORDINATE_H
#include <stdint.h>
class Coordinate {
public:
Coordinate(/* args */);
~Coordinate();
double getDistance(Coordinate coordinate);
uint16_t getCompassDirection(Coordinate coordinate);
private:
double lon;
double lat;
};
#endif // COORDINATE_H
+27
View File
@@ -1,2 +1,29 @@
/**
* @file navigation.cpp
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @version 0.1
* @date 2022-01-31
*
* @copyright Copyright (c) 2022
*
*/
#include "navigation.h"
Navigation::Navigation(uint8_t rx, uint8_t tx) {
this->gps = new TinyGPSPlus();
Serial1.begin(9600, SERIAL_8N1, rx, tx);
}
void Navigation::loop() {
gps->encode(Serial1.read());
}
void Navigation::addCurrentPosToRoute() {
Point p;
if (this->gps->location.isUpdated() && this->gps->location.isValid()) {
p.lat = this->gps->location.lat();
p.lon = this->gps->location.lng();
}
}
+8 -8
View File
@@ -12,22 +12,22 @@
#ifndef NAVIGATION_H
#define NAVIGATION_H
#include <TinyGPS++.h>
#include <Arduino.h>
#include "coordinate.h"
#include "route.h"
class Navigation {
public:
Navigation(uint32_t baud, uint8_t rx, uint8_t tx);
Navigation(uint8_t rx, uint8_t tx);
void loop();
void addCoordinateToRoute(Coordinate coordinate);
void addCurrentCoordinateToRoute();
void delRoute();
void addCurrentPosToRoute();
double getDistanceToLastCoordinate();
TinyGPSPlus* getGPS() { return this->gps; }
private:
Coordinate *lastCoordinate;
TinyGPSPlus* gps;
Route* route;
};
#endif // NAVIGATION_H
+32
View File
@@ -0,0 +1,32 @@
/**
* @file route.cpp
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @version 0.1
* @date 2022-01-31
*
* @copyright Copyright (c) 2022
*
*/
#include "route.h"
Route::Route() {
}
void Route::addPointToRoute(Point point) {
this->points.push_back(point);
}
Point Route::startRoute() {
*this->it = this->points.begin();
return **this->it;
}
Point Route::getNextPoint() {
if (*this->it != this->points.end())
return **this->it;
else
return Point(0, 0);
}
+48
View File
@@ -0,0 +1,48 @@
/**
* @file route.h
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @version 0.1
* @date 2022-01-31
*
* @copyright Copyright (c) 2022
*
*/
#ifndef ROUTE_H
#define ROUTE_H
#include <cstdint>
#include <list>
class Point{
public:
Point(double lat, double lon) {this->lat = lat; this->lon = lon;}
double lat = 0;
double lon = 0;
bool operator==(const Point& rhs) const {
return this->lat == rhs.lat && this->lon == rhs.lon;
}
};
class Route {
public:
Route();
void addPointToRoute(Point point);
Point startRoute();
Point getNextPoint();
uint16_t getNumberOfPoints() { return this->count_points; }
private:
uint16_t count_points = 0;
std::list<Point> points;
std::list<Point>::iterator* it;
};
#endif // ROUTE_H