From 9d5cc92a80f8bf1b9526db55de1574753e5093d3 Mon Sep 17 00:00:00 2001 From: Alexander Klein Date: Wed, 28 Dec 2022 10:20:48 +0100 Subject: [PATCH] moved print function to base class --- lib/Menu/menuControl.cpp | 24 ++++++++++++++++++++++++ lib/Menu/menuControl.h | 4 +++- lib/Menu/menuInformationSites.cpp | 12 ------------ lib/Menu/menuInformationSites.h | 1 - 4 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 lib/Menu/menuControl.cpp diff --git a/lib/Menu/menuControl.cpp b/lib/Menu/menuControl.cpp new file mode 100644 index 0000000..8a06de5 --- /dev/null +++ b/lib/Menu/menuControl.cpp @@ -0,0 +1,24 @@ +/** + * @file menuControl.cpp + * @author Alexander Klein (alex@kleiax.de) + * @brief + * @version 0.1 + * @date 2022-12-28 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "menuControl.h" + +void MenuControl::print(String lineOne, String lineTwo) const { + if (this->lcd) { + lcd->clear(); + lcd->setCursor(0, 0); + lcd->printf(lineOne.c_str()); + lcd->setCursor(0, 1); + lcd->printf(lineTwo.c_str()); + } + + std::cout << lineOne.c_str() << " " << lineTwo.c_str() << std::endl; +} diff --git a/lib/Menu/menuControl.h b/lib/Menu/menuControl.h index 162cbd0..95c8c45 100644 --- a/lib/Menu/menuControl.h +++ b/lib/Menu/menuControl.h @@ -18,7 +18,7 @@ /** * @brief Baseclass to build Menus * - * This class must be inherited by other classes which want to be + * This class have to be inherited by other classes which want to be * act as a menu, because the menu structure uses polymorphism. * */ @@ -69,6 +69,8 @@ class MenuControl { void setLcd(LiquidCrystal_I2C* lcd) { this->lcd = lcd; } protected: + void print(String lineOne, String lineTwo) const; + MenuControl* parentMenu = nullptr; LiquidCrystal_I2C* lcd = nullptr; }; diff --git a/lib/Menu/menuInformationSites.cpp b/lib/Menu/menuInformationSites.cpp index 7405d72..5a5804f 100644 --- a/lib/Menu/menuInformationSites.cpp +++ b/lib/Menu/menuInformationSites.cpp @@ -77,15 +77,3 @@ void MenuInformationSites::printDefault() const { this->print(lineOne, lineTwo); } - -void MenuInformationSites::print(String lineOne, String lineTwo) const { - if (this->lcd) { - lcd->clear(); - lcd->setCursor(0, 0); - lcd->printf(lineOne.c_str()); - lcd->setCursor(0, 1); - lcd->printf(lineTwo.c_str()); - } - - std::cout << lineOne.c_str() << " " << lineTwo.c_str() << std::endl; -} diff --git a/lib/Menu/menuInformationSites.h b/lib/Menu/menuInformationSites.h index 84224cc..e9f3e14 100644 --- a/lib/Menu/menuInformationSites.h +++ b/lib/Menu/menuInformationSites.h @@ -74,7 +74,6 @@ class MenuInformationSites : public MenuControl { virtual void runCommand() const {} void printDefault() const; - void print(String lineOne, String lineTwo) const; private: uint8_t countPages;