refactor, added akku menu, finished autopilot menu
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* @file menuGPS.cpp
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2022-01-29
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "menuGPS.h"
|
||||
|
||||
MenuGPS::MenuGPS(TinyGPSPlus* gps) {
|
||||
this->gps = gps;
|
||||
this->last_millis = 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->printMenu();
|
||||
}
|
||||
|
||||
void MenuGPS::left() {
|
||||
if (this->parentMenu)
|
||||
this->parentMenu->printMenu();
|
||||
}
|
||||
|
||||
void MenuGPS::no() {
|
||||
this->left();
|
||||
}
|
||||
|
||||
void MenuGPS::yes() {
|
||||
this->printMenu();
|
||||
}
|
||||
|
||||
void MenuGPS::printMenu() {
|
||||
this->printPage(this->currentPage);
|
||||
}
|
||||
|
||||
void MenuGPS::update() {
|
||||
if (millis() - this->last_millis < this->delay) {
|
||||
return;
|
||||
}
|
||||
this->printMenu();
|
||||
this->last_millis = millis();
|
||||
}
|
||||
|
||||
void MenuGPS::printPage(uint8_t page) const {
|
||||
switch (this->currentPage) {
|
||||
case 0:
|
||||
if (this->lcd) {
|
||||
lcd->clear();
|
||||
lcd->setCursor(0, 0);
|
||||
if (gps->satellites.isValid() && gps->satellites.value() > 2) {
|
||||
lcd->printf("Sats: %3.d", gps->satellites.value());
|
||||
lcd->setCursor(0, 1);
|
||||
lcd->printf("HDOP: %f", gps->hdop.hdop());
|
||||
} else {
|
||||
lcd->printf("Data isn't valid");
|
||||
lcd->setCursor(0, 1);
|
||||
lcd->printf("or no GPS signal");
|
||||
}
|
||||
} else {
|
||||
if (gps->satellites.isValid() && gps->satellites.value() > 2)
|
||||
std::cout << "Sats: " << gps->satellites.value()
|
||||
<< "HDOP: " << gps->hdop.hdop() << std::endl;
|
||||
else
|
||||
std::cout << "Date isn't valid or no GPS signal" << std::endl;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if (this->lcd) {
|
||||
lcd->clear();
|
||||
lcd->setCursor(0, 0);
|
||||
if (gps->location.isValid() && gps->satellites.value() > 2) {
|
||||
lcd->printf("Lat: %9.6f", gps->location.lat());
|
||||
lcd->setCursor(0, 1);
|
||||
lcd->printf("Lng: %9.6f", gps->location.lng());
|
||||
} else {
|
||||
lcd->printf("Data isn't valid");
|
||||
lcd->setCursor(0, 1);
|
||||
lcd->printf("or NO GPS signal");
|
||||
}
|
||||
} else {
|
||||
if (gps->satellites.isValid() && gps->satellites.value() > 2)
|
||||
std::cout << "Lat: " << gps->location.lat()
|
||||
<< "Lng: " << gps->location.lng() << std::endl;
|
||||
else
|
||||
std::cout << "Date isn't valid or NO GPS signal" << std::endl;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (this->lcd) {
|
||||
lcd->clear();
|
||||
lcd->setCursor(0, 0);
|
||||
lcd->printf("Chars processed");
|
||||
lcd->setCursor(0, 1);
|
||||
lcd->printf("-> %u", gps->charsProcessed());
|
||||
} else {
|
||||
std::cout << "Chars processed: " << gps->charsProcessed() << std::endl;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (this->lcd) {
|
||||
lcd->clear();
|
||||
lcd->setCursor(0, 0);
|
||||
lcd->printf("Page: %u", page);
|
||||
} else {
|
||||
printf("Page: %u", page);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @file menuGPS.h
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2022-01-29
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MENU_GPS_H
|
||||
#define MENU_GPS_H
|
||||
|
||||
#include <TinyGPS++.h>
|
||||
|
||||
#include "menuControl.h"
|
||||
|
||||
class MenuGPS : public MenuControl {
|
||||
public:
|
||||
MenuGPS(TinyGPSPlus* gps);
|
||||
|
||||
void down();
|
||||
void up();
|
||||
void right();
|
||||
void left();
|
||||
void no();
|
||||
void yes();
|
||||
|
||||
void printMenu();
|
||||
void update();
|
||||
|
||||
private:
|
||||
const uint8_t countPages = 7;
|
||||
uint8_t currentPage = 0;
|
||||
void printPage(const uint8_t page) const;
|
||||
|
||||
TinyGPSPlus* gps;
|
||||
|
||||
const uint16_t delay = 5000;
|
||||
uint32_t last_millis = 0;
|
||||
};
|
||||
|
||||
#endif // MENU_GPS_H
|
||||
Reference in New Issue
Block a user