build new class for information with pages

This commit is contained in:
2022-12-27 15:21:52 +01:00
parent 009d42f947
commit 1b0c5aa383
5 changed files with 168 additions and 110 deletions
+72
View File
@@ -0,0 +1,72 @@
/**
* @file menuInformationSites.cpp
* @author Alexander Klein (alex@kleiax.de)
* @brief Contains an implementation of the class MenuInformationSites
* @version 0.1
* @date 2022-12-27
*
* @copyright Copyright (c) 2022
*
*/
#include "menuInformationSites.h"
MenuInformationSites::MenuInformationSites(uint8_t pages) {
this->countPages = pages;
this->currentPage = 0;
this->lastMillis = millis();
}
void MenuInformationSites::up() {
if (this->currentPage == 0)
this->currentPage = this->countPages - 1;
else
this->currentPage--;
this->printMenu();
}
void MenuInformationSites::down() {
if (this->currentPage == this->countPages - 1)
this->currentPage = 0;
else
this->currentPage++;
this->printMenu();
}
void MenuInformationSites::right() {
this->yes();
}
void MenuInformationSites::left() {
if (this->parentMenu)
this->parentMenu->printMenu();
}
void MenuInformationSites::no() {
this->left();
}
void MenuInformationSites::yes() {
this->runCommand();
this->printMenu();
}
void MenuInformationSites::printMenu() {
this->printPage();
}
void MenuInformationSites::update() {
if (millis() - this->lastMillis < this->delay) {
return;
}
this->printMenu();
this->lastMillis = millis();
}
uint8_t MenuInformationSites::getCountPages() const {
return this->countPages;
}
uint8_t MenuInformationSites::getCurrentPage() const {
return this->currentPage;
}
+84
View File
@@ -0,0 +1,84 @@
/**
* @file menuInformationSites.h
* @author Alexander Klein (alex@kleiax.de)
* @brief Contains a class to print informations over more pages
* @version 0.1
* @date 2022-12-27
*
* @copyright Copyright (c) 2022
*
*/
#ifndef MENU_INFORMATION_SITES_H
#define MENU_INFORMATION_SITES_H
#include "menuControl.h"
class MenuInformationSites : public MenuControl {
public:
/**
* @brief Construct a new Menu Information Sites object
*
* @param amount of pages
*/
MenuInformationSites(uint8_t pages);
/**
* @brief Next page
*/
void down() override;
/**
* @brief Previous page
*/
void up() override;
/**
* @brief Update information
*/
void right() override;
/**
* @brief Go to the parent menu
*/
void left() override;
/**
* @brief Go to the parent menu
*/
void no() override;
/**
* @brief Update information
*/
void yes() override;
/**
* @brief Prints the Information to display and console
*
* Prints the selected page.
* The informations are only printed to the display if it
* set.
*/
void printMenu() override;
/**
* @brief can be called to update shown data
*/
void update() override;
protected:
uint8_t getCountPages() const;
uint8_t getCurrentPage() const;
virtual void printPage() const = 0;
virtual void runCommand() const {}
private:
uint8_t countPages;
uint8_t currentPage;
const uint16_t delay = 5000;
uint32_t lastMillis = 0;
};
#endif // MENU_INFORMATION_SITES_H
-4
View File
@@ -141,9 +141,7 @@ CourseCorrection Navigation::getCourseCorrection() {
}
bool Navigation::addCurrentPosToRoute() {
std::cout << "Navigation::addCurrentPosToRoute: 1" << std::endl;
if (!this->currentPosition.isValid()) { return false; }
std::cout << "Navigation::addCurrentPosToRoute: 2" << std::endl;
// First Point
if (this->route->getRouteInfo().totalPoints == 0) {
@@ -151,7 +149,6 @@ bool Navigation::addCurrentPosToRoute() {
this->lastPoint = this->currentPosition;
return true;
}
std::cout << "Navigation::addCurrentPosToRoute: 3" << std::endl;
// Every Point after the first
if (MIN_DISTANCE_BETWEEN_POINTS <= this->currentPosition.distanceTo(this->lastPoint)) {
@@ -159,7 +156,6 @@ bool Navigation::addCurrentPosToRoute() {
this->lastPoint = this->currentPosition;
return true;
}
std::cout << "Navigation::addCurrentPosToRoute: 4" << std::endl;
return false;
}
+8 -52
View File
@@ -11,56 +11,10 @@
#include "menuGPS.h"
MenuGPS::MenuGPS(DriveManager* driveManager) {
MenuGPS::MenuGPS(DriveManager* driveManager) :
MenuInformationSites(10) {
this->navigation = driveManager->getNavigation();
this->ntripClient = this->navigation->getNTRIPClient();
this->lastMillis = millis();
}
void MenuGPS::up() {
if (this->currentPage == 0)
this->currentPage = this->countPages - 1;
else
this->currentPage--;
this->printMenu();
}
void MenuGPS::down() {
if (this->currentPage == this->countPages - 1)
this->currentPage = 0;
else
this->currentPage++;
this->printMenu();
}
void MenuGPS::right() {
this->yes();
}
void MenuGPS::left() {
if (this->parentMenu)
this->parentMenu->printMenu();
}
void MenuGPS::no() {
this->left();
}
void MenuGPS::yes() {
this->runCommand();
this->printMenu();
}
void MenuGPS::printMenu() {
this->printPage();
}
void MenuGPS::update() {
if (millis() - this->lastMillis < this->delay) {
return;
}
this->printMenu();
this->lastMillis = millis();
}
void MenuGPS::printPage() const {
@@ -69,7 +23,7 @@ void MenuGPS::printPage() const {
if (gpsData)
fixType = gpsData->fixType;
switch (this->currentPage) {
switch (this->getCurrentPage()) {
case 0: {
uint8_t siv = 0;
uint32_t pDOP = 0;
@@ -192,15 +146,17 @@ void MenuGPS::printPage() const {
if (this->lcd) {
lcd->clear();
lcd->setCursor(0, 0);
lcd->printf("Page: %u", this->currentPage);
lcd->printf("Page: %u", this->getCurrentPage() + 1);
lcd->setCursor(0, 1);
lcd->printf("of %u", this->getCountPages());
}
std::cout << "Page: " << (int) this->currentPage << std::endl;
std::cout << "Page: " << (int) this->getCurrentPage() + 1 << " of " << (int) this->getCountPages() << std::endl;
break;
}
}
void MenuGPS::runCommand() const {
switch (this->currentPage) {
switch (this->getCurrentPage()) {
case 3: {
// std::cout << "MenuGPS::runCommand " << this->ntripClient->getClientState() << std::endl;
if (this->ntripClient->getClientState() == NTRIPClientStates::pushData)
+4 -54
View File
@@ -14,7 +14,7 @@
#include <SparkFun_u-blox_GNSS_Arduino_Library.h>
#include "menuControl.h"
#include "menuInformationSites.h"
#include "driveModi/driveManager.h"
#include "navigation.h"
#include "ntripClient.h"
@@ -23,7 +23,7 @@
* @brief A class to print informations about the GPS object
*
*/
class MenuGPS : public MenuControl {
class MenuGPS : public MenuInformationSites {
public:
/**
* @brief Construct a new Menu GPS object
@@ -32,62 +32,12 @@ class MenuGPS : public MenuControl {
*/
MenuGPS(DriveManager* driveManager);
/**
* @brief Next page
*/
void down() override;
/**
* @brief Previous page
*/
void up() override;
/**
* @brief Update information
*/
void right() override;
/**
* @brief Go to the parent menu
*/
void left() override;
/**
* @brief Go to the parent menu
*/
void no() override;
/**
* @brief Update information
*/
void yes() override;
/**
* @brief Prints the Information to display and console
*
* Prints the selected page.
* The informations are only printed to the display if it
* set.
*/
void printMenu() override;
/**
* @brief can be called to update shown data
*/
void update() override;
private:
const uint8_t countPages = 7;
uint8_t currentPage = 0;
void printPage() const;
void runCommand() const;
void printPage() const override;
void runCommand() const override;
NTRIPClient* ntripClient;
Navigation* navigation;
const uint16_t delay = 5000;
uint32_t lastMillis = 0;
};
#endif // MENU_GPS_H