added update for menu
This commit is contained in:
+27
-20
@@ -11,14 +11,14 @@
|
||||
#include "menu.h"
|
||||
|
||||
Menu::Menu() {
|
||||
this->it = this->entrys.begin();
|
||||
this->selectedEntry = this->entrys.begin();
|
||||
}
|
||||
|
||||
void Menu::addEntry(MenuAction* entry) {
|
||||
this->entrys.push_back(entry);
|
||||
|
||||
if (this->entrys.size() == 2)
|
||||
this->it = this->entrys.begin();
|
||||
this->selectedEntry = this->entrys.begin();
|
||||
}
|
||||
|
||||
void Menu::printMenu() {
|
||||
@@ -26,9 +26,9 @@ void Menu::printMenu() {
|
||||
lcd->clear();
|
||||
lcd->setCursor(0, 0);
|
||||
lcd->print("-> ");
|
||||
lcd->print((**this->it).getName());
|
||||
lcd->print((**this->selectedEntry).getName());
|
||||
lcd->setCursor(0, 1);
|
||||
std::list<MenuAction*>::iterator iter = this->it;
|
||||
std::list<MenuAction*>::iterator iter = this->selectedEntry;
|
||||
iter++;
|
||||
if (iter != this->entrys.end()) {
|
||||
lcd->print((**iter).getName());
|
||||
@@ -37,7 +37,7 @@ void Menu::printMenu() {
|
||||
} else {
|
||||
std::cout << std::endl;
|
||||
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;
|
||||
else
|
||||
std::cout << (**iter).getName() << std::endl;
|
||||
@@ -46,54 +46,61 @@ void Menu::printMenu() {
|
||||
this->inSubmenu = false;
|
||||
}
|
||||
|
||||
void Menu::update() {
|
||||
if (this->inSubmenu) {
|
||||
(**this->selectedEntry).getMenu()->update();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::down() {
|
||||
if (this->inSubmenu) {
|
||||
(**this->it).getMenu()->down();
|
||||
(**this->selectedEntry).getMenu()->down();
|
||||
return;
|
||||
}
|
||||
|
||||
// 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++;
|
||||
if (iter != this->entrys.end())
|
||||
this->it++;
|
||||
this->selectedEntry++;
|
||||
else
|
||||
this->it = this->entrys.begin();
|
||||
this->selectedEntry = this->entrys.begin();
|
||||
this->printMenu();
|
||||
}
|
||||
|
||||
void Menu::up() {
|
||||
if (this->inSubmenu) {
|
||||
(**this->it).getMenu()->up();
|
||||
(**this->selectedEntry).getMenu()->up();
|
||||
return;
|
||||
}
|
||||
std::list<MenuAction*>::iterator iter = this->entrys.end();
|
||||
iter--;
|
||||
if (this->it != this->entrys.begin()) {
|
||||
this->it--;
|
||||
if (this->selectedEntry != this->entrys.begin()) {
|
||||
this->selectedEntry--;
|
||||
}
|
||||
else {
|
||||
this->it = iter;
|
||||
this->selectedEntry = iter;
|
||||
}
|
||||
this->printMenu();
|
||||
}
|
||||
|
||||
void Menu::right() {
|
||||
if (this->inSubmenu) {
|
||||
(**this->it).getMenu()->right();
|
||||
(**this->selectedEntry).getMenu()->right();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((**this->it).getIsMenu()) {
|
||||
if ((**this->selectedEntry).getIsMenu()) {
|
||||
this->inSubmenu = true;
|
||||
(**this->it).getMenu()->setParentMenu(this);
|
||||
(**this->selectedEntry).getMenu()->setParentMenu(this);
|
||||
}
|
||||
(**this->it).runAction();
|
||||
(**this->selectedEntry).runAction();
|
||||
}
|
||||
|
||||
void Menu::left() {
|
||||
if (this->inSubmenu) {
|
||||
(**this->it).getMenu()->left();
|
||||
(**this->selectedEntry).getMenu()->left();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -103,7 +110,7 @@ void Menu::left() {
|
||||
|
||||
void Menu::yes() {
|
||||
if (this->inSubmenu) {
|
||||
(**this->it).getMenu()->yes();
|
||||
(**this->selectedEntry).getMenu()->yes();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -112,7 +119,7 @@ void Menu::yes() {
|
||||
|
||||
void Menu::no() {
|
||||
if (this->inSubmenu) {
|
||||
(**this->it).getMenu()->no();
|
||||
(**this->selectedEntry).getMenu()->no();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -23,6 +23,7 @@ class Menu : public MenuControl {
|
||||
|
||||
void addEntry(MenuAction* entry);
|
||||
void printMenu();
|
||||
void update();
|
||||
|
||||
void down();
|
||||
void up();
|
||||
@@ -35,7 +36,7 @@ class Menu : public MenuControl {
|
||||
bool inSubmenu = false;
|
||||
|
||||
std::list<MenuAction*> entrys;
|
||||
std::list<MenuAction*>::iterator it;
|
||||
std::list<MenuAction*>::iterator selectedEntry;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -26,9 +26,11 @@ class MenuControl {
|
||||
virtual void yes();
|
||||
virtual void no();
|
||||
|
||||
virtual void update();
|
||||
|
||||
virtual void printMenu();
|
||||
void setParentMenu(MenuControl* menu) {this->parentMenu = menu;}
|
||||
void setLcd(LiquidCrystal_I2C* lcd) {this->lcd = lcd;}
|
||||
void setParentMenu(MenuControl* menu) { this->parentMenu = menu; }
|
||||
void setLcd(LiquidCrystal_I2C* lcd) { this->lcd = lcd; }
|
||||
|
||||
protected:
|
||||
MenuControl* parentMenu = nullptr;
|
||||
|
||||
@@ -13,6 +13,23 @@
|
||||
|
||||
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() {
|
||||
@@ -33,25 +50,83 @@ void MenuGPS::yes() {
|
||||
}
|
||||
|
||||
void MenuGPS::printMenu() {
|
||||
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->clear();
|
||||
lcd->setCursor(0, 0);
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -20,17 +20,25 @@ class MenuGPS : public MenuControl {
|
||||
public:
|
||||
MenuGPS(TinyGPSPlus* gps);
|
||||
|
||||
void down(){}
|
||||
void up(){}
|
||||
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
|
||||
@@ -33,6 +33,7 @@ class MenuPidSettings : public MenuControl {
|
||||
void yes();
|
||||
|
||||
void printMenu();
|
||||
void update(){};
|
||||
|
||||
private:
|
||||
PID* pid;
|
||||
|
||||
Reference in New Issue
Block a user