Files
Bachelorarbeit-Rover/lib/Menu/menuInformationSites.cpp
T
2023-01-04 00:18:07 +01:00

99 lines
2.1 KiB
C++

/**
* @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();
this->leaved = true;
}
}
void MenuInformationSites::no() {
this->left();
}
void MenuInformationSites::yes() {
this->runCommand();
this->printMenu();
}
void MenuInformationSites::printMenu() {
if (this->leaved) {
this->leaved = false;
this->lastPageNumber++;
this->init();
}
this->printPage();
this->lastPageNumber = this->currentPage;
}
void MenuInformationSites::update() {
if (millis() - this->lastMillis < this->delay) {
return;
}
this->printMenu();
this->lastMillis = millis();
}
bool MenuInformationSites::setCountPages(uint8_t pages) {
this->countPages = pages;
this->currentPage = 0;
if (this->countPages == 0) {
this->countPages = 1;
return false;
}
return true;
}
uint8_t MenuInformationSites::getCountPages() const {
return this->countPages;
}
uint8_t MenuInformationSites::getCurrentPage() const {
return this->currentPage;
}
void MenuInformationSites::printDefault() const {
String lineOne = String("Page: ") + (this->currentPage + 1);
String lineTwo = String("of ") + this->countPages;
this->print(lineOne, lineTwo);
}