added update for menu

This commit is contained in:
2022-02-01 18:25:23 +01:00
parent d356b28ffb
commit 15fd17e058
6 changed files with 139 additions and 45 deletions
+27 -20
View File
@@ -11,14 +11,14 @@
#include "menu.h" #include "menu.h"
Menu::Menu() { Menu::Menu() {
this->it = this->entrys.begin(); this->selectedEntry = this->entrys.begin();
} }
void Menu::addEntry(MenuAction* entry) { void Menu::addEntry(MenuAction* entry) {
this->entrys.push_back(entry); this->entrys.push_back(entry);
if (this->entrys.size() == 2) if (this->entrys.size() == 2)
this->it = this->entrys.begin(); this->selectedEntry = this->entrys.begin();
} }
void Menu::printMenu() { void Menu::printMenu() {
@@ -26,9 +26,9 @@ void Menu::printMenu() {
lcd->clear(); lcd->clear();
lcd->setCursor(0, 0); lcd->setCursor(0, 0);
lcd->print("-> "); lcd->print("-> ");
lcd->print((**this->it).getName()); lcd->print((**this->selectedEntry).getName());
lcd->setCursor(0, 1); lcd->setCursor(0, 1);
std::list<MenuAction*>::iterator iter = this->it; std::list<MenuAction*>::iterator iter = this->selectedEntry;
iter++; iter++;
if (iter != this->entrys.end()) { if (iter != this->entrys.end()) {
lcd->print((**iter).getName()); lcd->print((**iter).getName());
@@ -37,7 +37,7 @@ void Menu::printMenu() {
} else { } else {
std::cout << std::endl; std::cout << std::endl;
for (std::list<MenuAction*>::iterator iter = this->entrys.begin(); iter != this->entrys.end(); iter++) { for (std::list<MenuAction*>::iterator iter = this->entrys.begin(); iter != this->entrys.end(); iter++) {
if (this->it == iter) if (this->selectedEntry == iter)
std::cout << " " << (**iter).getName() << std::endl; std::cout << " " << (**iter).getName() << std::endl;
else else
std::cout << (**iter).getName() << std::endl; std::cout << (**iter).getName() << std::endl;
@@ -46,54 +46,61 @@ void Menu::printMenu() {
this->inSubmenu = false; this->inSubmenu = false;
} }
void Menu::update() {
if (this->inSubmenu) {
(**this->selectedEntry).getMenu()->update();
return;
}
}
void Menu::down() { void Menu::down() {
if (this->inSubmenu) { if (this->inSubmenu) {
(**this->it).getMenu()->down(); (**this->selectedEntry).getMenu()->down();
return; return;
} }
// TODO: Why I need the fucking next two lines? here and in the next function // TODO: Why I need the fucking next two lines? here and in the next function
std::list<MenuAction*>::iterator iter = this->it; std::list<MenuAction*>::iterator iter = this->selectedEntry;
iter++; iter++;
if (iter != this->entrys.end()) if (iter != this->entrys.end())
this->it++; this->selectedEntry++;
else else
this->it = this->entrys.begin(); this->selectedEntry = this->entrys.begin();
this->printMenu(); this->printMenu();
} }
void Menu::up() { void Menu::up() {
if (this->inSubmenu) { if (this->inSubmenu) {
(**this->it).getMenu()->up(); (**this->selectedEntry).getMenu()->up();
return; return;
} }
std::list<MenuAction*>::iterator iter = this->entrys.end(); std::list<MenuAction*>::iterator iter = this->entrys.end();
iter--; iter--;
if (this->it != this->entrys.begin()) { if (this->selectedEntry != this->entrys.begin()) {
this->it--; this->selectedEntry--;
} }
else { else {
this->it = iter; this->selectedEntry = iter;
} }
this->printMenu(); this->printMenu();
} }
void Menu::right() { void Menu::right() {
if (this->inSubmenu) { if (this->inSubmenu) {
(**this->it).getMenu()->right(); (**this->selectedEntry).getMenu()->right();
return; return;
} }
if ((**this->it).getIsMenu()) { if ((**this->selectedEntry).getIsMenu()) {
this->inSubmenu = true; this->inSubmenu = true;
(**this->it).getMenu()->setParentMenu(this); (**this->selectedEntry).getMenu()->setParentMenu(this);
} }
(**this->it).runAction(); (**this->selectedEntry).runAction();
} }
void Menu::left() { void Menu::left() {
if (this->inSubmenu) { if (this->inSubmenu) {
(**this->it).getMenu()->left(); (**this->selectedEntry).getMenu()->left();
return; return;
} }
@@ -103,7 +110,7 @@ void Menu::left() {
void Menu::yes() { void Menu::yes() {
if (this->inSubmenu) { if (this->inSubmenu) {
(**this->it).getMenu()->yes(); (**this->selectedEntry).getMenu()->yes();
return; return;
} }
@@ -112,7 +119,7 @@ void Menu::yes() {
void Menu::no() { void Menu::no() {
if (this->inSubmenu) { if (this->inSubmenu) {
(**this->it).getMenu()->no(); (**this->selectedEntry).getMenu()->no();
return; return;
} }
+2 -1
View File
@@ -23,6 +23,7 @@ class Menu : public MenuControl {
void addEntry(MenuAction* entry); void addEntry(MenuAction* entry);
void printMenu(); void printMenu();
void update();
void down(); void down();
void up(); void up();
@@ -35,7 +36,7 @@ class Menu : public MenuControl {
bool inSubmenu = false; bool inSubmenu = false;
std::list<MenuAction*> entrys; std::list<MenuAction*> entrys;
std::list<MenuAction*>::iterator it; std::list<MenuAction*>::iterator selectedEntry;
}; };
+2
View File
@@ -26,6 +26,8 @@ class MenuControl {
virtual void yes(); virtual void yes();
virtual void no(); virtual void no();
virtual void update();
virtual void printMenu(); virtual void printMenu();
void setParentMenu(MenuControl* menu) { this->parentMenu = menu; } void setParentMenu(MenuControl* menu) { this->parentMenu = menu; }
void setLcd(LiquidCrystal_I2C* lcd) { this->lcd = lcd; } void setLcd(LiquidCrystal_I2C* lcd) { this->lcd = lcd; }
+77 -2
View File
@@ -13,6 +13,23 @@
MenuGPS::MenuGPS(TinyGPSPlus* gps) { MenuGPS::MenuGPS(TinyGPSPlus* gps) {
this->gps = 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() { void MenuGPS::right() {
@@ -33,6 +50,20 @@ void MenuGPS::yes() {
} }
void MenuGPS::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) { if (this->lcd) {
lcd->clear(); lcd->clear();
lcd->setCursor(0, 0); lcd->setCursor(0, 0);
@@ -41,8 +72,6 @@ void MenuGPS::printMenu() {
lcd->setCursor(0, 1); lcd->setCursor(0, 1);
lcd->printf("HDOP: %f", gps->hdop.hdop()); lcd->printf("HDOP: %f", gps->hdop.hdop());
} else { } else {
lcd->clear();
lcd->setCursor(0, 0);
lcd->printf("Data isn't valid"); lcd->printf("Data isn't valid");
lcd->setCursor(0, 1); lcd->setCursor(0, 1);
lcd->printf("or no GPS signal"); lcd->printf("or no GPS signal");
@@ -54,4 +83,50 @@ void MenuGPS::printMenu() {
else else
std::cout << "Date isn't valid or no GPS signal" << std::endl; 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;
}
} }
+10 -2
View File
@@ -20,17 +20,25 @@ class MenuGPS : public MenuControl {
public: public:
MenuGPS(TinyGPSPlus* gps); MenuGPS(TinyGPSPlus* gps);
void down(){} void down();
void up(){} void up();
void right(); void right();
void left(); void left();
void no(); void no();
void yes(); void yes();
void printMenu(); void printMenu();
void update();
private: private:
const uint8_t countPages = 7;
uint8_t currentPage = 0;
void printPage(const uint8_t page) const;
TinyGPSPlus* gps; TinyGPSPlus* gps;
const uint16_t delay = 5000;
uint32_t last_millis = 0;
}; };
#endif // MENU_GPS_H #endif // MENU_GPS_H
+1
View File
@@ -33,6 +33,7 @@ class MenuPidSettings : public MenuControl {
void yes(); void yes();
void printMenu(); void printMenu();
void update(){};
private: private:
PID* pid; PID* pid;