From 8dc600fc907b7b4a65b8dbfee6b12361f351af2e Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Fri, 24 Nov 2023 14:51:45 +0100 Subject: [PATCH 01/23] Added U8g2lib. Created Component base class for Analog and Digital. Created Display class and displaying "Hello World!". --- .vscode/settings.json | 3 ++- lib/Component/Component.cpp | 27 +++++++++++++++++++++++++++ lib/Component/Component.hpp | 23 +++++++++++++++++++++++ lib/Component/Display.cpp | 16 ++++++++++++++++ lib/Component/Display.hpp | 10 ++++++++++ platformio.ini | 8 +++++--- src/main.cpp | 24 ++++++++++++------------ 7 files changed, 95 insertions(+), 16 deletions(-) create mode 100644 lib/Component/Component.cpp create mode 100644 lib/Component/Component.hpp create mode 100644 lib/Component/Display.cpp create mode 100644 lib/Component/Display.hpp diff --git a/.vscode/settings.json b/.vscode/settings.json index d8cb326..4707309 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "files.associations": { "string": "cpp" - } + }, + "cmake.configureOnOpen": false } \ No newline at end of file diff --git a/lib/Component/Component.cpp b/lib/Component/Component.cpp new file mode 100644 index 0000000..98b84c9 --- /dev/null +++ b/lib/Component/Component.cpp @@ -0,0 +1,27 @@ +#include "Component.hpp" + +Component::Component(ComponentType ct, uint8_t p) +: _type(ct), _pin(p) +{} + +std::any Component::getValue(void){ + switch(_type) + { + case ComponentType::Digital: + return digitalRead(_pin); + case ComponentType::Analog: + return analogRead(_pin); + default: + return 0; + } +} + +void Component::sendValue(std::any data) +{ + switch(_type) { + case ComponentType::Digital: + digitalWrite(_pin, std::any_cast(data)); + case ComponentType::Analog: + analogWrite(_pin, std::any_cast(data)); + } +} \ No newline at end of file diff --git a/lib/Component/Component.hpp b/lib/Component/Component.hpp new file mode 100644 index 0000000..344d781 --- /dev/null +++ b/lib/Component/Component.hpp @@ -0,0 +1,23 @@ +#ifndef _HEADER_COMPONENT +#define _HEADER_COMPONENT +#include +#include + +enum class ComponentType { + Digital, + Analog, + I2C, + Serial +}; + +class Component{ + public: + Component(ComponentType ct, uint8_t p); + std::any getValue(); + void sendValue(std::any data); + private: + ComponentType _type; + const uint8_t _pin; +}; + +#endif //_HEADER_COMPONENT \ No newline at end of file diff --git a/lib/Component/Display.cpp b/lib/Component/Display.cpp new file mode 100644 index 0000000..e2c8d00 --- /dev/null +++ b/lib/Component/Display.cpp @@ -0,0 +1,16 @@ +#include "Display.hpp" + +Display::Display() +{ + _display = new U8G2_SSD1306_128X64_NONAME_F_HW_I2C(U8G2_R0,U8X8_PIN_NONE,SCL,SDA); + _display->begin(); +} + +void Display::loop() +{ + _display->clearBuffer(); // clear the internal memory + _display->setFont(u8g2_font_ncenB08_tr); // choose a suitable font + _display->drawStr(0,10,"Hello World!"); // write something to the internal memory + _display->sendBuffer(); // transfer internal memory to the display + delay(1000); +} \ No newline at end of file diff --git a/lib/Component/Display.hpp b/lib/Component/Display.hpp new file mode 100644 index 0000000..79b6c25 --- /dev/null +++ b/lib/Component/Display.hpp @@ -0,0 +1,10 @@ +#include +#include + +class Display { + public: + Display(); + void loop(); + private: + U8G2_SSD1306_128X64_NONAME_F_HW_I2C* _display; +}; \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 239547c..32bd1eb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,6 +12,8 @@ platform = espressif8266 board = nodemcuv2 framework = arduino -lib_deps = tzapu/WiFiManager@^0.16.0 - bbx10/DNSServer@^1.1.0 - ArduinoJson +lib_deps = + tzapu/WiFiManager@^0.16.0 + bbx10/DNSServer@^1.1.0 + ArduinoJson + olikraus/U8g2@^2.35.7 diff --git a/src/main.cpp b/src/main.cpp index dc97a3c..ab540cc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,27 +4,27 @@ #include "ServerHandler.hpp" #include "DataHandler.hpp" +#include "Component.hpp" +#include "Display.hpp" DataHandler dataHandler; ServerHandler serverHandler(&dataHandler); // Référence à dataHandler +Component humidity(ComponentType::Analog, PIN_A0); +Display screen; - -void setup() { +void setup() +{ Serial.begin(9600); - - dataHandler.updateTemperatureData(20.0); - dataHandler.updateHumidityData(3.141592); - - serverHandler.setup("Redmi Note 10", "bbooksdd"); + serverHandler.setup("Iphone de Nicole", "cesthonteux"); } -void loop() { +void loop() +{ + screen.loop(); + dataHandler.updateTemperatureData(random(1800, 2200) / 100.0); + dataHandler.updateHumidityData(static_cast(std::any_cast(humidity.getValue()))); Serial.println(dataHandler.getJsonData()); - - dataHandler.updateTemperatureData(random(1800, 2200)/100.0); - dataHandler.updateHumidityData(random(4400, 5000)/100.0); delay(1000); - serverHandler.loop(); } From 8cf51ec22d0d11d32519476a7a60a5abc4bc8ecf Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Fri, 24 Nov 2023 14:54:47 +0100 Subject: [PATCH 02/23] Changing directory. --- .gitignore => embedded/.gitignore | 0 {.vscode => embedded/.vscode}/extensions.json | 0 {.vscode => embedded/.vscode}/settings.json | 0 {include => embedded/include}/README | 0 {lib => embedded/lib}/Component/Component.cpp | 0 {lib => embedded/lib}/Component/Component.hpp | 0 {lib => embedded/lib}/Component/Display.cpp | 0 {lib => embedded/lib}/Component/Display.hpp | 0 {lib => embedded/lib}/DataHandler/DataHandler.cpp | 0 {lib => embedded/lib}/DataHandler/DataHandler.hpp | 0 {lib => embedded/lib}/README | 0 {lib => embedded/lib}/ServerHandler/ServerHandler.cpp | 0 {lib => embedded/lib}/ServerHandler/ServerHandler.hpp | 0 platformio.ini => embedded/platformio.ini | 0 {src => embedded/src}/main.cpp | 0 {test => embedded/test}/README | 0 16 files changed, 0 insertions(+), 0 deletions(-) rename .gitignore => embedded/.gitignore (100%) rename {.vscode => embedded/.vscode}/extensions.json (100%) rename {.vscode => embedded/.vscode}/settings.json (100%) rename {include => embedded/include}/README (100%) rename {lib => embedded/lib}/Component/Component.cpp (100%) rename {lib => embedded/lib}/Component/Component.hpp (100%) rename {lib => embedded/lib}/Component/Display.cpp (100%) rename {lib => embedded/lib}/Component/Display.hpp (100%) rename {lib => embedded/lib}/DataHandler/DataHandler.cpp (100%) rename {lib => embedded/lib}/DataHandler/DataHandler.hpp (100%) rename {lib => embedded/lib}/README (100%) rename {lib => embedded/lib}/ServerHandler/ServerHandler.cpp (100%) rename {lib => embedded/lib}/ServerHandler/ServerHandler.hpp (100%) rename platformio.ini => embedded/platformio.ini (100%) rename {src => embedded/src}/main.cpp (100%) rename {test => embedded/test}/README (100%) diff --git a/.gitignore b/embedded/.gitignore similarity index 100% rename from .gitignore rename to embedded/.gitignore diff --git a/.vscode/extensions.json b/embedded/.vscode/extensions.json similarity index 100% rename from .vscode/extensions.json rename to embedded/.vscode/extensions.json diff --git a/.vscode/settings.json b/embedded/.vscode/settings.json similarity index 100% rename from .vscode/settings.json rename to embedded/.vscode/settings.json diff --git a/include/README b/embedded/include/README similarity index 100% rename from include/README rename to embedded/include/README diff --git a/lib/Component/Component.cpp b/embedded/lib/Component/Component.cpp similarity index 100% rename from lib/Component/Component.cpp rename to embedded/lib/Component/Component.cpp diff --git a/lib/Component/Component.hpp b/embedded/lib/Component/Component.hpp similarity index 100% rename from lib/Component/Component.hpp rename to embedded/lib/Component/Component.hpp diff --git a/lib/Component/Display.cpp b/embedded/lib/Component/Display.cpp similarity index 100% rename from lib/Component/Display.cpp rename to embedded/lib/Component/Display.cpp diff --git a/lib/Component/Display.hpp b/embedded/lib/Component/Display.hpp similarity index 100% rename from lib/Component/Display.hpp rename to embedded/lib/Component/Display.hpp diff --git a/lib/DataHandler/DataHandler.cpp b/embedded/lib/DataHandler/DataHandler.cpp similarity index 100% rename from lib/DataHandler/DataHandler.cpp rename to embedded/lib/DataHandler/DataHandler.cpp diff --git a/lib/DataHandler/DataHandler.hpp b/embedded/lib/DataHandler/DataHandler.hpp similarity index 100% rename from lib/DataHandler/DataHandler.hpp rename to embedded/lib/DataHandler/DataHandler.hpp diff --git a/lib/README b/embedded/lib/README similarity index 100% rename from lib/README rename to embedded/lib/README diff --git a/lib/ServerHandler/ServerHandler.cpp b/embedded/lib/ServerHandler/ServerHandler.cpp similarity index 100% rename from lib/ServerHandler/ServerHandler.cpp rename to embedded/lib/ServerHandler/ServerHandler.cpp diff --git a/lib/ServerHandler/ServerHandler.hpp b/embedded/lib/ServerHandler/ServerHandler.hpp similarity index 100% rename from lib/ServerHandler/ServerHandler.hpp rename to embedded/lib/ServerHandler/ServerHandler.hpp diff --git a/platformio.ini b/embedded/platformio.ini similarity index 100% rename from platformio.ini rename to embedded/platformio.ini diff --git a/src/main.cpp b/embedded/src/main.cpp similarity index 100% rename from src/main.cpp rename to embedded/src/main.cpp diff --git a/test/README b/embedded/test/README similarity index 100% rename from test/README rename to embedded/test/README From c9ad92c0315b03b34eff6652c3f5b8e16700b8f8 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Fri, 24 Nov 2023 14:55:28 +0100 Subject: [PATCH 03/23] Added app directory. --- app/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 app/.gitkeep diff --git a/app/.gitkeep b/app/.gitkeep new file mode 100644 index 0000000..e69de29 From 0b63d995109f8aa9ba0baa267c93afc8f15942c2 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Sun, 26 Nov 2023 14:50:41 +0100 Subject: [PATCH 04/23] Added password/ssid dotenv management in plateform io. --- embedded/.gitignore | 1 + embedded/platformio.ini | 2 ++ embedded/readme.MD | 4 ++++ embedded/scripts/dotenv-var.py | 14 ++++++++++++++ embedded/src/main.cpp | 12 ++++++++++-- 5 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 embedded/readme.MD create mode 100644 embedded/scripts/dotenv-var.py diff --git a/embedded/.gitignore b/embedded/.gitignore index 89cc49c..6045fd3 100644 --- a/embedded/.gitignore +++ b/embedded/.gitignore @@ -3,3 +3,4 @@ .vscode/c_cpp_properties.json .vscode/launch.json .vscode/ipch +.env \ No newline at end of file diff --git a/embedded/platformio.ini b/embedded/platformio.ini index 32bd1eb..6f09bfb 100644 --- a/embedded/platformio.ini +++ b/embedded/platformio.ini @@ -17,3 +17,5 @@ lib_deps = bbx10/DNSServer@^1.1.0 ArduinoJson olikraus/U8g2@^2.35.7 +extra_scripts = + pre:scripts/dotenv-var.py \ No newline at end of file diff --git a/embedded/readme.MD b/embedded/readme.MD new file mode 100644 index 0000000..4cf28b6 --- /dev/null +++ b/embedded/readme.MD @@ -0,0 +1,4 @@ +# .env file + +SSID_CLOVER='"SSID"' +PSWD_CLOVER='"PASSWORD"' \ No newline at end of file diff --git a/embedded/scripts/dotenv-var.py b/embedded/scripts/dotenv-var.py new file mode 100644 index 0000000..f0f8134 --- /dev/null +++ b/embedded/scripts/dotenv-var.py @@ -0,0 +1,14 @@ +from os.path import isfile +Import("env") +assert isfile(".env") +try: + f = open(".env", "r") + lines = f.readlines() + envs = [] + for line in lines: + envs.append("-D{}".format(line.strip())) + env.Append(BUILD_FLAGS=envs) +except IOError: + print("File .env not accessible",) +finally: + f.close() \ No newline at end of file diff --git a/embedded/src/main.cpp b/embedded/src/main.cpp index ab540cc..a1167ea 100644 --- a/embedded/src/main.cpp +++ b/embedded/src/main.cpp @@ -7,6 +7,13 @@ #include "Component.hpp" #include "Display.hpp" +#ifdef SSID_CLOVER + const char* ssid = SSID_CLOVER; +#endif +#ifdef PSWD_CLOVER + const char* pswd = PSWD_CLOVER; +#endif + DataHandler dataHandler; ServerHandler serverHandler(&dataHandler); // Référence à dataHandler Component humidity(ComponentType::Analog, PIN_A0); @@ -15,16 +22,17 @@ Display screen; void setup() { Serial.begin(9600); - serverHandler.setup("Iphone de Nicole", "cesthonteux"); + serverHandler.setup(ssid, pswd); } void loop() { screen.loop(); dataHandler.updateTemperatureData(random(1800, 2200) / 100.0); + // 0 -> air(0), 0-300 -> dry(20), 300-700 -> humid (580), 700-950 -> water(940) dataHandler.updateHumidityData(static_cast(std::any_cast(humidity.getValue()))); Serial.println(dataHandler.getJsonData()); delay(1000); serverHandler.loop(); -} +} \ No newline at end of file From c49073ece131fbad8f5d9a0b9452947554e98c6e Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Sun, 26 Nov 2023 16:11:48 +0100 Subject: [PATCH 05/23] DataHandler and ServerHandler are now single instances following the Singleton pattern. --- embedded/lib/DataHandler/DataHandler.cpp | 2 ++ embedded/lib/DataHandler/DataHandler.hpp | 15 ++++++++++++--- embedded/lib/ServerHandler/ServerHandler.cpp | 7 +++++-- embedded/lib/ServerHandler/ServerHandler.hpp | 17 ++++++++++++++--- embedded/src/main.cpp | 7 ++++--- 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/embedded/lib/DataHandler/DataHandler.cpp b/embedded/lib/DataHandler/DataHandler.cpp index 40c891b..8c6a5b2 100644 --- a/embedded/lib/DataHandler/DataHandler.cpp +++ b/embedded/lib/DataHandler/DataHandler.cpp @@ -2,6 +2,8 @@ DataHandler::DataHandler() {} +DataHandler::~DataHandler() {} + void DataHandler::updateTemperatureData(float temp) { temperature = temp; } diff --git a/embedded/lib/DataHandler/DataHandler.hpp b/embedded/lib/DataHandler/DataHandler.hpp index 1bb29c6..5335e3a 100644 --- a/embedded/lib/DataHandler/DataHandler.hpp +++ b/embedded/lib/DataHandler/DataHandler.hpp @@ -5,16 +5,25 @@ class DataHandler { public: - DataHandler(); + // Singleton + static DataHandler& GetInstance() + { + static DataHandler instance; + return instance; + } + // Public functions String getJsonData(); - void updateTemperatureData(float temperature); void updateHumidityData(float humidity); private: + // Singleton + DataHandler(); + ~DataHandler(); + DataHandler(const DataHandler&) = delete; + DataHandler& operator=(const DataHandler&) = delete; float temperature; float humidity; - String buildJson(); }; diff --git a/embedded/lib/ServerHandler/ServerHandler.cpp b/embedded/lib/ServerHandler/ServerHandler.cpp index b65eb5d..240ce39 100644 --- a/embedded/lib/ServerHandler/ServerHandler.cpp +++ b/embedded/lib/ServerHandler/ServerHandler.cpp @@ -1,8 +1,10 @@ #include "ServerHandler.hpp" -ServerHandler::ServerHandler(DataHandler * dataHandler) : server(80), dataHandler(dataHandler) { +ServerHandler::ServerHandler() : server(80) { } +ServerHandler::~ServerHandler() {} + void ServerHandler::setup(const char* ssid, const char* password) { // On utilise les scope resolution operator pour définir les méthodes la classe ServerHandle qui elle est dans hpp Serial.begin(9600); WiFi.begin(ssid, password); @@ -25,6 +27,7 @@ void ServerHandler::loop() { } void ServerHandler::handleRoot() { - String jsonFormattedData = dataHandler->getJsonData(); + auto& dataHandler = DataHandler::GetInstance(); + String jsonFormattedData = dataHandler.getJsonData(); server.send(200, "application/json", jsonFormattedData); } diff --git a/embedded/lib/ServerHandler/ServerHandler.hpp b/embedded/lib/ServerHandler/ServerHandler.hpp index ce6c9b0..3ea8757 100644 --- a/embedded/lib/ServerHandler/ServerHandler.hpp +++ b/embedded/lib/ServerHandler/ServerHandler.hpp @@ -8,14 +8,25 @@ class ServerHandler { public: - ServerHandler(DataHandler * dataHandler); + // Singleton + static ServerHandler& GetInstance() + { + static ServerHandler instance; + return instance; + } + // Public functions void setup(const char* ssid, const char* password); void loop(); private: - ESP8266WebServer server; + // Singleton + ServerHandler(); + ~ServerHandler(); + ServerHandler(const ServerHandler&) = delete; + ServerHandler& operator=(const ServerHandler&) = delete; + // Private variables/functions void handleRoot(); - DataHandler * dataHandler; // Pointeur vers dataHandler + ESP8266WebServer server; }; #endif diff --git a/embedded/src/main.cpp b/embedded/src/main.cpp index a1167ea..c70a98a 100644 --- a/embedded/src/main.cpp +++ b/embedded/src/main.cpp @@ -3,7 +3,6 @@ #include #include "ServerHandler.hpp" -#include "DataHandler.hpp" #include "Component.hpp" #include "Display.hpp" @@ -14,19 +13,21 @@ const char* pswd = PSWD_CLOVER; #endif -DataHandler dataHandler; -ServerHandler serverHandler(&dataHandler); // Référence à dataHandler Component humidity(ComponentType::Analog, PIN_A0); Display screen; void setup() { + auto& serverHandler = ServerHandler::GetInstance(); Serial.begin(9600); serverHandler.setup(ssid, pswd); } void loop() { + auto& serverHandler = ServerHandler::GetInstance(); + auto& dataHandler = DataHandler::GetInstance(); + screen.loop(); dataHandler.updateTemperatureData(random(1800, 2200) / 100.0); // 0 -> air(0), 0-300 -> dry(20), 300-700 -> humid (580), 700-950 -> water(940) From b5c01dc017348c285e2727cb76a10e24f8015972 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Sun, 26 Nov 2023 23:46:13 +0100 Subject: [PATCH 06/23] Updated Display to Screen. Added ScreenComponents to simplify the use of the U8g2lib. Now showing IP on the screen. --- embedded/lib/Component/Display.cpp | 16 ---- embedded/lib/Component/Display.hpp | 10 --- embedded/lib/Component/Screen.cpp | 86 ++++++++++++++++++++ embedded/lib/Component/Screen.hpp | 53 ++++++++++++ embedded/lib/Component/ScreenComponents.cpp | 82 +++++++++++++++++++ embedded/lib/Component/ScreenComponents.hpp | 59 ++++++++++++++ embedded/lib/ServerHandler/ServerHandler.cpp | 10 ++- embedded/src/main.cpp | 8 +- 8 files changed, 289 insertions(+), 35 deletions(-) delete mode 100644 embedded/lib/Component/Display.cpp delete mode 100644 embedded/lib/Component/Display.hpp create mode 100644 embedded/lib/Component/Screen.cpp create mode 100644 embedded/lib/Component/Screen.hpp create mode 100644 embedded/lib/Component/ScreenComponents.cpp create mode 100644 embedded/lib/Component/ScreenComponents.hpp diff --git a/embedded/lib/Component/Display.cpp b/embedded/lib/Component/Display.cpp deleted file mode 100644 index e2c8d00..0000000 --- a/embedded/lib/Component/Display.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "Display.hpp" - -Display::Display() -{ - _display = new U8G2_SSD1306_128X64_NONAME_F_HW_I2C(U8G2_R0,U8X8_PIN_NONE,SCL,SDA); - _display->begin(); -} - -void Display::loop() -{ - _display->clearBuffer(); // clear the internal memory - _display->setFont(u8g2_font_ncenB08_tr); // choose a suitable font - _display->drawStr(0,10,"Hello World!"); // write something to the internal memory - _display->sendBuffer(); // transfer internal memory to the display - delay(1000); -} \ No newline at end of file diff --git a/embedded/lib/Component/Display.hpp b/embedded/lib/Component/Display.hpp deleted file mode 100644 index 79b6c25..0000000 --- a/embedded/lib/Component/Display.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -class Display { - public: - Display(); - void loop(); - private: - U8G2_SSD1306_128X64_NONAME_F_HW_I2C* _display; -}; \ No newline at end of file diff --git a/embedded/lib/Component/Screen.cpp b/embedded/lib/Component/Screen.cpp new file mode 100644 index 0000000..24a4d6b --- /dev/null +++ b/embedded/lib/Component/Screen.cpp @@ -0,0 +1,86 @@ +#include "Screen.hpp" +#include +#include + +using namespace Display; + +Screen::Screen() +{ + _screen = new U8G2_SSD1306_128X64_NONAME_F_HW_I2C(U8G2_R0, U8X8_PIN_NONE, SCL, SDA); + _screen->begin(); + _width = _screen->getDisplayWidth(); + _height = _screen->getDisplayHeight(); +} + +Screen::~Screen() +{ +} + +void Screen::Setup(uint8_t *font) +{ + _font = font; + _screen->setFont(_font); + + // Static Components + connectingWindow.Add(TextBox("connect",StyleWidth::CENTERED, U8G2_BTN_BW0)); + connectedWindow.Add({TextBox("Connected to Wi-Fi !", StyleWidth::LEFT, U8G2_BTN_BW0), + TextBox("IP address: ", StyleWidth::LEFT, U8G2_BTN_BW0), + TextBox("addr", StyleWidth::CENTERED, U8G2_BTN_BW0)}); +} + +uint16_t Screen::setupHeader(const uint16_t w_padding, const uint16_t h_padding) +{ + _screen->setFont(u8g2_font_helvB08_tr); + // calculating y position + const uint16_t y = FONT_SIZE + ((w_padding + 1) * 2); + _screen->drawButtonUTF8(w_padding, y, U8G2_BTN_INV, _screen->getDisplayWidth(), h_padding, w_padding, "Clover Setup"); + return y; +} + +void Screen::connecting(uint8_t state) +{ + const size_t connectSize(16); + char connectText[connectSize]; + + // Connecting dot dot dot (depending on state) + strncpy(connectText, "Connecting", connectSize); + for (uint8_t i = 0; i < state; i++) + strncat(connectText, ".", connectSize); + + // Displaying connecting text and setup bar. + _screen->clearBuffer(); + const auto setupPadding = setupHeader(); + + // Reactive Component + connectingWindow.Update(0,connectText); + // Displaying + connectingWindow.Display(StyleHeight::CENTERED, setupPadding); + _screen->sendBuffer(); +} + +void Screen::connected(const char *ipaddress) +{ + // Displaying connecting text and setup bar. + _screen->clearBuffer(); + const auto setupPadding = setupHeader(); + + // Reactive Component + connectedWindow.Update(2,ipaddress); + // Displaying + connectedWindow.Display(StyleHeight::CENTERED, setupPadding+5); + _screen->sendBuffer(); +} + +void Screen::loop() +{ + _screen->clearBuffer(); // clear the internal memory + _screen->setFont(_font); + _screen->drawStr(0, 10, "Hello World!"); // write something to the internal memory + _screen->sendBuffer(); // transfer internal memory to the display + delay(1000); +} + +uint16_t Screen::getHeight() { return _height; } +uint16_t Screen::getWidth() { return _width; } +U8G2_SSD1306_128X64_NONAME_F_HW_I2C &Screen::getScreen() { return *_screen; } +uint16_t Screen::getTextWidth(const char *str) { return _screen->getStrWidth(str); } \ No newline at end of file diff --git a/embedded/lib/Component/Screen.hpp b/embedded/lib/Component/Screen.hpp new file mode 100644 index 0000000..30a13b0 --- /dev/null +++ b/embedded/lib/Component/Screen.hpp @@ -0,0 +1,53 @@ +#ifndef _HEADER_SCREEN +#define _HEADER_SCREEN +#include +#include + +#include "ScreenComponents.hpp" + +namespace Display +{ + constexpr uint8_t FONT_SIZE=8; + + class Screen + { + public: + // Singleton + static Screen &GetInstance() + { + static Screen instance; + return instance; + } + // Public functions + void Setup(uint8_t *font); + void connecting(uint8_t state = 0); + void connected(const char *ipaddress); + void loop(); + // Getters + uint16_t getHeight(); + uint16_t getWidth(); + U8G2_SSD1306_128X64_NONAME_F_HW_I2C& getScreen(); + uint16_t getTextWidth(const char * str); + private: + // Singleton + Screen(); + ~Screen(); + Screen(const Screen &) = delete; + Screen &operator=(const Screen &) = delete; + + // Fonctions + uint16_t setupHeader(const uint16_t w_padding = 2, const uint16_t h_padding = 5); + + // Variables + U8G2_SSD1306_128X64_NONAME_F_HW_I2C *_screen; + uint8_t *_font; + uint16_t _width; + uint16_t _height; + + // Static Components + Components connectingWindow; + Components connectedWindow; + }; +} + +#endif //_HEADER_SCREEN \ No newline at end of file diff --git a/embedded/lib/Component/ScreenComponents.cpp b/embedded/lib/Component/ScreenComponents.cpp new file mode 100644 index 0000000..4bead11 --- /dev/null +++ b/embedded/lib/Component/ScreenComponents.cpp @@ -0,0 +1,82 @@ +#include "ScreenComponents.hpp" +#include "Screen.hpp" +#include + +using namespace Display; + +Components::Components() +{ +} + +void Components::Add(TextBox box) +{ + _boxes.push_back(box); +} + +void Components::Add(std::vector boxes) +{ + for (auto box : boxes) + { + _boxes.push_back(box); + } +} + +void Components::Update(size_t index, String text) +{ + _boxes[index].updateString(text); +} + +void Components::Display(StyleHeight sh, uint16_t offset) +{ + const auto totalTextSize = _boxes.size() * FONT_SIZE; + const auto centeredOffset = (Screen::GetInstance().getHeight() - totalTextSize) - offset; + for (size_t i = 0; i < _boxes.size(); i++) + { + switch (sh) + { + case StyleHeight::TOP: + Screen::GetInstance().getScreen().drawButtonUTF8(_boxes[i].getX(), (i * FONT_SIZE) + offset, _boxes[i].getStyle(), _boxes[i].getTextWidth(), 0, 0, _boxes[i].getString()); + break; + case StyleHeight::CENTERED: + Screen::GetInstance().getScreen().drawButtonUTF8(_boxes[i].getX(), ((centeredOffset / 2) + i * FONT_SIZE) + offset, _boxes[i].getStyle(), _boxes[i].getTextWidth(), 0, 0, _boxes[i].getString()); + break; + case StyleHeight::BOTTOM: + Screen::GetInstance().getScreen().drawButtonUTF8(_boxes[i].getX(), (centeredOffset + i * FONT_SIZE) + offset, _boxes[i].getStyle(), _boxes[i].getTextWidth(), 0, 0, _boxes[i].getString()); + break; + } + } +} + +TextBox::TextBox(String str, StyleWidth sw, u8g2_uint_t style) + : _text(str), _style(style), _styleWidth(sw) +{ + Calculate(); +} + +void TextBox::Calculate() +{ + const auto width = Screen::GetInstance().getWidth(); + _textWidth = Screen::GetInstance().getTextWidth(_text.c_str()); + switch (_styleWidth) + { + case StyleWidth::LEFT: + _x = 0; + break; + case StyleWidth::CENTERED: + _x = (width - _textWidth) / 2; + break; + case StyleWidth::RIGHT: + _x = width - _textWidth; + break; + } +} + +uint16_t TextBox::getX() { return _x; } +const char *TextBox::getString() { return _text.c_str(); } +void TextBox::updateString(String str) +{ + _text = str; + Calculate(); +} +u8g2_uint_t TextBox::getStyle() { return _style; } +uint16_t TextBox::getTextWidth() { return _textWidth; } \ No newline at end of file diff --git a/embedded/lib/Component/ScreenComponents.hpp b/embedded/lib/Component/ScreenComponents.hpp new file mode 100644 index 0000000..bf38f38 --- /dev/null +++ b/embedded/lib/Component/ScreenComponents.hpp @@ -0,0 +1,59 @@ +#ifndef _HEADER_SCREEN_COMPONENTS +#define _HEADER_SCREEN_COMPONENTS +#include +#include +#include + +namespace Display +{ + // Enums + enum class StyleWidth + { + LEFT, + CENTERED, + RIGHT + }; + + enum class StyleHeight + { + TOP, + CENTERED, + BOTTOM + }; + + // TextBox which inherits from Box (Single Component) + class TextBox + { + public: + TextBox(String str, StyleWidth sw, u8g2_uint_t style); + uint16_t getX(); + const char * getString(); + void updateString(String str); + u8g2_uint_t getStyle(); + uint16_t getTextWidth(); + private: + void Calculate(); + String _text; + uint8_t *_font; + u8g2_uint_t _style; + StyleWidth _styleWidth; + uint16_t _x; + uint16_t _textWidth; + }; + + // Components which contains every type + class Components + { + public: + Components(); + void Add(TextBox box); + void Add(std::vector boxes); + void Update(size_t index, String text); + void Display(StyleHeight sh=StyleHeight::TOP, uint16_t offset=0); + private: + // Boxes + std::vector _boxes; + }; +}; + +#endif //_HEADER_SCREEN_COMPONENTS \ No newline at end of file diff --git a/embedded/lib/ServerHandler/ServerHandler.cpp b/embedded/lib/ServerHandler/ServerHandler.cpp index 240ce39..0cf585c 100644 --- a/embedded/lib/ServerHandler/ServerHandler.cpp +++ b/embedded/lib/ServerHandler/ServerHandler.cpp @@ -1,4 +1,5 @@ #include "ServerHandler.hpp" +#include "Screen.hpp" ServerHandler::ServerHandler() : server(80) { } @@ -6,17 +7,18 @@ ServerHandler::ServerHandler() : server(80) { ServerHandler::~ServerHandler() {} void ServerHandler::setup(const char* ssid, const char* password) { // On utilise les scope resolution operator pour définir les méthodes la classe ServerHandle qui elle est dans hpp + uint8_t state(0); Serial.begin(9600); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); - Serial.print("."); + Display::Screen::GetInstance().connecting(state); + state >= 3 ? state = 0: state++; } - Serial.println(""); - Serial.println("Connected to Wi-Fi. IP address: "); - Serial.println(WiFi.localIP()); + auto ip = WiFi.localIP().toString(); + Display::Screen::GetInstance().connected(ip.c_str()); server.begin(); server.on("/", [this]() { this->handleRoot(); }); // fonction lamda pour gérer les requettes get diff --git a/embedded/src/main.cpp b/embedded/src/main.cpp index c70a98a..47f681a 100644 --- a/embedded/src/main.cpp +++ b/embedded/src/main.cpp @@ -4,7 +4,7 @@ #include "ServerHandler.hpp" #include "Component.hpp" -#include "Display.hpp" +#include "Screen.hpp" #ifdef SSID_CLOVER const char* ssid = SSID_CLOVER; @@ -14,13 +14,12 @@ #endif Component humidity(ComponentType::Analog, PIN_A0); -Display screen; void setup() { - auto& serverHandler = ServerHandler::GetInstance(); Serial.begin(9600); - serverHandler.setup(ssid, pswd); + Display::Screen::GetInstance().Setup(const_cast(u8g2_font_helvB08_tr)); + ServerHandler::GetInstance().setup(ssid, pswd); } void loop() @@ -28,7 +27,6 @@ void loop() auto& serverHandler = ServerHandler::GetInstance(); auto& dataHandler = DataHandler::GetInstance(); - screen.loop(); dataHandler.updateTemperatureData(random(1800, 2200) / 100.0); // 0 -> air(0), 0-300 -> dry(20), 300-700 -> humid (580), 700-950 -> water(940) dataHandler.updateHumidityData(static_cast(std::any_cast(humidity.getValue()))); From 9e32194a70ae050f857d7ec25a6df2a65fd6be14 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Mon, 27 Nov 2023 00:01:22 +0100 Subject: [PATCH 07/23] Updated gitignore. Removing warning for connecting() function in Screen. --- embedded/.gitignore | 5 +---- embedded/.vscode/extensions.json | 10 ---------- embedded/.vscode/settings.json | 6 ------ embedded/lib/Component/Screen.cpp | 11 +++++++++-- 4 files changed, 10 insertions(+), 22 deletions(-) delete mode 100644 embedded/.vscode/extensions.json delete mode 100644 embedded/.vscode/settings.json diff --git a/embedded/.gitignore b/embedded/.gitignore index 6045fd3..59fcd8c 100644 --- a/embedded/.gitignore +++ b/embedded/.gitignore @@ -1,6 +1,3 @@ .pio -.vscode/.browse.c_cpp.db* -.vscode/c_cpp_properties.json -.vscode/launch.json -.vscode/ipch +.vscode/ .env \ No newline at end of file diff --git a/embedded/.vscode/extensions.json b/embedded/.vscode/extensions.json deleted file mode 100644 index 080e70d..0000000 --- a/embedded/.vscode/extensions.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide" - ], - "unwantedRecommendations": [ - "ms-vscode.cpptools-extension-pack" - ] -} diff --git a/embedded/.vscode/settings.json b/embedded/.vscode/settings.json deleted file mode 100644 index 4707309..0000000 --- a/embedded/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "files.associations": { - "string": "cpp" - }, - "cmake.configureOnOpen": false -} \ No newline at end of file diff --git a/embedded/lib/Component/Screen.cpp b/embedded/lib/Component/Screen.cpp index 24a4d6b..3461053 100644 --- a/embedded/lib/Component/Screen.cpp +++ b/embedded/lib/Component/Screen.cpp @@ -44,8 +44,15 @@ void Screen::connecting(uint8_t state) // Connecting dot dot dot (depending on state) strncpy(connectText, "Connecting", connectSize); - for (uint8_t i = 0; i < state; i++) - strncat(connectText, ".", connectSize); + size_t currentLength = strlen(connectText); + +for (uint8_t i = 0; i < state; i++) { + // Checking space + if (currentLength+1 < connectSize) { + strncat(connectText, ".", currentLength+1); + currentLength += 1; + } +} // Displaying connecting text and setup bar. _screen->clearBuffer(); From 72ac1f20df031659bbce4c1c76cba11260ed4b3b Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Mon, 27 Nov 2023 21:50:04 +0100 Subject: [PATCH 08/23] Added padding to display. --- embedded/lib/Component/Screen.cpp | 22 +++++++++++---------- embedded/lib/Component/ScreenComponents.cpp | 8 ++++---- embedded/lib/Component/ScreenComponents.hpp | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/embedded/lib/Component/Screen.cpp b/embedded/lib/Component/Screen.cpp index 3461053..006731e 100644 --- a/embedded/lib/Component/Screen.cpp +++ b/embedded/lib/Component/Screen.cpp @@ -21,8 +21,8 @@ void Screen::Setup(uint8_t *font) _font = font; _screen->setFont(_font); - // Static Components - connectingWindow.Add(TextBox("connect",StyleWidth::CENTERED, U8G2_BTN_BW0)); + // Static Components + connectingWindow.Add(TextBox("connect", StyleWidth::CENTERED, U8G2_BTN_BW0)); connectedWindow.Add({TextBox("Connected to Wi-Fi !", StyleWidth::LEFT, U8G2_BTN_BW0), TextBox("IP address: ", StyleWidth::LEFT, U8G2_BTN_BW0), TextBox("addr", StyleWidth::CENTERED, U8G2_BTN_BW0)}); @@ -46,20 +46,22 @@ void Screen::connecting(uint8_t state) strncpy(connectText, "Connecting", connectSize); size_t currentLength = strlen(connectText); -for (uint8_t i = 0; i < state; i++) { + for (uint8_t i = 0; i < state; i++) + { // Checking space - if (currentLength+1 < connectSize) { - strncat(connectText, ".", currentLength+1); - currentLength += 1; + if (currentLength + 1 < connectSize) + { + strncat(connectText, ".", currentLength + 1); + currentLength += 1; } -} + } // Displaying connecting text and setup bar. _screen->clearBuffer(); const auto setupPadding = setupHeader(); // Reactive Component - connectingWindow.Update(0,connectText); + connectingWindow.Update(0, connectText); // Displaying connectingWindow.Display(StyleHeight::CENTERED, setupPadding); _screen->sendBuffer(); @@ -72,9 +74,9 @@ void Screen::connected(const char *ipaddress) const auto setupPadding = setupHeader(); // Reactive Component - connectedWindow.Update(2,ipaddress); + connectedWindow.Update(2, ipaddress); // Displaying - connectedWindow.Display(StyleHeight::CENTERED, setupPadding+5); + connectedWindow.Display(StyleHeight::CENTERED, setupPadding + 5, 2); _screen->sendBuffer(); } diff --git a/embedded/lib/Component/ScreenComponents.cpp b/embedded/lib/Component/ScreenComponents.cpp index 4bead11..917a4a4 100644 --- a/embedded/lib/Component/ScreenComponents.cpp +++ b/embedded/lib/Component/ScreenComponents.cpp @@ -26,7 +26,7 @@ void Components::Update(size_t index, String text) _boxes[index].updateString(text); } -void Components::Display(StyleHeight sh, uint16_t offset) +void Components::Display(StyleHeight sh, uint16_t offset, uint16_t padding) { const auto totalTextSize = _boxes.size() * FONT_SIZE; const auto centeredOffset = (Screen::GetInstance().getHeight() - totalTextSize) - offset; @@ -35,13 +35,13 @@ void Components::Display(StyleHeight sh, uint16_t offset) switch (sh) { case StyleHeight::TOP: - Screen::GetInstance().getScreen().drawButtonUTF8(_boxes[i].getX(), (i * FONT_SIZE) + offset, _boxes[i].getStyle(), _boxes[i].getTextWidth(), 0, 0, _boxes[i].getString()); + Screen::GetInstance().getScreen().drawButtonUTF8(_boxes[i].getX()+padding*i, (i * FONT_SIZE)+offset+padding*i, _boxes[i].getStyle(), _boxes[i].getTextWidth(), padding, padding, _boxes[i].getString()); break; case StyleHeight::CENTERED: - Screen::GetInstance().getScreen().drawButtonUTF8(_boxes[i].getX(), ((centeredOffset / 2) + i * FONT_SIZE) + offset, _boxes[i].getStyle(), _boxes[i].getTextWidth(), 0, 0, _boxes[i].getString()); + Screen::GetInstance().getScreen().drawButtonUTF8(_boxes[i].getX()+padding*i, ((centeredOffset / 2)+i*FONT_SIZE)+offset+padding*i, _boxes[i].getStyle(), _boxes[i].getTextWidth(), padding, padding, _boxes[i].getString()); break; case StyleHeight::BOTTOM: - Screen::GetInstance().getScreen().drawButtonUTF8(_boxes[i].getX(), (centeredOffset + i * FONT_SIZE) + offset, _boxes[i].getStyle(), _boxes[i].getTextWidth(), 0, 0, _boxes[i].getString()); + Screen::GetInstance().getScreen().drawButtonUTF8(_boxes[i].getX()+padding*i, (centeredOffset + i * FONT_SIZE)+offset+padding*i, _boxes[i].getStyle(), _boxes[i].getTextWidth(), padding, padding, _boxes[i].getString()); break; } } diff --git a/embedded/lib/Component/ScreenComponents.hpp b/embedded/lib/Component/ScreenComponents.hpp index bf38f38..a783588 100644 --- a/embedded/lib/Component/ScreenComponents.hpp +++ b/embedded/lib/Component/ScreenComponents.hpp @@ -49,7 +49,7 @@ namespace Display void Add(TextBox box); void Add(std::vector boxes); void Update(size_t index, String text); - void Display(StyleHeight sh=StyleHeight::TOP, uint16_t offset=0); + void Display(StyleHeight sh=StyleHeight::TOP, uint16_t offset=0, uint16_t padding=0); private: // Boxes std::vector _boxes; From cf50debfd0f70f1fd468af9fe26655b2e5c9dd64 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Mon, 27 Nov 2023 23:06:42 +0100 Subject: [PATCH 09/23] Added Loading screen when connected. Showing basic loop when finished. Fixed padding. --- embedded/lib/Component/Screen.cpp | 19 ++++++++++++++++--- embedded/lib/Component/Screen.hpp | 5 +++-- embedded/lib/Component/ScreenComponents.cpp | 10 ++++++---- embedded/lib/Component/ScreenComponents.hpp | 1 + embedded/lib/ServerHandler/ServerHandler.cpp | 15 +++++++++++---- embedded/lib/ServerHandler/ServerHandler.hpp | 5 +++++ embedded/src/main.cpp | 10 ++++++++-- 7 files changed, 50 insertions(+), 15 deletions(-) diff --git a/embedded/lib/Component/Screen.cpp b/embedded/lib/Component/Screen.cpp index 006731e..1cfeeb8 100644 --- a/embedded/lib/Component/Screen.cpp +++ b/embedded/lib/Component/Screen.cpp @@ -1,6 +1,7 @@ #include "Screen.hpp" #include #include +#include using namespace Display; @@ -10,6 +11,7 @@ Screen::Screen() _screen->begin(); _width = _screen->getDisplayWidth(); _height = _screen->getDisplayHeight(); + _loading = ""; } Screen::~Screen() @@ -34,6 +36,7 @@ uint16_t Screen::setupHeader(const uint16_t w_padding, const uint16_t h_padding) // calculating y position const uint16_t y = FONT_SIZE + ((w_padding + 1) * 2); _screen->drawButtonUTF8(w_padding, y, U8G2_BTN_INV, _screen->getDisplayWidth(), h_padding, w_padding, "Clover Setup"); + _screen->setFont(_font); return y; } @@ -67,8 +70,9 @@ void Screen::connecting(uint8_t state) _screen->sendBuffer(); } -void Screen::connected(const char *ipaddress) +void Screen::connected(const char *ipaddress, uint8_t timing) { + // Displaying connecting text and setup bar. _screen->clearBuffer(); const auto setupPadding = setupHeader(); @@ -76,7 +80,16 @@ void Screen::connected(const char *ipaddress) // Reactive Component connectedWindow.Update(2, ipaddress); // Displaying - connectedWindow.Display(StyleHeight::CENTERED, setupPadding + 5, 2); + connectedWindow.Display(StyleHeight::CENTERED, setupPadding, 4); + + // Creating loading timing + if(timing !=0) + { + _screen->setFont(u8g2_font_3x3basic_tr); + _loading.concat(" "); + _screen->drawButtonUTF8(0, _screen->getDisplayHeight()-5, U8G2_BTN_INV, _screen->getStrWidth(_loading.c_str()), 0, 0, _loading.c_str()); + _screen->setFont(_font); + } _screen->sendBuffer(); } @@ -84,7 +97,7 @@ void Screen::loop() { _screen->clearBuffer(); // clear the internal memory _screen->setFont(_font); - _screen->drawStr(0, 10, "Hello World!"); // write something to the internal memory + _screen->drawStr(0, 10, "Hello Plant!"); // write something to the internal memory _screen->sendBuffer(); // transfer internal memory to the display delay(1000); } diff --git a/embedded/lib/Component/Screen.hpp b/embedded/lib/Component/Screen.hpp index 30a13b0..06cb975 100644 --- a/embedded/lib/Component/Screen.hpp +++ b/embedded/lib/Component/Screen.hpp @@ -7,7 +7,7 @@ namespace Display { - constexpr uint8_t FONT_SIZE=8; + constexpr uint8_t FONT_SIZE=6; class Screen { @@ -21,7 +21,7 @@ namespace Display // Public functions void Setup(uint8_t *font); void connecting(uint8_t state = 0); - void connected(const char *ipaddress); + void connected(const char *ipaddress, uint8_t timing); void loop(); // Getters uint16_t getHeight(); @@ -43,6 +43,7 @@ namespace Display uint8_t *_font; uint16_t _width; uint16_t _height; + String _loading; // Static Components Components connectingWindow; diff --git a/embedded/lib/Component/ScreenComponents.cpp b/embedded/lib/Component/ScreenComponents.cpp index 917a4a4..c1cd4d6 100644 --- a/embedded/lib/Component/ScreenComponents.cpp +++ b/embedded/lib/Component/ScreenComponents.cpp @@ -32,16 +32,17 @@ void Components::Display(StyleHeight sh, uint16_t offset, uint16_t padding) const auto centeredOffset = (Screen::GetInstance().getHeight() - totalTextSize) - offset; for (size_t i = 0; i < _boxes.size(); i++) { + const auto x = (_boxes[i].getStyleWidth() == StyleWidth::CENTERED) ? _boxes[i].getX() : _boxes[i].getX()+padding*i; switch (sh) { case StyleHeight::TOP: - Screen::GetInstance().getScreen().drawButtonUTF8(_boxes[i].getX()+padding*i, (i * FONT_SIZE)+offset+padding*i, _boxes[i].getStyle(), _boxes[i].getTextWidth(), padding, padding, _boxes[i].getString()); + Screen::GetInstance().getScreen().drawButtonUTF8(x, (i * FONT_SIZE)+offset+padding*i, _boxes[i].getStyle(), _boxes[i].getTextWidth(), padding, padding, _boxes[i].getString()); break; case StyleHeight::CENTERED: - Screen::GetInstance().getScreen().drawButtonUTF8(_boxes[i].getX()+padding*i, ((centeredOffset / 2)+i*FONT_SIZE)+offset+padding*i, _boxes[i].getStyle(), _boxes[i].getTextWidth(), padding, padding, _boxes[i].getString()); + Screen::GetInstance().getScreen().drawButtonUTF8(x, ((centeredOffset / 2)+i*FONT_SIZE)+offset+padding*i, _boxes[i].getStyle(), _boxes[i].getTextWidth(), padding, padding, _boxes[i].getString()); break; case StyleHeight::BOTTOM: - Screen::GetInstance().getScreen().drawButtonUTF8(_boxes[i].getX()+padding*i, (centeredOffset + i * FONT_SIZE)+offset+padding*i, _boxes[i].getStyle(), _boxes[i].getTextWidth(), padding, padding, _boxes[i].getString()); + Screen::GetInstance().getScreen().drawButtonUTF8(x, (centeredOffset + i * FONT_SIZE)+offset+padding*i, _boxes[i].getStyle(), _boxes[i].getTextWidth(), padding, padding, _boxes[i].getString()); break; } } @@ -79,4 +80,5 @@ void TextBox::updateString(String str) Calculate(); } u8g2_uint_t TextBox::getStyle() { return _style; } -uint16_t TextBox::getTextWidth() { return _textWidth; } \ No newline at end of file +uint16_t TextBox::getTextWidth() { return _textWidth; } +StyleWidth TextBox::getStyleWidth() { return _styleWidth; } \ No newline at end of file diff --git a/embedded/lib/Component/ScreenComponents.hpp b/embedded/lib/Component/ScreenComponents.hpp index a783588..1a606eb 100644 --- a/embedded/lib/Component/ScreenComponents.hpp +++ b/embedded/lib/Component/ScreenComponents.hpp @@ -31,6 +31,7 @@ namespace Display void updateString(String str); u8g2_uint_t getStyle(); uint16_t getTextWidth(); + StyleWidth getStyleWidth(); private: void Calculate(); String _text; diff --git a/embedded/lib/ServerHandler/ServerHandler.cpp b/embedded/lib/ServerHandler/ServerHandler.cpp index 0cf585c..6983c88 100644 --- a/embedded/lib/ServerHandler/ServerHandler.cpp +++ b/embedded/lib/ServerHandler/ServerHandler.cpp @@ -1,7 +1,7 @@ #include "ServerHandler.hpp" #include "Screen.hpp" -ServerHandler::ServerHandler() : server(80) { +ServerHandler::ServerHandler() : server(80), display_time(0) { } ServerHandler::~ServerHandler() {} @@ -17,17 +17,24 @@ void ServerHandler::setup(const char* ssid, const char* password) { // On utilis state >= 3 ? state = 0: state++; } - auto ip = WiFi.localIP().toString(); - Display::Screen::GetInstance().connected(ip.c_str()); - server.begin(); server.on("/", [this]() { this->handleRoot(); }); // fonction lamda pour gérer les requettes get } void ServerHandler::loop() { + if(display_time < MAX_TIME) + { + Display::Screen::GetInstance().connected(WiFi.localIP().toString().c_str(),display_time); + display_time++; + } server.handleClient(); } +bool ServerHandler::showNext() +{ + return (display_time >= MAX_TIME); +} + void ServerHandler::handleRoot() { auto& dataHandler = DataHandler::GetInstance(); String jsonFormattedData = dataHandler.getJsonData(); diff --git a/embedded/lib/ServerHandler/ServerHandler.hpp b/embedded/lib/ServerHandler/ServerHandler.hpp index 3ea8757..bf233ae 100644 --- a/embedded/lib/ServerHandler/ServerHandler.hpp +++ b/embedded/lib/ServerHandler/ServerHandler.hpp @@ -6,6 +6,8 @@ #include "DataHandler.hpp" +constexpr uint8_t MAX_TIME = 28; + class ServerHandler { public: // Singleton @@ -17,6 +19,8 @@ public: // Public functions void setup(const char* ssid, const char* password); void loop(); + // Return if the screen needs to be changed. + bool showNext(); private: // Singleton @@ -27,6 +31,7 @@ private: // Private variables/functions void handleRoot(); ESP8266WebServer server; + uint8_t display_time; }; #endif diff --git a/embedded/src/main.cpp b/embedded/src/main.cpp index 47f681a..8659b95 100644 --- a/embedded/src/main.cpp +++ b/embedded/src/main.cpp @@ -18,7 +18,7 @@ Component humidity(ComponentType::Analog, PIN_A0); void setup() { Serial.begin(9600); - Display::Screen::GetInstance().Setup(const_cast(u8g2_font_helvB08_tr)); + Display::Screen::GetInstance().Setup(const_cast(u8g2_font_profont10_tr)); ServerHandler::GetInstance().setup(ssid, pswd); } @@ -26,12 +26,18 @@ void loop() { auto& serverHandler = ServerHandler::GetInstance(); auto& dataHandler = DataHandler::GetInstance(); + auto& screen = Display::Screen::GetInstance(); + + // If serverHandler finished showing ip. + if (serverHandler.showNext()) + screen.loop(); dataHandler.updateTemperatureData(random(1800, 2200) / 100.0); // 0 -> air(0), 0-300 -> dry(20), 300-700 -> humid (580), 700-950 -> water(940) dataHandler.updateHumidityData(static_cast(std::any_cast(humidity.getValue()))); Serial.println(dataHandler.getJsonData()); - delay(1000); + // When showing IP, delay is faster. + delay(serverHandler.showNext() ? 1000 : 250); serverHandler.loop(); } \ No newline at end of file From 668d22fd40ab277c29e8c6e721c79e2a0fd90371 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Mon, 27 Nov 2023 23:30:29 +0100 Subject: [PATCH 10/23] Changed font --- embedded/lib/Component/Screen.cpp | 10 ++++++---- embedded/lib/Component/Screen.hpp | 3 ++- embedded/src/main.cpp | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/embedded/lib/Component/Screen.cpp b/embedded/lib/Component/Screen.cpp index 1cfeeb8..24d06d6 100644 --- a/embedded/lib/Component/Screen.cpp +++ b/embedded/lib/Component/Screen.cpp @@ -28,6 +28,7 @@ void Screen::Setup(uint8_t *font) connectedWindow.Add({TextBox("Connected to Wi-Fi !", StyleWidth::LEFT, U8G2_BTN_BW0), TextBox("IP address: ", StyleWidth::LEFT, U8G2_BTN_BW0), TextBox("addr", StyleWidth::CENTERED, U8G2_BTN_BW0)}); + loopWindow.Add(TextBox("Hello, Plant!", StyleWidth::CENTERED, U8G2_BTN_BW1)); } uint16_t Screen::setupHeader(const uint16_t w_padding, const uint16_t h_padding) @@ -95,11 +96,12 @@ void Screen::connected(const char *ipaddress, uint8_t timing) void Screen::loop() { - _screen->clearBuffer(); // clear the internal memory + _screen->clearBuffer(); _screen->setFont(_font); - _screen->drawStr(0, 10, "Hello Plant!"); // write something to the internal memory - _screen->sendBuffer(); // transfer internal memory to the display - delay(1000); + + loopWindow.Display(StyleHeight::CENTERED); + + _screen->sendBuffer(); } uint16_t Screen::getHeight() { return _height; } diff --git a/embedded/lib/Component/Screen.hpp b/embedded/lib/Component/Screen.hpp index 06cb975..f060c20 100644 --- a/embedded/lib/Component/Screen.hpp +++ b/embedded/lib/Component/Screen.hpp @@ -7,7 +7,7 @@ namespace Display { - constexpr uint8_t FONT_SIZE=6; + constexpr uint8_t FONT_SIZE=8; class Screen { @@ -48,6 +48,7 @@ namespace Display // Static Components Components connectingWindow; Components connectedWindow; + Components loopWindow; }; } diff --git a/embedded/src/main.cpp b/embedded/src/main.cpp index 8659b95..31d961b 100644 --- a/embedded/src/main.cpp +++ b/embedded/src/main.cpp @@ -18,7 +18,7 @@ Component humidity(ComponentType::Analog, PIN_A0); void setup() { Serial.begin(9600); - Display::Screen::GetInstance().Setup(const_cast(u8g2_font_profont10_tr)); + Display::Screen::GetInstance().Setup(const_cast(u8g2_font_busdisplay8x5_tr)); ServerHandler::GetInstance().setup(ssid, pswd); } From f7d7bd76882ff5d889632e773598831d8794b37a Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Mon, 27 Nov 2023 23:55:32 +0100 Subject: [PATCH 11/23] Added clover logo. --- embedded/lib/Pictures/clover.xbm | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 embedded/lib/Pictures/clover.xbm diff --git a/embedded/lib/Pictures/clover.xbm b/embedded/lib/Pictures/clover.xbm new file mode 100644 index 0000000..4f520d9 --- /dev/null +++ b/embedded/lib/Pictures/clover.xbm @@ -0,0 +1,6 @@ +#define clover_width 16 +#define clover_height 16 +static unsigned char clover_bits[] = { + 0xff, 0xff, 0x7f, 0xfe, 0x7f, 0xfe, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, + 0x1f, 0xf8, 0x1f, 0xf8, 0x1c, 0x38, 0x30, 0x0c, 0x60, 0x06, 0xc1, 0x83, + 0xc1, 0x83, 0x83, 0xc1, 0x87, 0xe1, 0x3f, 0xfc }; From 629bae5fd536f4804233702f7e3903cea671224c Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Tue, 28 Nov 2023 21:30:37 +0100 Subject: [PATCH 12/23] More generic Approach for TextBox, same for Components that will be containg Boxes --- embedded/lib/Component/Screen.cpp | 58 ++++++------------ embedded/lib/Component/Screen.hpp | 4 +- embedded/lib/Component/ScreenComponents.cpp | 67 ++++++++++++--------- embedded/lib/Component/ScreenComponents.hpp | 15 +++-- 4 files changed, 67 insertions(+), 77 deletions(-) diff --git a/embedded/lib/Component/Screen.cpp b/embedded/lib/Component/Screen.cpp index 24d06d6..bb54f30 100644 --- a/embedded/lib/Component/Screen.cpp +++ b/embedded/lib/Component/Screen.cpp @@ -15,30 +15,21 @@ Screen::Screen() } Screen::~Screen() -{ -} +{} void Screen::Setup(uint8_t *font) { _font = font; _screen->setFont(_font); + headerSetup = TextBox("Clover Setup", StyleWidth::LEFT, StyleHeight::TOP, U8G2_BTN_INV); // Static Components - connectingWindow.Add(TextBox("connect", StyleWidth::CENTERED, U8G2_BTN_BW0)); - connectedWindow.Add({TextBox("Connected to Wi-Fi !", StyleWidth::LEFT, U8G2_BTN_BW0), - TextBox("IP address: ", StyleWidth::LEFT, U8G2_BTN_BW0), - TextBox("addr", StyleWidth::CENTERED, U8G2_BTN_BW0)}); - loopWindow.Add(TextBox("Hello, Plant!", StyleWidth::CENTERED, U8G2_BTN_BW1)); -} - -uint16_t Screen::setupHeader(const uint16_t w_padding, const uint16_t h_padding) -{ - _screen->setFont(u8g2_font_helvB08_tr); - // calculating y position - const uint16_t y = FONT_SIZE + ((w_padding + 1) * 2); - _screen->drawButtonUTF8(w_padding, y, U8G2_BTN_INV, _screen->getDisplayWidth(), h_padding, w_padding, "Clover Setup"); - _screen->setFont(_font); - return y; + connectingWindow.Add({headerSetup, TextBox("connect", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0)}); + connectedWindow.Add({headerSetup, + TextBox("Connected to Wi-Fi !", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0), + TextBox("IP address: ", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0), + TextBox("addr", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0)}); + loopWindow.Add(TextBox("Hello, Plant!", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW1)); } void Screen::connecting(uint8_t state) @@ -49,7 +40,6 @@ void Screen::connecting(uint8_t state) // Connecting dot dot dot (depending on state) strncpy(connectText, "Connecting", connectSize); size_t currentLength = strlen(connectText); - for (uint8_t i = 0; i < state; i++) { // Checking space @@ -60,35 +50,28 @@ void Screen::connecting(uint8_t state) } } - // Displaying connecting text and setup bar. _screen->clearBuffer(); - const auto setupPadding = setupHeader(); - - // Reactive Component - connectingWindow.Update(0, connectText); + // Component + connectingWindow.Update(1, connectText); + connectingWindow.Display(); // Displaying - connectingWindow.Display(StyleHeight::CENTERED, setupPadding); _screen->sendBuffer(); } void Screen::connected(const char *ipaddress, uint8_t timing) { - - // Displaying connecting text and setup bar. _screen->clearBuffer(); - const auto setupPadding = setupHeader(); + // Component + connectedWindow.Update(3, ipaddress); - // Reactive Component - connectedWindow.Update(2, ipaddress); // Displaying - connectedWindow.Display(StyleHeight::CENTERED, setupPadding, 4); - - // Creating loading timing - if(timing !=0) + connectedWindow.Display(); + // Creating loading bar + if (timing != 0) { _screen->setFont(u8g2_font_3x3basic_tr); _loading.concat(" "); - _screen->drawButtonUTF8(0, _screen->getDisplayHeight()-5, U8G2_BTN_INV, _screen->getStrWidth(_loading.c_str()), 0, 0, _loading.c_str()); + _screen->drawButtonUTF8(0, _screen->getDisplayHeight() - 5, U8G2_BTN_INV, _screen->getStrWidth(_loading.c_str()), 0, 0, _loading.c_str()); _screen->setFont(_font); } _screen->sendBuffer(); @@ -97,10 +80,9 @@ void Screen::connected(const char *ipaddress, uint8_t timing) void Screen::loop() { _screen->clearBuffer(); - _screen->setFont(_font); - - loopWindow.Display(StyleHeight::CENTERED); - + // Component + loopWindow.Display(); + // Displaying _screen->sendBuffer(); } diff --git a/embedded/lib/Component/Screen.hpp b/embedded/lib/Component/Screen.hpp index f060c20..cb5fcc8 100644 --- a/embedded/lib/Component/Screen.hpp +++ b/embedded/lib/Component/Screen.hpp @@ -34,9 +34,6 @@ namespace Display ~Screen(); Screen(const Screen &) = delete; Screen &operator=(const Screen &) = delete; - - // Fonctions - uint16_t setupHeader(const uint16_t w_padding = 2, const uint16_t h_padding = 5); // Variables U8G2_SSD1306_128X64_NONAME_F_HW_I2C *_screen; @@ -46,6 +43,7 @@ namespace Display String _loading; // Static Components + TextBox headerSetup; Components connectingWindow; Components connectedWindow; Components loopWindow; diff --git a/embedded/lib/Component/ScreenComponents.cpp b/embedded/lib/Component/ScreenComponents.cpp index c1cd4d6..6bbd5a0 100644 --- a/embedded/lib/Component/ScreenComponents.cpp +++ b/embedded/lib/Component/ScreenComponents.cpp @@ -23,37 +23,38 @@ void Components::Add(std::vector boxes) void Components::Update(size_t index, String text) { - _boxes[index].updateString(text); + _boxes[index].Update(text); } -void Components::Display(StyleHeight sh, uint16_t offset, uint16_t padding) +void Components::Display() { - const auto totalTextSize = _boxes.size() * FONT_SIZE; - const auto centeredOffset = (Screen::GetInstance().getHeight() - totalTextSize) - offset; - for (size_t i = 0; i < _boxes.size(); i++) + const auto size_boxes = _boxes.size(); + size_t i(0); + for(auto it = _boxes.begin() ; it!= _boxes.end() ;it++) { - const auto x = (_boxes[i].getStyleWidth() == StyleWidth::CENTERED) ? _boxes[i].getX() : _boxes[i].getX()+padding*i; - switch (sh) - { - case StyleHeight::TOP: - Screen::GetInstance().getScreen().drawButtonUTF8(x, (i * FONT_SIZE)+offset+padding*i, _boxes[i].getStyle(), _boxes[i].getTextWidth(), padding, padding, _boxes[i].getString()); - break; - case StyleHeight::CENTERED: - Screen::GetInstance().getScreen().drawButtonUTF8(x, ((centeredOffset / 2)+i*FONT_SIZE)+offset+padding*i, _boxes[i].getStyle(), _boxes[i].getTextWidth(), padding, padding, _boxes[i].getString()); - break; - case StyleHeight::BOTTOM: - Screen::GetInstance().getScreen().drawButtonUTF8(x, (centeredOffset + i * FONT_SIZE)+offset+padding*i, _boxes[i].getStyle(), _boxes[i].getTextWidth(), padding, padding, _boxes[i].getString()); - break; - } + it->Display(size_boxes,i); + if (it+1 != _boxes.end() && ((it+1)->getStyleHeight() == it->getStyleHeight())) + i++; + else + i=0; } } -TextBox::TextBox(String str, StyleWidth sw, u8g2_uint_t style) - : _text(str), _style(style), _styleWidth(sw) +TextBox::TextBox() +{} + +TextBox::TextBox(String str, StyleWidth sw, StyleHeight sh, u8g2_uint_t style) + : _text(str), _style(style), _styleWidth(sw), _styleHeight(sh) { Calculate(); } +void TextBox::Update(String str) +{ + _text = str; + Calculate(); +} + void TextBox::Calculate() { const auto width = Screen::GetInstance().getWidth(); @@ -72,13 +73,23 @@ void TextBox::Calculate() } } -uint16_t TextBox::getX() { return _x; } -const char *TextBox::getString() { return _text.c_str(); } -void TextBox::updateString(String str) +void TextBox::Display(size_t size, size_t position) { - _text = str; - Calculate(); + const auto centeredOffset = (Screen::GetInstance().getHeight() - (size * FONT_SIZE)); + // Later will be used with padding/margin + const auto x = (_styleWidth == StyleWidth::CENTERED) ? _x : _x; + switch (_styleHeight) + { + case StyleHeight::TOP: + Screen::GetInstance().getScreen().drawButtonUTF8(x, (position+1)*FONT_SIZE, _style, _textWidth, 0, 0, _text.c_str()); + break; + case StyleHeight::CENTERED: + Screen::GetInstance().getScreen().drawButtonUTF8(x, static_cast((centeredOffset/2)) + (position+1)*FONT_SIZE, _style, _textWidth, 0, 0, _text.c_str()); + break; + case StyleHeight::BOTTOM: + Screen::GetInstance().getScreen().drawButtonUTF8(x, centeredOffset + (position+1)*FONT_SIZE, _style, _textWidth, 0, 0, _text.c_str()); + break; + } } -u8g2_uint_t TextBox::getStyle() { return _style; } -uint16_t TextBox::getTextWidth() { return _textWidth; } -StyleWidth TextBox::getStyleWidth() { return _styleWidth; } \ No newline at end of file + +StyleHeight TextBox::getStyleHeight() { return _styleHeight; } \ No newline at end of file diff --git a/embedded/lib/Component/ScreenComponents.hpp b/embedded/lib/Component/ScreenComponents.hpp index 1a606eb..51b707d 100644 --- a/embedded/lib/Component/ScreenComponents.hpp +++ b/embedded/lib/Component/ScreenComponents.hpp @@ -25,19 +25,18 @@ namespace Display class TextBox { public: - TextBox(String str, StyleWidth sw, u8g2_uint_t style); - uint16_t getX(); - const char * getString(); - void updateString(String str); - u8g2_uint_t getStyle(); - uint16_t getTextWidth(); - StyleWidth getStyleWidth(); + TextBox(); + TextBox(String str, StyleWidth sw, StyleHeight sh, u8g2_uint_t style); + void Display(size_t size, size_t position); + void Update(String str); + StyleHeight getStyleHeight(); private: void Calculate(); String _text; uint8_t *_font; u8g2_uint_t _style; StyleWidth _styleWidth; + StyleHeight _styleHeight; uint16_t _x; uint16_t _textWidth; }; @@ -50,7 +49,7 @@ namespace Display void Add(TextBox box); void Add(std::vector boxes); void Update(size_t index, String text); - void Display(StyleHeight sh=StyleHeight::TOP, uint16_t offset=0, uint16_t padding=0); + void Display(); private: // Boxes std::vector _boxes; From f2153f53afaa5157a87bc6d8e8ea4e9333a2bcc7 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Tue, 28 Nov 2023 22:23:24 +0100 Subject: [PATCH 13/23] ScreenComponents: Added padding for each textbox. modified Display() logic in component. In screen, added padding for Connecting(). --- embedded/lib/Component/Screen.cpp | 8 ++-- embedded/lib/Component/ScreenComponents.cpp | 52 ++++++++++++++------- embedded/lib/Component/ScreenComponents.hpp | 21 ++++++++- 3 files changed, 59 insertions(+), 22 deletions(-) diff --git a/embedded/lib/Component/Screen.cpp b/embedded/lib/Component/Screen.cpp index bb54f30..7084fec 100644 --- a/embedded/lib/Component/Screen.cpp +++ b/embedded/lib/Component/Screen.cpp @@ -22,13 +22,13 @@ void Screen::Setup(uint8_t *font) _font = font; _screen->setFont(_font); - headerSetup = TextBox("Clover Setup", StyleWidth::LEFT, StyleHeight::TOP, U8G2_BTN_INV); + headerSetup = TextBox("Clover Setup", StyleWidth::LEFT, StyleHeight::TOP, U8G2_BTN_INV,2,5, true); // Static Components connectingWindow.Add({headerSetup, TextBox("connect", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0)}); connectedWindow.Add({headerSetup, - TextBox("Connected to Wi-Fi !", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0), - TextBox("IP address: ", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0), - TextBox("addr", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0)}); + TextBox("Connected to Wi-Fi !", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0,0,2), + TextBox("IP address: ", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0,0,2), + TextBox("addr", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0,0,2)}); loopWindow.Add(TextBox("Hello, Plant!", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW1)); } diff --git a/embedded/lib/Component/ScreenComponents.cpp b/embedded/lib/Component/ScreenComponents.cpp index 6bbd5a0..abb5c07 100644 --- a/embedded/lib/Component/ScreenComponents.cpp +++ b/embedded/lib/Component/ScreenComponents.cpp @@ -10,6 +10,7 @@ Components::Components() void Components::Add(TextBox box) { + // When Added, boxes should be reordered by style. _boxes.push_back(box); } @@ -28,23 +29,41 @@ void Components::Update(size_t index, String text) void Components::Display() { - const auto size_boxes = _boxes.size(); size_t i(0); - for(auto it = _boxes.begin() ; it!= _boxes.end() ;it++) + u8g2_uint_t verticalPadding(0); + for (auto it = _boxes.begin(); it != _boxes.end(); it++) { - it->Display(size_boxes,i); - if (it+1 != _boxes.end() && ((it+1)->getStyleHeight() == it->getStyleHeight())) + const auto size_boxes = GetSize(it->getStyleHeight()); + it->Display(size_boxes, i, verticalPadding); + // Index and verticalPadding only incrementing for the same style. (eg : it and it+1 as the same style.) + if (it + 1 != _boxes.end() && ((it + 1)->getStyleHeight() == it->getStyleHeight())) + { + verticalPadding += it->getPadding(); i++; + } else - i=0; + { + verticalPadding = 0; + i = 0; + } } } -TextBox::TextBox() -{} +size_t Components::GetSize(StyleHeight sh) +{ + size_t returnSize(0); + // returnSize is equal to FONT_SIZE + vertical padding * boxes with style sh + for(auto& box : _boxes) + returnSize += (box.getStyleHeight() == sh ? (FONT_SIZE+box.getPadding()) : 0); + return returnSize; +} -TextBox::TextBox(String str, StyleWidth sw, StyleHeight sh, u8g2_uint_t style) - : _text(str), _style(style), _styleWidth(sw), _styleHeight(sh) +TextBox::TextBox() +{ +} + +TextBox::TextBox(String str, StyleWidth sw, StyleHeight sh, u8g2_uint_t style, u8g2_uint_t w_padding, u8g2_uint_t h_padding, bool takeWholeLine) + : _text(str), _style(style), _paddingWidth(w_padding), _paddingHeight(h_padding), _styleWidth(sw), _styleHeight(sh), _takeWholeLine(takeWholeLine) { Calculate(); } @@ -58,7 +77,7 @@ void TextBox::Update(String str) void TextBox::Calculate() { const auto width = Screen::GetInstance().getWidth(); - _textWidth = Screen::GetInstance().getTextWidth(_text.c_str()); + _textWidth = _takeWholeLine ? width : Screen::GetInstance().getTextWidth(_text.c_str()); switch (_styleWidth) { case StyleWidth::LEFT: @@ -73,23 +92,24 @@ void TextBox::Calculate() } } -void TextBox::Display(size_t size, size_t position) +void TextBox::Display(size_t size, size_t position, u8g2_uint_t offsetY) { - const auto centeredOffset = (Screen::GetInstance().getHeight() - (size * FONT_SIZE)); + const auto centeredOffset = (Screen::GetInstance().getHeight() - size); // Later will be used with padding/margin const auto x = (_styleWidth == StyleWidth::CENTERED) ? _x : _x; switch (_styleHeight) { case StyleHeight::TOP: - Screen::GetInstance().getScreen().drawButtonUTF8(x, (position+1)*FONT_SIZE, _style, _textWidth, 0, 0, _text.c_str()); + Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + x, (position + 1) * FONT_SIZE + offsetY, _style, _textWidth, _paddingHeight, _paddingWidth, _text.c_str()); break; case StyleHeight::CENTERED: - Screen::GetInstance().getScreen().drawButtonUTF8(x, static_cast((centeredOffset/2)) + (position+1)*FONT_SIZE, _style, _textWidth, 0, 0, _text.c_str()); + Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + x, static_cast((centeredOffset / 2)) + (position + 1) * FONT_SIZE + offsetY, _style, _textWidth, _paddingHeight, _paddingWidth, _text.c_str()); break; case StyleHeight::BOTTOM: - Screen::GetInstance().getScreen().drawButtonUTF8(x, centeredOffset + (position+1)*FONT_SIZE, _style, _textWidth, 0, 0, _text.c_str()); + Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + x, centeredOffset + (position + 1) * FONT_SIZE + offsetY, _style, _textWidth, _paddingHeight, _paddingWidth, _text.c_str()); break; } } -StyleHeight TextBox::getStyleHeight() { return _styleHeight; } \ No newline at end of file +StyleHeight TextBox::getStyleHeight() { return _styleHeight; } +u8g2_uint_t TextBox::getPadding() { return _paddingHeight; } \ No newline at end of file diff --git a/embedded/lib/Component/ScreenComponents.hpp b/embedded/lib/Component/ScreenComponents.hpp index 51b707d..816490f 100644 --- a/embedded/lib/Component/ScreenComponents.hpp +++ b/embedded/lib/Component/ScreenComponents.hpp @@ -26,19 +26,35 @@ namespace Display { public: TextBox(); - TextBox(String str, StyleWidth sw, StyleHeight sh, u8g2_uint_t style); - void Display(size_t size, size_t position); + /** + * @brief Construct a new Text Box object + * + * @param str the string to display + * @param sw style width (LEFT, CENTERED, RIGHT) + * @param sh style height (TOP, CENTERED, BOTTOM) + * @param style u8g2lib button style (see doc @ ) + * @param w_padding width padding (default: 0) + * @param h_padding height padding (default: 0) + * @param takeWholeLine if true, the button takes the whole line + */ + TextBox(String str, StyleWidth sw, StyleHeight sh, u8g2_uint_t style, u8g2_uint_t w_padding=0, u8g2_uint_t h_padding=0, bool takeWholeLine=false); + void Display(size_t size, size_t position, u8g2_uint_t offsetY); void Update(String str); StyleHeight getStyleHeight(); + // Only vertical/height padding + u8g2_uint_t getPadding(); private: void Calculate(); String _text; uint8_t *_font; u8g2_uint_t _style; + u8g2_uint_t _paddingWidth; + u8g2_uint_t _paddingHeight; StyleWidth _styleWidth; StyleHeight _styleHeight; uint16_t _x; uint16_t _textWidth; + bool _takeWholeLine; }; // Components which contains every type @@ -51,6 +67,7 @@ namespace Display void Update(size_t index, String text); void Display(); private: + size_t GetSize(StyleHeight sh); // Boxes std::vector _boxes; }; From a16ee2b01f9f12634c09456b8920cb3c390b48fc Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Tue, 28 Nov 2023 23:31:17 +0100 Subject: [PATCH 14/23] Moved all the files from Screen. Components now uses shared ptr objects of Box. TextBox inherits from Box. --- embedded/lib/Display/Components/Box.hpp | 39 ++++++++++++ .../lib/Display/Components/Components.cpp | 57 +++++++++++++++++ .../lib/Display/Components/Components.hpp | 24 +++++++ .../Components/TextBox.cpp} | 63 ++----------------- .../Components/TextBox.hpp} | 53 +++------------- .../lib/{Component => Display}/Screen.cpp | 21 ++++--- .../lib/{Component => Display}/Screen.hpp | 5 +- embedded/lib/ServerHandler/ServerHandler.cpp | 2 +- 8 files changed, 150 insertions(+), 114 deletions(-) create mode 100644 embedded/lib/Display/Components/Box.hpp create mode 100644 embedded/lib/Display/Components/Components.cpp create mode 100644 embedded/lib/Display/Components/Components.hpp rename embedded/lib/{Component/ScreenComponents.cpp => Display/Components/TextBox.cpp} (59%) rename embedded/lib/{Component/ScreenComponents.hpp => Display/Components/TextBox.hpp} (53%) rename embedded/lib/{Component => Display}/Screen.cpp (69%) rename embedded/lib/{Component => Display}/Screen.hpp (94%) diff --git a/embedded/lib/Display/Components/Box.hpp b/embedded/lib/Display/Components/Box.hpp new file mode 100644 index 0000000..8a11bab --- /dev/null +++ b/embedded/lib/Display/Components/Box.hpp @@ -0,0 +1,39 @@ +#ifndef _HEADER_DISPLAY_BOX +#define _HEADER_DISPLAY_BOX +#include + +namespace Display +{ + // Global Constants + constexpr uint8_t FONT_SIZE = 8; + + // Enums + enum class StyleWidth + { + UNDEFINED, + LEFT, + CENTERED, + RIGHT + }; + + enum class StyleHeight + { + UNDEFINED, + TOP, + CENTERED, + BOTTOM + }; + + class Box + { + public: + Box() {}; + virtual void Display(size_t size, size_t position, u8g2_uint_t offsetY) {}; + virtual void Update(String str) {}; + virtual StyleHeight getStyleHeight() { return StyleHeight::UNDEFINED; }; + // Only vertical/height padding + virtual u8g2_uint_t getPadding() { return 0; }; + }; +} + +#endif //_HEADER_DISPLAY_BOX \ No newline at end of file diff --git a/embedded/lib/Display/Components/Components.cpp b/embedded/lib/Display/Components/Components.cpp new file mode 100644 index 0000000..8aae7c8 --- /dev/null +++ b/embedded/lib/Display/Components/Components.cpp @@ -0,0 +1,57 @@ +#include "Components.hpp" + +using namespace Display; + +Components::Components() +{ +} + +void Components::Add(std::shared_ptr box) +{ + // When Added, boxes should be reordered by style. + _boxes.push_back(box); +} + +void Components::Add(std::vector> boxes) +{ + for (auto box : boxes) + { + _boxes.push_back(box); + } +} + +void Components::Update(size_t index, String text) +{ + _boxes[index]->Update(text); +} + +void Components::Display() +{ + size_t i(0); + u8g2_uint_t verticalPadding(0); + for (auto it = _boxes.begin(); it != _boxes.end(); it++) + { + const auto size_boxes = GetSize((*it)->getStyleHeight()); + (*it)->Display(size_boxes, i, verticalPadding); + // Index and verticalPadding only incrementing for the same style. (eg : it and it+1 as the same style.) + if (it + 1 != _boxes.end() && ((*(it+1))->getStyleHeight() == (*it)->getStyleHeight())) + { + verticalPadding += (*it)->getPadding(); + i++; + } + else + { + verticalPadding = 0; + i = 0; + } + } +} + +size_t Components::GetSize(StyleHeight sh) +{ + size_t returnSize(0); + // returnSize is equal to FONT_SIZE + vertical padding * boxes with style sh + for(auto& box : _boxes) + returnSize += (box->getStyleHeight() == sh ? (FONT_SIZE+box->getPadding()) : 0); + return returnSize; +} \ No newline at end of file diff --git a/embedded/lib/Display/Components/Components.hpp b/embedded/lib/Display/Components/Components.hpp new file mode 100644 index 0000000..0f1ef8c --- /dev/null +++ b/embedded/lib/Display/Components/Components.hpp @@ -0,0 +1,24 @@ +#ifndef _HEADER_DISPLAY_COMPONENTS +#define _HEADER_DISPLAY_COMPONENTS +#include +#include +#include "Box.hpp" + +namespace Display +{ + class Components + { + public: + Components(); + void Add(std::shared_ptr box); + void Add(std::vector> boxes); + void Update(size_t index, String text); + void Display(); + private: + size_t GetSize(StyleHeight sh); + // Boxes + std::vector> _boxes; + }; +}; + +#endif //_HEADER_DISPLAY_COMPONENTS \ No newline at end of file diff --git a/embedded/lib/Component/ScreenComponents.cpp b/embedded/lib/Display/Components/TextBox.cpp similarity index 59% rename from embedded/lib/Component/ScreenComponents.cpp rename to embedded/lib/Display/Components/TextBox.cpp index abb5c07..ccadce3 100644 --- a/embedded/lib/Component/ScreenComponents.cpp +++ b/embedded/lib/Display/Components/TextBox.cpp @@ -1,63 +1,8 @@ -#include "ScreenComponents.hpp" -#include "Screen.hpp" -#include +#include "../Screen.hpp" +#include "TextBox.hpp" using namespace Display; -Components::Components() -{ -} - -void Components::Add(TextBox box) -{ - // When Added, boxes should be reordered by style. - _boxes.push_back(box); -} - -void Components::Add(std::vector boxes) -{ - for (auto box : boxes) - { - _boxes.push_back(box); - } -} - -void Components::Update(size_t index, String text) -{ - _boxes[index].Update(text); -} - -void Components::Display() -{ - size_t i(0); - u8g2_uint_t verticalPadding(0); - for (auto it = _boxes.begin(); it != _boxes.end(); it++) - { - const auto size_boxes = GetSize(it->getStyleHeight()); - it->Display(size_boxes, i, verticalPadding); - // Index and verticalPadding only incrementing for the same style. (eg : it and it+1 as the same style.) - if (it + 1 != _boxes.end() && ((it + 1)->getStyleHeight() == it->getStyleHeight())) - { - verticalPadding += it->getPadding(); - i++; - } - else - { - verticalPadding = 0; - i = 0; - } - } -} - -size_t Components::GetSize(StyleHeight sh) -{ - size_t returnSize(0); - // returnSize is equal to FONT_SIZE + vertical padding * boxes with style sh - for(auto& box : _boxes) - returnSize += (box.getStyleHeight() == sh ? (FONT_SIZE+box.getPadding()) : 0); - return returnSize; -} - TextBox::TextBox() { } @@ -89,6 +34,8 @@ void TextBox::Calculate() case StyleWidth::RIGHT: _x = width - _textWidth; break; + default: + _x=0; } } @@ -108,6 +55,8 @@ void TextBox::Display(size_t size, size_t position, u8g2_uint_t offsetY) case StyleHeight::BOTTOM: Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + x, centeredOffset + (position + 1) * FONT_SIZE + offsetY, _style, _textWidth, _paddingHeight, _paddingWidth, _text.c_str()); break; + default: + break; } } diff --git a/embedded/lib/Component/ScreenComponents.hpp b/embedded/lib/Display/Components/TextBox.hpp similarity index 53% rename from embedded/lib/Component/ScreenComponents.hpp rename to embedded/lib/Display/Components/TextBox.hpp index 816490f..4bef776 100644 --- a/embedded/lib/Component/ScreenComponents.hpp +++ b/embedded/lib/Display/Components/TextBox.hpp @@ -1,28 +1,11 @@ -#ifndef _HEADER_SCREEN_COMPONENTS -#define _HEADER_SCREEN_COMPONENTS -#include -#include -#include +#ifndef _HEADER_DISPLAY_TEXTBOX +#define _HEADER_DISPLAY_TEXTBOX +#include "Box.hpp" namespace Display { - // Enums - enum class StyleWidth - { - LEFT, - CENTERED, - RIGHT - }; - enum class StyleHeight - { - TOP, - CENTERED, - BOTTOM - }; - - // TextBox which inherits from Box (Single Component) - class TextBox + class TextBox : public Box { public: TextBox(); @@ -38,11 +21,10 @@ namespace Display * @param takeWholeLine if true, the button takes the whole line */ TextBox(String str, StyleWidth sw, StyleHeight sh, u8g2_uint_t style, u8g2_uint_t w_padding=0, u8g2_uint_t h_padding=0, bool takeWholeLine=false); - void Display(size_t size, size_t position, u8g2_uint_t offsetY); - void Update(String str); - StyleHeight getStyleHeight(); - // Only vertical/height padding - u8g2_uint_t getPadding(); + void Display(size_t size, size_t position, u8g2_uint_t offsetY) override; + void Update(String str) override; + StyleHeight getStyleHeight() override; + u8g2_uint_t getPadding() override; private: void Calculate(); String _text; @@ -56,21 +38,6 @@ namespace Display uint16_t _textWidth; bool _takeWholeLine; }; +} - // Components which contains every type - class Components - { - public: - Components(); - void Add(TextBox box); - void Add(std::vector boxes); - void Update(size_t index, String text); - void Display(); - private: - size_t GetSize(StyleHeight sh); - // Boxes - std::vector _boxes; - }; -}; - -#endif //_HEADER_SCREEN_COMPONENTS \ No newline at end of file +#endif //_HEADER_DISPLAY_TEXTBOX \ No newline at end of file diff --git a/embedded/lib/Component/Screen.cpp b/embedded/lib/Display/Screen.cpp similarity index 69% rename from embedded/lib/Component/Screen.cpp rename to embedded/lib/Display/Screen.cpp index 7084fec..8e46855 100644 --- a/embedded/lib/Component/Screen.cpp +++ b/embedded/lib/Display/Screen.cpp @@ -1,7 +1,6 @@ #include "Screen.hpp" -#include #include -#include +#include using namespace Display; @@ -15,21 +14,23 @@ Screen::Screen() } Screen::~Screen() -{} +{ +} void Screen::Setup(uint8_t *font) { _font = font; _screen->setFont(_font); - headerSetup = TextBox("Clover Setup", StyleWidth::LEFT, StyleHeight::TOP, U8G2_BTN_INV,2,5, true); + headerSetup = TextBox("Clover Setup", StyleWidth::LEFT, StyleHeight::TOP, U8G2_BTN_INV, 2, 5, true); // Static Components - connectingWindow.Add({headerSetup, TextBox("connect", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0)}); - connectedWindow.Add({headerSetup, - TextBox("Connected to Wi-Fi !", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0,0,2), - TextBox("IP address: ", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0,0,2), - TextBox("addr", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0,0,2)}); - loopWindow.Add(TextBox("Hello, Plant!", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW1)); + connectingWindow.Add({std::make_shared(headerSetup), + std::make_shared(TextBox("connect", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0))}); + connectedWindow.Add({std::make_shared(headerSetup), + std::make_shared(TextBox("Connected to Wi-Fi !", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), + std::make_shared(TextBox("IP address: ", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), + std::make_shared(TextBox("addr", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))}); + loopWindow.Add(std::make_shared(TextBox("Hello, Plant!", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW1))); } void Screen::connecting(uint8_t state) diff --git a/embedded/lib/Component/Screen.hpp b/embedded/lib/Display/Screen.hpp similarity index 94% rename from embedded/lib/Component/Screen.hpp rename to embedded/lib/Display/Screen.hpp index cb5fcc8..9f26ff0 100644 --- a/embedded/lib/Component/Screen.hpp +++ b/embedded/lib/Display/Screen.hpp @@ -3,12 +3,11 @@ #include #include -#include "ScreenComponents.hpp" +#include "Components/Components.hpp" +#include "Components/TextBox.hpp" namespace Display { - constexpr uint8_t FONT_SIZE=8; - class Screen { public: diff --git a/embedded/lib/ServerHandler/ServerHandler.cpp b/embedded/lib/ServerHandler/ServerHandler.cpp index 6983c88..fee89d0 100644 --- a/embedded/lib/ServerHandler/ServerHandler.cpp +++ b/embedded/lib/ServerHandler/ServerHandler.cpp @@ -1,5 +1,5 @@ #include "ServerHandler.hpp" -#include "Screen.hpp" +#include "../Display/Screen.hpp" ServerHandler::ServerHandler() : server(80), display_time(0) { } From f8adba547ee1f4a1ede6214d21b4299ed3ab6596 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Wed, 29 Nov 2023 15:16:03 +0100 Subject: [PATCH 15/23] Added many comments, Box has now some protected variables. --- embedded/lib/Display/Components/Box.hpp | 70 ++++++++++++++++++--- embedded/lib/Display/Components/TextBox.cpp | 18 +++--- embedded/lib/Display/Components/TextBox.hpp | 13 ++-- embedded/readme.MD | 4 +- 4 files changed, 80 insertions(+), 25 deletions(-) diff --git a/embedded/lib/Display/Components/Box.hpp b/embedded/lib/Display/Components/Box.hpp index 8a11bab..f127ad1 100644 --- a/embedded/lib/Display/Components/Box.hpp +++ b/embedded/lib/Display/Components/Box.hpp @@ -4,10 +4,14 @@ namespace Display { - // Global Constants + /** Size of the actual font from Screen. Used for many calculations + * ! Must be changed if the _font size is updated + */ constexpr uint8_t FONT_SIZE = 8; - // Enums + /** + * @brief Where each Box element is centered on the x axis. + */ enum class StyleWidth { UNDEFINED, @@ -16,6 +20,11 @@ namespace Display RIGHT }; + /** + * @brief Each Box element can be ordered into heights. + * Each height is independent from another and is placed differently on the screen. + * TOP starts on x=0, CENTERED on x=height/2 and TOP x=height + */ enum class StyleHeight { UNDEFINED, @@ -24,15 +33,60 @@ namespace Display BOTTOM }; + /** + * @brief Box is a virtual class which can be derived into many box elements + * and will be used in the 'Components' object. + * It is composed of 4 functions which may or not be used. + * Each box should use the Screen Interface in the Display function, + * other functions can be modified to the developer's needs. + */ class Box { public: - Box() {}; - virtual void Display(size_t size, size_t position, u8g2_uint_t offsetY) {}; - virtual void Update(String str) {}; - virtual StyleHeight getStyleHeight() { return StyleHeight::UNDEFINED; }; - // Only vertical/height padding - virtual u8g2_uint_t getPadding() { return 0; }; + /** + * @brief Construct a new Box object, can be ignored. + */ + Box(StyleHeight sh, u8g2_uint_t h_padding) + : _styleHeight(sh), _paddingHeight(h_padding){}; + + /** + * @brief Used to display the element on the screen. + * Will be using any Display function from the U8g2lib. + * ! Maybe a font will be added to arguments next... + * + * @param size the total size of the elements from a styleheight + * @param position the actual position of the element depending of the previous size + * @param offsetY an offset in Y, given by the 'Components' + */ + virtual void Display(size_t size, size_t position, u8g2_uint_t offsetY){}; + + /** + * @brief Will update by recalculating the 'Box' constants + * with the given argument. + * ! Will be modified in the near future to accept a template, or an std::any + * + * @param str + */ + virtual void Update(String str){}; + + /** + * @brief Get the Style Height, logic can be changed. + * + * @return StyleHeight + */ + virtual StyleHeight getStyleHeight() { return _styleHeight; }; + + /** + * @brief Get the Padding object, logic can be changed. + * ? Only vertical/height padding + * + * @return u8g2_uint_t + */ + virtual u8g2_uint_t getPadding() { return _paddingHeight; }; + + protected: + StyleHeight _styleHeight; + u8g2_uint_t _paddingHeight; }; } diff --git a/embedded/lib/Display/Components/TextBox.cpp b/embedded/lib/Display/Components/TextBox.cpp index ccadce3..b40c0c1 100644 --- a/embedded/lib/Display/Components/TextBox.cpp +++ b/embedded/lib/Display/Components/TextBox.cpp @@ -4,11 +4,12 @@ using namespace Display; TextBox::TextBox() + : Box(StyleHeight::UNDEFINED, 0) { } TextBox::TextBox(String str, StyleWidth sw, StyleHeight sh, u8g2_uint_t style, u8g2_uint_t w_padding, u8g2_uint_t h_padding, bool takeWholeLine) - : _text(str), _style(style), _paddingWidth(w_padding), _paddingHeight(h_padding), _styleWidth(sw), _styleHeight(sh), _takeWholeLine(takeWholeLine) + : Box(sh, h_padding), _text(str), _style(style), _paddingWidth(w_padding), _styleWidth(sw), _takeWholeLine(takeWholeLine) { Calculate(); } @@ -35,7 +36,7 @@ void TextBox::Calculate() _x = width - _textWidth; break; default: - _x=0; + _x = 0; } } @@ -44,21 +45,18 @@ void TextBox::Display(size_t size, size_t position, u8g2_uint_t offsetY) const auto centeredOffset = (Screen::GetInstance().getHeight() - size); // Later will be used with padding/margin const auto x = (_styleWidth == StyleWidth::CENTERED) ? _x : _x; - switch (_styleHeight) + switch (this->_styleHeight) { case StyleHeight::TOP: - Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + x, (position + 1) * FONT_SIZE + offsetY, _style, _textWidth, _paddingHeight, _paddingWidth, _text.c_str()); + Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + x, (position + 1) * FONT_SIZE + offsetY, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); break; case StyleHeight::CENTERED: - Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + x, static_cast((centeredOffset / 2)) + (position + 1) * FONT_SIZE + offsetY, _style, _textWidth, _paddingHeight, _paddingWidth, _text.c_str()); + Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + x, static_cast((centeredOffset / 2)) + (position + 1) * FONT_SIZE + offsetY, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); break; case StyleHeight::BOTTOM: - Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + x, centeredOffset + (position + 1) * FONT_SIZE + offsetY, _style, _textWidth, _paddingHeight, _paddingWidth, _text.c_str()); + Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + x, centeredOffset + (position + 1) * FONT_SIZE + offsetY, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); break; default: break; } -} - -StyleHeight TextBox::getStyleHeight() { return _styleHeight; } -u8g2_uint_t TextBox::getPadding() { return _paddingHeight; } \ No newline at end of file +} \ No newline at end of file diff --git a/embedded/lib/Display/Components/TextBox.hpp b/embedded/lib/Display/Components/TextBox.hpp index 4bef776..922dc1d 100644 --- a/embedded/lib/Display/Components/TextBox.hpp +++ b/embedded/lib/Display/Components/TextBox.hpp @@ -11,7 +11,7 @@ namespace Display TextBox(); /** * @brief Construct a new Text Box object - * + * * @param str the string to display * @param sw style width (LEFT, CENTERED, RIGHT) * @param sh style height (TOP, CENTERED, BOTTOM) @@ -20,20 +20,21 @@ namespace Display * @param h_padding height padding (default: 0) * @param takeWholeLine if true, the button takes the whole line */ - TextBox(String str, StyleWidth sw, StyleHeight sh, u8g2_uint_t style, u8g2_uint_t w_padding=0, u8g2_uint_t h_padding=0, bool takeWholeLine=false); + TextBox(String str, StyleWidth sw, StyleHeight sh, u8g2_uint_t style, u8g2_uint_t w_padding = 0, u8g2_uint_t h_padding = 0, bool takeWholeLine = false); void Display(size_t size, size_t position, u8g2_uint_t offsetY) override; void Update(String str) override; - StyleHeight getStyleHeight() override; - u8g2_uint_t getPadding() override; + private: + /** + * @brief Called on constructor or Update(). + */ void Calculate(); + String _text; uint8_t *_font; u8g2_uint_t _style; u8g2_uint_t _paddingWidth; - u8g2_uint_t _paddingHeight; StyleWidth _styleWidth; - StyleHeight _styleHeight; uint16_t _x; uint16_t _textWidth; bool _takeWholeLine; diff --git a/embedded/readme.MD b/embedded/readme.MD index 4cf28b6..0131bad 100644 --- a/embedded/readme.MD +++ b/embedded/readme.MD @@ -1,4 +1,6 @@ # .env file +``` SSID_CLOVER='"SSID"' -PSWD_CLOVER='"PASSWORD"' \ No newline at end of file +PSWD_CLOVER='"PASSWORD"' +``` \ No newline at end of file From 38308f77f83378805dd184761deefe6a837aad16 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Wed, 29 Nov 2023 22:27:57 +0100 Subject: [PATCH 16/23] Updated clover.xbm. Modified Box to use std::any. Added SpriteBox. Showing the clover sprite at startup. --- embedded/lib/Display/Components/Box.hpp | 6 ++-- embedded/lib/Display/Components/SpriteBox.cpp | 27 ++++++++++++++ embedded/lib/Display/Components/SpriteBox.hpp | 36 +++++++++++++++++++ embedded/lib/Display/Components/TextBox.cpp | 4 +-- embedded/lib/Display/Components/TextBox.hpp | 8 ++++- embedded/lib/Display/Screen.cpp | 6 +++- embedded/lib/Pictures/clover.xbm | 6 ++-- 7 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 embedded/lib/Display/Components/SpriteBox.cpp create mode 100644 embedded/lib/Display/Components/SpriteBox.hpp diff --git a/embedded/lib/Display/Components/Box.hpp b/embedded/lib/Display/Components/Box.hpp index f127ad1..0f8d897 100644 --- a/embedded/lib/Display/Components/Box.hpp +++ b/embedded/lib/Display/Components/Box.hpp @@ -1,6 +1,7 @@ #ifndef _HEADER_DISPLAY_BOX #define _HEADER_DISPLAY_BOX #include +#include namespace Display { @@ -63,11 +64,10 @@ namespace Display /** * @brief Will update by recalculating the 'Box' constants * with the given argument. - * ! Will be modified in the near future to accept a template, or an std::any * - * @param str + * @param data the data to modify, depending on the Box type */ - virtual void Update(String str){}; + virtual void Update(std::any data){}; /** * @brief Get the Style Height, logic can be changed. diff --git a/embedded/lib/Display/Components/SpriteBox.cpp b/embedded/lib/Display/Components/SpriteBox.cpp new file mode 100644 index 0000000..08f892d --- /dev/null +++ b/embedded/lib/Display/Components/SpriteBox.cpp @@ -0,0 +1,27 @@ +#include "../Screen.hpp" +#include "SpriteBox.hpp" + +using namespace Display; + +SpriteBox::SpriteBox() + :Box(StyleHeight::UNDEFINED,0) +{} + +SpriteBox::SpriteBox(unsigned char *sprite, uint16_t width, uint16_t height, u8g2_uint_t x, u8g2_uint_t y) + :Box(StyleHeight::TOP,0) + , _sprite(sprite) + , _width(width) + , _height(height) + , _x(x) + , _y(y) +{} + +void SpriteBox::Update(std::any data) +{ + _sprite = std::any_cast(data); +} + +void SpriteBox::Display(size_t size, size_t position, u8g2_uint_t offsetY) +{ + Screen::GetInstance().getScreen().drawXBM(_x,_y,_width,_height,_sprite); +} \ No newline at end of file diff --git a/embedded/lib/Display/Components/SpriteBox.hpp b/embedded/lib/Display/Components/SpriteBox.hpp new file mode 100644 index 0000000..06dcae5 --- /dev/null +++ b/embedded/lib/Display/Components/SpriteBox.hpp @@ -0,0 +1,36 @@ +#ifndef _HEADER_DISPLAY_SPRITEBOX +#define _HEADER_DISPLAY_SPRITEBOX +#include "Box.hpp" + +namespace Display +{ + + class SpriteBox : public Box + { + public: + SpriteBox(); + /** + * @brief Construct a new Text Box object + * + * @param sprite array from an .xbm format + */ + SpriteBox(unsigned char *sprite, uint16_t width, uint16_t height, u8g2_uint_t x=0, u8g2_uint_t y=0); + void Display(size_t size, size_t position, u8g2_uint_t offsetY) override; + + /** + * @brief Updates sprite + * + * @param data unsigned char* + */ + void Update(std::any data) override; + + private: + unsigned char* _sprite; + uint16_t _width; + uint16_t _height; + u8g2_uint_t _x; + u8g2_uint_t _y; + }; +} + +#endif //_HEADER_DISPLAY_SPRITEBOX \ No newline at end of file diff --git a/embedded/lib/Display/Components/TextBox.cpp b/embedded/lib/Display/Components/TextBox.cpp index b40c0c1..03b5d7d 100644 --- a/embedded/lib/Display/Components/TextBox.cpp +++ b/embedded/lib/Display/Components/TextBox.cpp @@ -14,9 +14,9 @@ TextBox::TextBox(String str, StyleWidth sw, StyleHeight sh, u8g2_uint_t style, u Calculate(); } -void TextBox::Update(String str) +void TextBox::Update(std::any data) { - _text = str; + _text = std::any_cast(data); Calculate(); } diff --git a/embedded/lib/Display/Components/TextBox.hpp b/embedded/lib/Display/Components/TextBox.hpp index 922dc1d..6bb6c41 100644 --- a/embedded/lib/Display/Components/TextBox.hpp +++ b/embedded/lib/Display/Components/TextBox.hpp @@ -22,7 +22,13 @@ namespace Display */ TextBox(String str, StyleWidth sw, StyleHeight sh, u8g2_uint_t style, u8g2_uint_t w_padding = 0, u8g2_uint_t h_padding = 0, bool takeWholeLine = false); void Display(size_t size, size_t position, u8g2_uint_t offsetY) override; - void Update(String str) override; + + /** + * @brief Updates String data + * + * @param data String + */ + void Update(std::any data) override; private: /** diff --git a/embedded/lib/Display/Screen.cpp b/embedded/lib/Display/Screen.cpp index 8e46855..5da8036 100644 --- a/embedded/lib/Display/Screen.cpp +++ b/embedded/lib/Display/Screen.cpp @@ -2,6 +2,10 @@ #include #include +// XBM Files +#include "Components/SpriteBox.hpp" +#include "../Pictures/clover.xbm" + using namespace Display; Screen::Screen() @@ -30,7 +34,7 @@ void Screen::Setup(uint8_t *font) std::make_shared(TextBox("Connected to Wi-Fi !", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), std::make_shared(TextBox("IP address: ", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), std::make_shared(TextBox("addr", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))}); - loopWindow.Add(std::make_shared(TextBox("Hello, Plant!", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW1))); + loopWindow.Add(std::make_shared(SpriteBox(clover_bits,clover_height,clover_width))); } void Screen::connecting(uint8_t state) diff --git a/embedded/lib/Pictures/clover.xbm b/embedded/lib/Pictures/clover.xbm index 4f520d9..3e0cf08 100644 --- a/embedded/lib/Pictures/clover.xbm +++ b/embedded/lib/Pictures/clover.xbm @@ -1,6 +1,6 @@ #define clover_width 16 #define clover_height 16 static unsigned char clover_bits[] = { - 0xff, 0xff, 0x7f, 0xfe, 0x7f, 0xfe, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, - 0x1f, 0xf8, 0x1f, 0xf8, 0x1c, 0x38, 0x30, 0x0c, 0x60, 0x06, 0xc1, 0x83, - 0xc1, 0x83, 0x83, 0xc1, 0x87, 0xe1, 0x3f, 0xfc }; + 0x00, 0x00, 0x80, 0x01, 0x80, 0x01, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, + 0xe0, 0x07, 0xe0, 0x07, 0xe3, 0xc7, 0xcf, 0xf3, 0x9f, 0xf9, 0x3e, 0x7c, + 0x3e, 0x7c, 0x7c, 0x3e, 0x78, 0x1e, 0xc0, 0x03 }; From d74c9516d26ac8f97110b6b34402cd532e1baa8b Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Thu, 30 Nov 2023 22:46:52 +0100 Subject: [PATCH 17/23] Update Components size_pos parameter. Updated SpriteBox to actually use Styles. --- embedded/lib/Display/Components/Box.hpp | 16 +++---- .../lib/Display/Components/Components.cpp | 10 ++-- embedded/lib/Display/Components/SpriteBox.cpp | 46 +++++++++++++++---- embedded/lib/Display/Components/SpriteBox.hpp | 9 ++-- embedded/lib/Display/Components/TextBox.cpp | 17 +++---- embedded/lib/Display/Components/TextBox.hpp | 6 ++- embedded/lib/Display/Screen.cpp | 2 +- 7 files changed, 67 insertions(+), 39 deletions(-) diff --git a/embedded/lib/Display/Components/Box.hpp b/embedded/lib/Display/Components/Box.hpp index 0f8d897..e577eb8 100644 --- a/embedded/lib/Display/Components/Box.hpp +++ b/embedded/lib/Display/Components/Box.hpp @@ -5,11 +5,6 @@ namespace Display { - /** Size of the actual font from Screen. Used for many calculations - * ! Must be changed if the _font size is updated - */ - constexpr uint8_t FONT_SIZE = 8; - /** * @brief Where each Box element is centered on the x axis. */ @@ -47,8 +42,8 @@ namespace Display /** * @brief Construct a new Box object, can be ignored. */ - Box(StyleHeight sh, u8g2_uint_t h_padding) - : _styleHeight(sh), _paddingHeight(h_padding){}; + Box(StyleHeight sh, u8g2_uint_t h_padding, uint16_t height) + : _styleHeight(sh), _paddingHeight(h_padding), _height(height) {}; /** * @brief Used to display the element on the screen. @@ -56,10 +51,10 @@ namespace Display * ! Maybe a font will be added to arguments next... * * @param size the total size of the elements from a styleheight - * @param position the actual position of the element depending of the previous size + * @param size_pos all the above sizes from each components in a same style height * @param offsetY an offset in Y, given by the 'Components' */ - virtual void Display(size_t size, size_t position, u8g2_uint_t offsetY){}; + virtual void Display(size_t size, size_t size_pos, u8g2_uint_t offsetY){}; /** * @brief Will update by recalculating the 'Box' constants @@ -84,9 +79,12 @@ namespace Display */ virtual u8g2_uint_t getPadding() { return _paddingHeight; }; + virtual uint16_t getHeight() { return _height; } + protected: StyleHeight _styleHeight; u8g2_uint_t _paddingHeight; + uint16_t _height; }; } diff --git a/embedded/lib/Display/Components/Components.cpp b/embedded/lib/Display/Components/Components.cpp index 8aae7c8..9ed0356 100644 --- a/embedded/lib/Display/Components/Components.cpp +++ b/embedded/lib/Display/Components/Components.cpp @@ -27,22 +27,22 @@ void Components::Update(size_t index, String text) void Components::Display() { - size_t i(0); + size_t totalSize(0); u8g2_uint_t verticalPadding(0); for (auto it = _boxes.begin(); it != _boxes.end(); it++) { const auto size_boxes = GetSize((*it)->getStyleHeight()); - (*it)->Display(size_boxes, i, verticalPadding); + (*it)->Display(size_boxes, totalSize, verticalPadding); // Index and verticalPadding only incrementing for the same style. (eg : it and it+1 as the same style.) if (it + 1 != _boxes.end() && ((*(it+1))->getStyleHeight() == (*it)->getStyleHeight())) { verticalPadding += (*it)->getPadding(); - i++; + totalSize += (*it)->getHeight(); } else { verticalPadding = 0; - i = 0; + totalSize = 0; } } } @@ -52,6 +52,6 @@ size_t Components::GetSize(StyleHeight sh) size_t returnSize(0); // returnSize is equal to FONT_SIZE + vertical padding * boxes with style sh for(auto& box : _boxes) - returnSize += (box->getStyleHeight() == sh ? (FONT_SIZE+box->getPadding()) : 0); + returnSize += (box->getStyleHeight() == sh ? (box->getHeight()+box->getPadding()) : 0); return returnSize; } \ No newline at end of file diff --git a/embedded/lib/Display/Components/SpriteBox.cpp b/embedded/lib/Display/Components/SpriteBox.cpp index 08f892d..d125156 100644 --- a/embedded/lib/Display/Components/SpriteBox.cpp +++ b/embedded/lib/Display/Components/SpriteBox.cpp @@ -4,24 +4,54 @@ using namespace Display; SpriteBox::SpriteBox() - :Box(StyleHeight::UNDEFINED,0) + :Box(StyleHeight::UNDEFINED,0,0) {} -SpriteBox::SpriteBox(unsigned char *sprite, uint16_t width, uint16_t height, u8g2_uint_t x, u8g2_uint_t y) - :Box(StyleHeight::TOP,0) +SpriteBox::SpriteBox(unsigned char *sprite, uint16_t width, uint16_t height, StyleWidth sw, StyleHeight sh) + :Box(sh,0,height) , _sprite(sprite) + , _styleWidth(sw) , _width(width) , _height(height) - , _x(x) - , _y(y) -{} +{ + Calculate(); +} void SpriteBox::Update(std::any data) { _sprite = std::any_cast(data); + Calculate(); } -void SpriteBox::Display(size_t size, size_t position, u8g2_uint_t offsetY) +void SpriteBox::Calculate() { - Screen::GetInstance().getScreen().drawXBM(_x,_y,_width,_height,_sprite); + const auto screenWidth = Screen::GetInstance().getWidth(); + switch (_styleWidth) + { + case StyleWidth::CENTERED: + _x = (screenWidth - _width) / 2; + break; + case StyleWidth::RIGHT: + _x = screenWidth - _width; + break; + default: + _x = 0; + } +} + +void SpriteBox::Display(size_t size, size_t size_pos, u8g2_uint_t offsetY) +{ + const auto centeredOffset = (Screen::GetInstance().getHeight() - size); + switch(this->_styleHeight) + { + case StyleHeight::CENTERED: + // idk must be the size of all the above + Screen::GetInstance().getScreen().drawXBM(_x, static_cast((centeredOffset / 2)) + size_pos + offsetY,_width,_height,_sprite); + break; + case StyleHeight::BOTTOM: + Screen::GetInstance().getScreen().drawXBM(_x, centeredOffset + size_pos + offsetY,_width,_height,_sprite); + break; + default: + Screen::GetInstance().getScreen().drawXBM(_x, size_pos + offsetY,_width,_height,_sprite); + } } \ No newline at end of file diff --git a/embedded/lib/Display/Components/SpriteBox.hpp b/embedded/lib/Display/Components/SpriteBox.hpp index 06dcae5..357231c 100644 --- a/embedded/lib/Display/Components/SpriteBox.hpp +++ b/embedded/lib/Display/Components/SpriteBox.hpp @@ -14,8 +14,8 @@ namespace Display * * @param sprite array from an .xbm format */ - SpriteBox(unsigned char *sprite, uint16_t width, uint16_t height, u8g2_uint_t x=0, u8g2_uint_t y=0); - void Display(size_t size, size_t position, u8g2_uint_t offsetY) override; + SpriteBox(unsigned char *sprite, uint16_t width, uint16_t height, StyleWidth sw, StyleHeight sh); + void Display(size_t size, size_t size_pos, u8g2_uint_t offsetY) override; /** * @brief Updates sprite @@ -25,11 +25,12 @@ namespace Display void Update(std::any data) override; private: + void Calculate(); unsigned char* _sprite; + StyleWidth _styleWidth; uint16_t _width; uint16_t _height; - u8g2_uint_t _x; - u8g2_uint_t _y; + uint16_t _x; }; } diff --git a/embedded/lib/Display/Components/TextBox.cpp b/embedded/lib/Display/Components/TextBox.cpp index 03b5d7d..ef7d11f 100644 --- a/embedded/lib/Display/Components/TextBox.cpp +++ b/embedded/lib/Display/Components/TextBox.cpp @@ -4,12 +4,12 @@ using namespace Display; TextBox::TextBox() - : Box(StyleHeight::UNDEFINED, 0) + : Box(StyleHeight::UNDEFINED, 0, 0) { } TextBox::TextBox(String str, StyleWidth sw, StyleHeight sh, u8g2_uint_t style, u8g2_uint_t w_padding, u8g2_uint_t h_padding, bool takeWholeLine) - : Box(sh, h_padding), _text(str), _style(style), _paddingWidth(w_padding), _styleWidth(sw), _takeWholeLine(takeWholeLine) + : Box(sh, h_padding, FONT_SIZE), _text(str), _style(style), _paddingWidth(w_padding), _styleWidth(sw), _takeWholeLine(takeWholeLine) { Calculate(); } @@ -40,23 +40,18 @@ void TextBox::Calculate() } } -void TextBox::Display(size_t size, size_t position, u8g2_uint_t offsetY) +void TextBox::Display(size_t size, size_t size_pos, u8g2_uint_t offsetY) { const auto centeredOffset = (Screen::GetInstance().getHeight() - size); - // Later will be used with padding/margin - const auto x = (_styleWidth == StyleWidth::CENTERED) ? _x : _x; switch (this->_styleHeight) { - case StyleHeight::TOP: - Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + x, (position + 1) * FONT_SIZE + offsetY, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); - break; case StyleHeight::CENTERED: - Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + x, static_cast((centeredOffset / 2)) + (position + 1) * FONT_SIZE + offsetY, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); + Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, static_cast((centeredOffset / 2)) + size_pos + offsetY, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); break; case StyleHeight::BOTTOM: - Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + x, centeredOffset + (position + 1) * FONT_SIZE + offsetY, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); + Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, centeredOffset + size_pos + offsetY, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); break; default: - break; + Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, size_pos + offsetY, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); } } \ No newline at end of file diff --git a/embedded/lib/Display/Components/TextBox.hpp b/embedded/lib/Display/Components/TextBox.hpp index 6bb6c41..5200a54 100644 --- a/embedded/lib/Display/Components/TextBox.hpp +++ b/embedded/lib/Display/Components/TextBox.hpp @@ -4,6 +4,10 @@ namespace Display { + /** Size of the actual font from Screen. Used for many calculations + * ! Must be changed if the _font size is updated + */ + constexpr uint8_t FONT_SIZE = 8; class TextBox : public Box { @@ -21,7 +25,7 @@ namespace Display * @param takeWholeLine if true, the button takes the whole line */ TextBox(String str, StyleWidth sw, StyleHeight sh, u8g2_uint_t style, u8g2_uint_t w_padding = 0, u8g2_uint_t h_padding = 0, bool takeWholeLine = false); - void Display(size_t size, size_t position, u8g2_uint_t offsetY) override; + void Display(size_t size, size_t size_pos, u8g2_uint_t offsetY) override; /** * @brief Updates String data diff --git a/embedded/lib/Display/Screen.cpp b/embedded/lib/Display/Screen.cpp index 5da8036..23ab7c4 100644 --- a/embedded/lib/Display/Screen.cpp +++ b/embedded/lib/Display/Screen.cpp @@ -34,7 +34,7 @@ void Screen::Setup(uint8_t *font) std::make_shared(TextBox("Connected to Wi-Fi !", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), std::make_shared(TextBox("IP address: ", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), std::make_shared(TextBox("addr", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))}); - loopWindow.Add(std::make_shared(SpriteBox(clover_bits,clover_height,clover_width))); + loopWindow.Add(std::make_shared(SpriteBox(clover_bits,clover_height,clover_width,StyleWidth::CENTERED,StyleHeight::CENTERED))); } void Screen::connecting(uint8_t state) From ad71d0997b25d611057786843b2f486ab694a515 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Fri, 1 Dec 2023 14:33:21 +0100 Subject: [PATCH 18/23] Fixed TextBox not well aligned. (Not tested on real hw.) --- embedded/lib/Display/Components/Box.hpp | 5 ++--- embedded/lib/Display/Components/Components.cpp | 15 ++++----------- embedded/lib/Display/Components/SpriteBox.cpp | 8 ++++---- embedded/lib/Display/Components/SpriteBox.hpp | 2 +- embedded/lib/Display/Components/TextBox.cpp | 8 ++++---- embedded/lib/Display/Components/TextBox.hpp | 2 +- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/embedded/lib/Display/Components/Box.hpp b/embedded/lib/Display/Components/Box.hpp index e577eb8..a68cc2c 100644 --- a/embedded/lib/Display/Components/Box.hpp +++ b/embedded/lib/Display/Components/Box.hpp @@ -51,10 +51,9 @@ namespace Display * ! Maybe a font will be added to arguments next... * * @param size the total size of the elements from a styleheight - * @param size_pos all the above sizes from each components in a same style height - * @param offsetY an offset in Y, given by the 'Components' + * @param size_pos all the above sizes from each components in a same style height plus its height padding */ - virtual void Display(size_t size, size_t size_pos, u8g2_uint_t offsetY){}; + virtual void Display(u8g2_uint_t size, u8g2_uint_t size_pos){}; /** * @brief Will update by recalculating the 'Box' constants diff --git a/embedded/lib/Display/Components/Components.cpp b/embedded/lib/Display/Components/Components.cpp index 9ed0356..07fc7d7 100644 --- a/embedded/lib/Display/Components/Components.cpp +++ b/embedded/lib/Display/Components/Components.cpp @@ -27,23 +27,16 @@ void Components::Update(size_t index, String text) void Components::Display() { - size_t totalSize(0); - u8g2_uint_t verticalPadding(0); + u8g2_uint_t totalSize(0); for (auto it = _boxes.begin(); it != _boxes.end(); it++) { const auto size_boxes = GetSize((*it)->getStyleHeight()); - (*it)->Display(size_boxes, totalSize, verticalPadding); + (*it)->Display(size_boxes, totalSize); // Index and verticalPadding only incrementing for the same style. (eg : it and it+1 as the same style.) if (it + 1 != _boxes.end() && ((*(it+1))->getStyleHeight() == (*it)->getStyleHeight())) - { - verticalPadding += (*it)->getPadding(); - totalSize += (*it)->getHeight(); - } + totalSize += (*it)->getHeight() + (2*(*it)->getPadding()); else - { - verticalPadding = 0; totalSize = 0; - } } } @@ -52,6 +45,6 @@ size_t Components::GetSize(StyleHeight sh) size_t returnSize(0); // returnSize is equal to FONT_SIZE + vertical padding * boxes with style sh for(auto& box : _boxes) - returnSize += (box->getStyleHeight() == sh ? (box->getHeight()+box->getPadding()) : 0); + returnSize += (box->getStyleHeight() == sh ? (box->getHeight()+(2*box->getPadding())) : 0); return returnSize; } \ No newline at end of file diff --git a/embedded/lib/Display/Components/SpriteBox.cpp b/embedded/lib/Display/Components/SpriteBox.cpp index d125156..44d32bb 100644 --- a/embedded/lib/Display/Components/SpriteBox.cpp +++ b/embedded/lib/Display/Components/SpriteBox.cpp @@ -39,19 +39,19 @@ void SpriteBox::Calculate() } } -void SpriteBox::Display(size_t size, size_t size_pos, u8g2_uint_t offsetY) +void SpriteBox::Display(u8g2_uint_t size, u8g2_uint_t size_pos) { const auto centeredOffset = (Screen::GetInstance().getHeight() - size); switch(this->_styleHeight) { case StyleHeight::CENTERED: // idk must be the size of all the above - Screen::GetInstance().getScreen().drawXBM(_x, static_cast((centeredOffset / 2)) + size_pos + offsetY,_width,_height,_sprite); + Screen::GetInstance().getScreen().drawXBM(_x, static_cast((centeredOffset / 2)) + size_pos,_width,_height,_sprite); break; case StyleHeight::BOTTOM: - Screen::GetInstance().getScreen().drawXBM(_x, centeredOffset + size_pos + offsetY,_width,_height,_sprite); + Screen::GetInstance().getScreen().drawXBM(_x, centeredOffset + size_pos,_width,_height,_sprite); break; default: - Screen::GetInstance().getScreen().drawXBM(_x, size_pos + offsetY,_width,_height,_sprite); + Screen::GetInstance().getScreen().drawXBM(_x, size_pos,_width,_height,_sprite); } } \ No newline at end of file diff --git a/embedded/lib/Display/Components/SpriteBox.hpp b/embedded/lib/Display/Components/SpriteBox.hpp index 357231c..1471114 100644 --- a/embedded/lib/Display/Components/SpriteBox.hpp +++ b/embedded/lib/Display/Components/SpriteBox.hpp @@ -15,7 +15,7 @@ namespace Display * @param sprite array from an .xbm format */ SpriteBox(unsigned char *sprite, uint16_t width, uint16_t height, StyleWidth sw, StyleHeight sh); - void Display(size_t size, size_t size_pos, u8g2_uint_t offsetY) override; + void Display(u8g2_uint_t size, u8g2_uint_t size_pos) override; /** * @brief Updates sprite diff --git a/embedded/lib/Display/Components/TextBox.cpp b/embedded/lib/Display/Components/TextBox.cpp index ef7d11f..c0fc3e1 100644 --- a/embedded/lib/Display/Components/TextBox.cpp +++ b/embedded/lib/Display/Components/TextBox.cpp @@ -40,18 +40,18 @@ void TextBox::Calculate() } } -void TextBox::Display(size_t size, size_t size_pos, u8g2_uint_t offsetY) +void TextBox::Display(u8g2_uint_t size, u8g2_uint_t size_pos) { const auto centeredOffset = (Screen::GetInstance().getHeight() - size); switch (this->_styleHeight) { case StyleHeight::CENTERED: - Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, static_cast((centeredOffset / 2)) + size_pos + offsetY, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); + Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, static_cast((centeredOffset / 2)) + size_pos + _height, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); break; case StyleHeight::BOTTOM: - Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, centeredOffset + size_pos + offsetY, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); + Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, centeredOffset + size_pos + _height, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); break; default: - Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, size_pos + offsetY, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); + Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, size_pos + _height, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); } } \ No newline at end of file diff --git a/embedded/lib/Display/Components/TextBox.hpp b/embedded/lib/Display/Components/TextBox.hpp index 5200a54..5955990 100644 --- a/embedded/lib/Display/Components/TextBox.hpp +++ b/embedded/lib/Display/Components/TextBox.hpp @@ -25,7 +25,7 @@ namespace Display * @param takeWholeLine if true, the button takes the whole line */ TextBox(String str, StyleWidth sw, StyleHeight sh, u8g2_uint_t style, u8g2_uint_t w_padding = 0, u8g2_uint_t h_padding = 0, bool takeWholeLine = false); - void Display(size_t size, size_t size_pos, u8g2_uint_t offsetY) override; + void Display(u8g2_uint_t size, u8g2_uint_t size_pos) override; /** * @brief Updates String data From 7e1d7f1526a1223428714526d84f35c047e278bb Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Wed, 13 Dec 2023 11:42:52 +0100 Subject: [PATCH 19/23] Screen: Added failed logo. Updated Box to have a FORCED_CENTERED. When Wifi is not connected, show failed screen. --- embedded/lib/Display/Components/Box.hpp | 5 ++- .../lib/Display/Components/Components.cpp | 6 ++- embedded/lib/Display/Components/SpriteBox.cpp | 1 + embedded/lib/Display/Components/TextBox.cpp | 1 + embedded/lib/Display/Screen.cpp | 15 ++++++- embedded/lib/Display/Screen.hpp | 4 +- embedded/lib/Pictures/failed.xbm | 6 +++ embedded/lib/ServerHandler/ServerHandler.cpp | 41 ++++++++++++------- embedded/lib/ServerHandler/ServerHandler.hpp | 3 ++ embedded/platformio.ini | 1 + embedded/src/main.cpp | 7 ++++ 11 files changed, 69 insertions(+), 21 deletions(-) create mode 100644 embedded/lib/Pictures/failed.xbm diff --git a/embedded/lib/Display/Components/Box.hpp b/embedded/lib/Display/Components/Box.hpp index a68cc2c..5b7b426 100644 --- a/embedded/lib/Display/Components/Box.hpp +++ b/embedded/lib/Display/Components/Box.hpp @@ -26,11 +26,12 @@ namespace Display UNDEFINED, TOP, CENTERED, - BOTTOM + BOTTOM, + FORCE_CENTERED }; /** - * @brief Box is a virtual class which can be derived into many box elements + * @brief Box is an abstract class which can be derived into many box elements * and will be used in the 'Components' object. * It is composed of 4 functions which may or not be used. * Each box should use the Screen Interface in the Display function, diff --git a/embedded/lib/Display/Components/Components.cpp b/embedded/lib/Display/Components/Components.cpp index 07fc7d7..d23913b 100644 --- a/embedded/lib/Display/Components/Components.cpp +++ b/embedded/lib/Display/Components/Components.cpp @@ -32,8 +32,10 @@ void Components::Display() { const auto size_boxes = GetSize((*it)->getStyleHeight()); (*it)->Display(size_boxes, totalSize); - // Index and verticalPadding only incrementing for the same style. (eg : it and it+1 as the same style.) - if (it + 1 != _boxes.end() && ((*(it+1))->getStyleHeight() == (*it)->getStyleHeight())) + + /* Index and verticalPadding only incrementing for the same style. (eg : it and it+1 as the same style.) + Plus, it has to not be FORCED to be incremented.*/ + if (it + 1 != _boxes.end() && ((*(it+1))->getStyleHeight() == (*it)->getStyleHeight()) && ((*it)->getStyleHeight() != StyleHeight::FORCE_CENTERED)) totalSize += (*it)->getHeight() + (2*(*it)->getPadding()); else totalSize = 0; diff --git a/embedded/lib/Display/Components/SpriteBox.cpp b/embedded/lib/Display/Components/SpriteBox.cpp index 44d32bb..683da52 100644 --- a/embedded/lib/Display/Components/SpriteBox.cpp +++ b/embedded/lib/Display/Components/SpriteBox.cpp @@ -45,6 +45,7 @@ void SpriteBox::Display(u8g2_uint_t size, u8g2_uint_t size_pos) switch(this->_styleHeight) { case StyleHeight::CENTERED: + case StyleHeight::FORCE_CENTERED: // idk must be the size of all the above Screen::GetInstance().getScreen().drawXBM(_x, static_cast((centeredOffset / 2)) + size_pos,_width,_height,_sprite); break; diff --git a/embedded/lib/Display/Components/TextBox.cpp b/embedded/lib/Display/Components/TextBox.cpp index c0fc3e1..9494fd1 100644 --- a/embedded/lib/Display/Components/TextBox.cpp +++ b/embedded/lib/Display/Components/TextBox.cpp @@ -46,6 +46,7 @@ void TextBox::Display(u8g2_uint_t size, u8g2_uint_t size_pos) switch (this->_styleHeight) { case StyleHeight::CENTERED: + case StyleHeight::FORCE_CENTERED: Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, static_cast((centeredOffset / 2)) + size_pos + _height, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); break; case StyleHeight::BOTTOM: diff --git a/embedded/lib/Display/Screen.cpp b/embedded/lib/Display/Screen.cpp index 23ab7c4..244c979 100644 --- a/embedded/lib/Display/Screen.cpp +++ b/embedded/lib/Display/Screen.cpp @@ -5,6 +5,7 @@ // XBM Files #include "Components/SpriteBox.hpp" #include "../Pictures/clover.xbm" +#include "../Pictures/failed.xbm" using namespace Display; @@ -30,11 +31,14 @@ void Screen::Setup(uint8_t *font) // Static Components connectingWindow.Add({std::make_shared(headerSetup), std::make_shared(TextBox("connect", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0))}); + connectionfailedWindow.Add({std::make_shared(headerSetup), + std::make_shared(TextBox("Failed to connect.", StyleWidth::RIGHT, StyleHeight::CENTERED, U8G2_BTN_BW0,3)), + std::make_shared(SpriteBox(failed_bits,failed_height,failed_width,StyleWidth::LEFT,StyleHeight::FORCE_CENTERED))}); connectedWindow.Add({std::make_shared(headerSetup), std::make_shared(TextBox("Connected to Wi-Fi !", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), std::make_shared(TextBox("IP address: ", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), std::make_shared(TextBox("addr", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))}); - loopWindow.Add(std::make_shared(SpriteBox(clover_bits,clover_height,clover_width,StyleWidth::CENTERED,StyleHeight::CENTERED))); + loopWindow.Add(std::make_shared(SpriteBox(clover_bits, clover_height, clover_width, StyleWidth::CENTERED, StyleHeight::CENTERED))); } void Screen::connecting(uint8_t state) @@ -63,6 +67,15 @@ void Screen::connecting(uint8_t state) _screen->sendBuffer(); } +void Screen::notConnected() +{ + _screen->clearBuffer(); + // Component + connectionfailedWindow.Display(); + // Displaying + _screen->sendBuffer(); +} + void Screen::connected(const char *ipaddress, uint8_t timing) { _screen->clearBuffer(); diff --git a/embedded/lib/Display/Screen.hpp b/embedded/lib/Display/Screen.hpp index 9f26ff0..c7731cd 100644 --- a/embedded/lib/Display/Screen.hpp +++ b/embedded/lib/Display/Screen.hpp @@ -19,7 +19,8 @@ namespace Display } // Public functions void Setup(uint8_t *font); - void connecting(uint8_t state = 0); + void connecting(uint8_t state=0); + void notConnected(); void connected(const char *ipaddress, uint8_t timing); void loop(); // Getters @@ -44,6 +45,7 @@ namespace Display // Static Components TextBox headerSetup; Components connectingWindow; + Components connectionfailedWindow; Components connectedWindow; Components loopWindow; }; diff --git a/embedded/lib/Pictures/failed.xbm b/embedded/lib/Pictures/failed.xbm new file mode 100644 index 0000000..2a1ffec --- /dev/null +++ b/embedded/lib/Pictures/failed.xbm @@ -0,0 +1,6 @@ +#define failed_width 16 +#define failed_height 16 +static unsigned char failed_bits[] = { + 0x00, 0x00, 0x06, 0x60, 0x0e, 0x70, 0x1c, 0x38, 0x38, 0x1c, 0x70, 0x0e, + 0xe0, 0x07, 0xc0, 0x03, 0xc0, 0x03, 0xe0, 0x07, 0x70, 0x0e, 0x38, 0x1c, + 0x1c, 0x38, 0x0e, 0x70, 0x06, 0x60, 0x00, 0x00 }; diff --git a/embedded/lib/ServerHandler/ServerHandler.cpp b/embedded/lib/ServerHandler/ServerHandler.cpp index fee89d0..8da17e4 100644 --- a/embedded/lib/ServerHandler/ServerHandler.cpp +++ b/embedded/lib/ServerHandler/ServerHandler.cpp @@ -1,42 +1,53 @@ #include "ServerHandler.hpp" #include "../Display/Screen.hpp" -ServerHandler::ServerHandler() : server(80), display_time(0) { +ServerHandler::ServerHandler() : server(80), display_time(0), _connected(false) +{ } ServerHandler::~ServerHandler() {} -void ServerHandler::setup(const char* ssid, const char* password) { // On utilise les scope resolution operator pour définir les méthodes la classe ServerHandle qui elle est dans hpp +void ServerHandler::setup(const char *ssid, const char *password) +{ // On utilise les scope resolution operator pour définir les méthodes la classe ServerHandle qui elle est dans hpp uint8_t state(0); + uint16_t tryConnection(0); Serial.begin(9600); WiFi.begin(ssid, password); - while (WiFi.status() != WL_CONNECTED) { + // Testing connection + while ((WiFi.status() != WL_CONNECTED) && (tryConnection < MAX_CONNECT_TRIES)) + { delay(500); Display::Screen::GetInstance().connecting(state); - state >= 3 ? state = 0: state++; + state >= 3 ? state = 0 : state++; + tryConnection++; } - server.begin(); - server.on("/", [this]() { this->handleRoot(); }); // fonction lamda pour gérer les requettes get + if (tryConnection < MAX_CONNECT_TRIES) + { + _connected = true; + server.begin(); + server.on("/", [this]() + { this->handleRoot(); }); // fonction lamda pour gérer les requettes get + } } -void ServerHandler::loop() { - if(display_time < MAX_TIME) +void ServerHandler::loop() +{ + if (display_time < MAX_TIME) { - Display::Screen::GetInstance().connected(WiFi.localIP().toString().c_str(),display_time); + Display::Screen::GetInstance().connected(WiFi.localIP().toString().c_str(), display_time); display_time++; } server.handleClient(); } -bool ServerHandler::showNext() -{ - return (display_time >= MAX_TIME); -} +bool ServerHandler::showNext() { return (display_time >= MAX_TIME); } +bool ServerHandler::isConnected() { return _connected; } -void ServerHandler::handleRoot() { - auto& dataHandler = DataHandler::GetInstance(); +void ServerHandler::handleRoot() +{ + auto &dataHandler = DataHandler::GetInstance(); String jsonFormattedData = dataHandler.getJsonData(); server.send(200, "application/json", jsonFormattedData); } diff --git a/embedded/lib/ServerHandler/ServerHandler.hpp b/embedded/lib/ServerHandler/ServerHandler.hpp index bf233ae..20a390b 100644 --- a/embedded/lib/ServerHandler/ServerHandler.hpp +++ b/embedded/lib/ServerHandler/ServerHandler.hpp @@ -7,6 +7,7 @@ #include "DataHandler.hpp" constexpr uint8_t MAX_TIME = 28; +constexpr uint16_t MAX_CONNECT_TRIES = 20; class ServerHandler { public: @@ -21,6 +22,7 @@ public: void loop(); // Return if the screen needs to be changed. bool showNext(); + bool isConnected(); private: // Singleton @@ -32,6 +34,7 @@ private: void handleRoot(); ESP8266WebServer server; uint8_t display_time; + bool _connected; }; #endif diff --git a/embedded/platformio.ini b/embedded/platformio.ini index 6f09bfb..1f38097 100644 --- a/embedded/platformio.ini +++ b/embedded/platformio.ini @@ -11,6 +11,7 @@ [env:nodemcuv2] platform = espressif8266 board = nodemcuv2 +build_flags = -fexceptions framework = arduino lib_deps = tzapu/WiFiManager@^0.16.0 diff --git a/embedded/src/main.cpp b/embedded/src/main.cpp index 31d961b..83b1a66 100644 --- a/embedded/src/main.cpp +++ b/embedded/src/main.cpp @@ -28,6 +28,13 @@ void loop() auto& dataHandler = DataHandler::GetInstance(); auto& screen = Display::Screen::GetInstance(); + // If could not connect, show screen failure + if(!serverHandler.isConnected()) + { + screen.notConnected(); + return; + } + // If serverHandler finished showing ip. if (serverHandler.showNext()) screen.loop(); From c2b18fc05210e71306fad6ace1cfa9ca2bc6e38b Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Wed, 13 Dec 2023 17:37:42 +0100 Subject: [PATCH 20/23] Screen: Added multiple frames for the boot screen. Fixed delay issues when in main loop. Showing bootscreen after setup. --- .../lib/Display/Components/Components.cpp | 4 +-- .../lib/Display/Components/Components.hpp | 2 +- embedded/lib/Display/Components/SpriteBox.cpp | 5 ++- embedded/lib/Display/Components/SpriteBox.hpp | 5 +++ embedded/lib/Display/Screen.cpp | 24 +++++++++---- embedded/lib/Display/Screen.hpp | 34 +++++++++++++++++++ embedded/lib/Pictures/clover1.xbm | 14 ++++++++ embedded/lib/Pictures/clover10.xbm | 14 ++++++++ embedded/lib/Pictures/clover11.xbm | 14 ++++++++ embedded/lib/Pictures/clover2.xbm | 14 ++++++++ embedded/lib/Pictures/clover3.xbm | 14 ++++++++ embedded/lib/Pictures/clover4.xbm | 14 ++++++++ embedded/lib/Pictures/clover5.xbm | 14 ++++++++ embedded/lib/Pictures/clover6.xbm | 14 ++++++++ embedded/lib/Pictures/clover7.xbm | 14 ++++++++ embedded/lib/Pictures/clover8.xbm | 14 ++++++++ embedded/lib/Pictures/clover9.xbm | 14 ++++++++ embedded/lib/ServerHandler/ServerHandler.cpp | 1 + embedded/lib/ServerHandler/ServerHandler.hpp | 1 + embedded/src/main.cpp | 13 +++++-- 20 files changed, 229 insertions(+), 14 deletions(-) create mode 100644 embedded/lib/Pictures/clover1.xbm create mode 100644 embedded/lib/Pictures/clover10.xbm create mode 100644 embedded/lib/Pictures/clover11.xbm create mode 100644 embedded/lib/Pictures/clover2.xbm create mode 100644 embedded/lib/Pictures/clover3.xbm create mode 100644 embedded/lib/Pictures/clover4.xbm create mode 100644 embedded/lib/Pictures/clover5.xbm create mode 100644 embedded/lib/Pictures/clover6.xbm create mode 100644 embedded/lib/Pictures/clover7.xbm create mode 100644 embedded/lib/Pictures/clover8.xbm create mode 100644 embedded/lib/Pictures/clover9.xbm diff --git a/embedded/lib/Display/Components/Components.cpp b/embedded/lib/Display/Components/Components.cpp index d23913b..d13a3b4 100644 --- a/embedded/lib/Display/Components/Components.cpp +++ b/embedded/lib/Display/Components/Components.cpp @@ -20,9 +20,9 @@ void Components::Add(std::vector> boxes) } } -void Components::Update(size_t index, String text) +void Components::Update(size_t index, std::any modified) { - _boxes[index]->Update(text); + _boxes[index]->Update(modified); } void Components::Display() diff --git a/embedded/lib/Display/Components/Components.hpp b/embedded/lib/Display/Components/Components.hpp index 0f1ef8c..d0c6212 100644 --- a/embedded/lib/Display/Components/Components.hpp +++ b/embedded/lib/Display/Components/Components.hpp @@ -12,7 +12,7 @@ namespace Display Components(); void Add(std::shared_ptr box); void Add(std::vector> boxes); - void Update(size_t index, String text); + void Update(size_t index, std::any modified); void Display(); private: size_t GetSize(StyleHeight sh); diff --git a/embedded/lib/Display/Components/SpriteBox.cpp b/embedded/lib/Display/Components/SpriteBox.cpp index 683da52..ad77b37 100644 --- a/embedded/lib/Display/Components/SpriteBox.cpp +++ b/embedded/lib/Display/Components/SpriteBox.cpp @@ -19,7 +19,10 @@ SpriteBox::SpriteBox(unsigned char *sprite, uint16_t width, uint16_t height, Sty void SpriteBox::Update(std::any data) { - _sprite = std::any_cast(data); + const auto pic = std::any_cast(data); + _height = pic.height; + _width = pic.width; + _sprite = pic.data; Calculate(); } diff --git a/embedded/lib/Display/Components/SpriteBox.hpp b/embedded/lib/Display/Components/SpriteBox.hpp index 1471114..0aea01f 100644 --- a/embedded/lib/Display/Components/SpriteBox.hpp +++ b/embedded/lib/Display/Components/SpriteBox.hpp @@ -4,6 +4,11 @@ namespace Display { + struct Picture { + unsigned char* data; + uint16_t width; + uint16_t height; + }; class SpriteBox : public Box { diff --git a/embedded/lib/Display/Screen.cpp b/embedded/lib/Display/Screen.cpp index 244c979..4b5497d 100644 --- a/embedded/lib/Display/Screen.cpp +++ b/embedded/lib/Display/Screen.cpp @@ -3,13 +3,11 @@ #include // XBM Files -#include "Components/SpriteBox.hpp" -#include "../Pictures/clover.xbm" #include "../Pictures/failed.xbm" using namespace Display; -Screen::Screen() +Screen::Screen() : _booted(0), _bootFrame(0) { _screen = new U8G2_SSD1306_128X64_NONAME_F_HW_I2C(U8G2_R0, U8X8_PIN_NONE, SCL, SDA); _screen->begin(); @@ -38,7 +36,8 @@ void Screen::Setup(uint8_t *font) std::make_shared(TextBox("Connected to Wi-Fi !", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), std::make_shared(TextBox("IP address: ", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), std::make_shared(TextBox("addr", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))}); - loopWindow.Add(std::make_shared(SpriteBox(clover_bits, clover_height, clover_width, StyleWidth::CENTERED, StyleHeight::CENTERED))); + bootWindow.Add(std::make_shared(SpriteBox(clover_frames[0].data, clover_frames[0].height, clover_frames[0].width, StyleWidth::CENTERED, StyleHeight::CENTERED))); + loopWindow.Add(std::make_shared(TextBox("Welcome to Clover!", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))); } void Screen::connecting(uint8_t state) @@ -61,7 +60,7 @@ void Screen::connecting(uint8_t state) _screen->clearBuffer(); // Component - connectingWindow.Update(1, connectText); + connectingWindow.Update(1, String(connectText)); connectingWindow.Display(); // Displaying _screen->sendBuffer(); @@ -80,7 +79,7 @@ void Screen::connected(const char *ipaddress, uint8_t timing) { _screen->clearBuffer(); // Component - connectedWindow.Update(3, ipaddress); + connectedWindow.Update(3, String(ipaddress)); // Displaying connectedWindow.Display(); @@ -95,6 +94,16 @@ void Screen::connected(const char *ipaddress, uint8_t timing) _screen->sendBuffer(); } +void Screen::boot() +{ + _screen->clearBuffer(); + // Component + bootWindow.Display(); + _bootFrame++; + bootWindow.Update(0,clover_frames[(_bootFrame >= 10 ? 10 : _bootFrame)]); + _screen->sendBuffer(); +} + void Screen::loop() { _screen->clearBuffer(); @@ -107,4 +116,5 @@ void Screen::loop() uint16_t Screen::getHeight() { return _height; } uint16_t Screen::getWidth() { return _width; } U8G2_SSD1306_128X64_NONAME_F_HW_I2C &Screen::getScreen() { return *_screen; } -uint16_t Screen::getTextWidth(const char *str) { return _screen->getStrWidth(str); } \ No newline at end of file +uint16_t Screen::getTextWidth(const char *str) { return _screen->getStrWidth(str); } +bool Screen::isBooting() { return (_bootFrame<=20); } \ No newline at end of file diff --git a/embedded/lib/Display/Screen.hpp b/embedded/lib/Display/Screen.hpp index c7731cd..0fb39d1 100644 --- a/embedded/lib/Display/Screen.hpp +++ b/embedded/lib/Display/Screen.hpp @@ -5,9 +5,37 @@ #include "Components/Components.hpp" #include "Components/TextBox.hpp" +#include "Components/SpriteBox.hpp" + +// Frame for booting +#include "../Pictures/clover1.xbm" +#include "../Pictures/clover2.xbm" +#include "../Pictures/clover3.xbm" +#include "../Pictures/clover4.xbm" +#include "../Pictures/clover5.xbm" +#include "../Pictures/clover6.xbm" +#include "../Pictures/clover7.xbm" +#include "../Pictures/clover8.xbm" +#include "../Pictures/clover9.xbm" +#include "../Pictures/clover10.xbm" +#include "../Pictures/clover11.xbm" namespace Display { + constexpr Picture clover_frames[] = { + {clover1_bits, clover1_width, clover1_height}, + {clover2_bits, clover2_width, clover2_height}, + {clover3_bits, clover3_width, clover3_height}, + {clover4_bits, clover4_width, clover4_height}, + {clover5_bits, clover5_width, clover5_height}, + {clover6_bits, clover6_width, clover6_height}, + {clover7_bits, clover7_width, clover7_height}, + {clover8_bits, clover8_width, clover8_height}, + {clover9_bits, clover9_width, clover9_height}, + {clover10_bits, clover10_width, clover10_height}, + {clover11_bits, clover11_width, clover11_height}, + }; + class Screen { public: @@ -22,12 +50,14 @@ namespace Display void connecting(uint8_t state=0); void notConnected(); void connected(const char *ipaddress, uint8_t timing); + void boot(); void loop(); // Getters uint16_t getHeight(); uint16_t getWidth(); U8G2_SSD1306_128X64_NONAME_F_HW_I2C& getScreen(); uint16_t getTextWidth(const char * str); + bool isBooting(); private: // Singleton Screen(); @@ -41,12 +71,16 @@ namespace Display uint16_t _width; uint16_t _height; String _loading; + // Extern + uint8_t _bootFrame; + bool _booted; // Static Components TextBox headerSetup; Components connectingWindow; Components connectionfailedWindow; Components connectedWindow; + Components bootWindow; Components loopWindow; }; } diff --git a/embedded/lib/Pictures/clover1.xbm b/embedded/lib/Pictures/clover1.xbm new file mode 100644 index 0000000..07243b1 --- /dev/null +++ b/embedded/lib/Pictures/clover1.xbm @@ -0,0 +1,14 @@ +#define clover1_width 26 +#define clover1_height 32 +static unsigned char clover1_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, + 0x00, 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, + 0x00, 0xfc, 0x00, 0x00, 0x60, 0xfc, 0x18, 0x00, 0xe0, 0x79, 0x1e, 0x00, + 0xe0, 0x33, 0x1f, 0x00, 0xc0, 0x87, 0x0f, 0x00, 0xc0, 0x87, 0x0f, 0x00, + 0x80, 0xcf, 0x07, 0x00, 0x00, 0xcf, 0x03, 0x00, 0x00, 0x78, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/embedded/lib/Pictures/clover10.xbm b/embedded/lib/Pictures/clover10.xbm new file mode 100644 index 0000000..607ec59 --- /dev/null +++ b/embedded/lib/Pictures/clover10.xbm @@ -0,0 +1,14 @@ +#define clover10_width 26 +#define clover10_height 32 +static unsigned char clover10_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, + 0x00, 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, + 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x60, 0xfc, 0x18, 0x00, + 0xe0, 0x79, 0x1e, 0x00, 0xe0, 0x33, 0x1f, 0x00, 0xc0, 0x87, 0x0f, 0x00, + 0xc0, 0x87, 0x0f, 0x00, 0x80, 0xcf, 0x07, 0x00, 0x00, 0xcf, 0x03, 0x00, + 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x00, 0x00, 0x44, 0x54, 0xa5, 0x00, 0x44, 0x54, 0x6d, 0x00, + 0x44, 0x54, 0xa5, 0x00, 0x98, 0x89, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/embedded/lib/Pictures/clover11.xbm b/embedded/lib/Pictures/clover11.xbm new file mode 100644 index 0000000..3671396 --- /dev/null +++ b/embedded/lib/Pictures/clover11.xbm @@ -0,0 +1,14 @@ +#define clover11_width 26 +#define clover11_height 32 +static unsigned char clover11_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, + 0x00, 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, + 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x60, 0xfc, 0x18, 0x00, + 0xe0, 0x79, 0x1e, 0x00, 0xe0, 0x33, 0x1f, 0x00, 0xc0, 0x87, 0x0f, 0x00, + 0xc0, 0x87, 0x0f, 0x00, 0x80, 0xcf, 0x07, 0x00, 0x00, 0xcf, 0x03, 0x00, + 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x58, 0x48, 0x6d, 0x00, 0x44, 0x54, 0xa5, 0x00, 0x44, 0x54, 0x6d, 0x00, + 0x44, 0x54, 0xa5, 0x00, 0x98, 0x89, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/embedded/lib/Pictures/clover2.xbm b/embedded/lib/Pictures/clover2.xbm new file mode 100644 index 0000000..65cb462 --- /dev/null +++ b/embedded/lib/Pictures/clover2.xbm @@ -0,0 +1,14 @@ +#define clover2_width 26 +#define clover2_height 32 +static unsigned char clover2_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, + 0x00, 0x78, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, + 0x60, 0xfc, 0x00, 0x00, 0xe0, 0xfc, 0x1c, 0x00, 0xe0, 0x79, 0x1e, 0x00, + 0xe0, 0x03, 0x1f, 0x00, 0xc0, 0x87, 0x0f, 0x00, 0xc0, 0xcf, 0x0f, 0x00, + 0x80, 0xcf, 0x03, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/embedded/lib/Pictures/clover3.xbm b/embedded/lib/Pictures/clover3.xbm new file mode 100644 index 0000000..e340366 --- /dev/null +++ b/embedded/lib/Pictures/clover3.xbm @@ -0,0 +1,14 @@ +#define clover3_width 26 +#define clover3_height 32 +static unsigned char clover3_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, + 0x00, 0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, + 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, + 0xe0, 0xfc, 0x0c, 0x00, 0xe0, 0x79, 0x1e, 0x00, 0xe0, 0x03, 0x1f, 0x00, + 0xc0, 0x87, 0x1f, 0x00, 0x80, 0xcf, 0x07, 0x00, 0x00, 0xcf, 0x03, 0x00, + 0x00, 0xd8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/embedded/lib/Pictures/clover4.xbm b/embedded/lib/Pictures/clover4.xbm new file mode 100644 index 0000000..4777054 --- /dev/null +++ b/embedded/lib/Pictures/clover4.xbm @@ -0,0 +1,14 @@ +#define clover4_width 26 +#define clover4_height 32 +static unsigned char clover4_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, + 0x00, 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, + 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, + 0xc0, 0x78, 0x0e, 0x00, 0xe0, 0x01, 0x1f, 0x00, 0xe0, 0x83, 0x1f, 0x00, + 0xe0, 0xcf, 0x1f, 0x00, 0x80, 0xcf, 0x07, 0x00, 0x00, 0xce, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/embedded/lib/Pictures/clover5.xbm b/embedded/lib/Pictures/clover5.xbm new file mode 100644 index 0000000..e4c1351 --- /dev/null +++ b/embedded/lib/Pictures/clover5.xbm @@ -0,0 +1,14 @@ +#define clover5_width 26 +#define clover5_height 32 +static unsigned char clover5_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, + 0x00, 0x78, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, + 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, + 0xe0, 0x00, 0x0e, 0x00, 0xf0, 0x03, 0x1f, 0x00, 0xf0, 0x87, 0x1f, 0x00, + 0xe0, 0xcf, 0x0f, 0x00, 0x80, 0xcf, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/embedded/lib/Pictures/clover6.xbm b/embedded/lib/Pictures/clover6.xbm new file mode 100644 index 0000000..84e4383 --- /dev/null +++ b/embedded/lib/Pictures/clover6.xbm @@ -0,0 +1,14 @@ +#define clover6_width 26 +#define clover6_height 32 +static unsigned char clover6_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, + 0x00, 0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, + 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, + 0x00, 0xfc, 0x00, 0x00, 0xe0, 0x78, 0x0e, 0x00, 0xf0, 0x01, 0x1f, 0x00, + 0xf0, 0x83, 0x1f, 0x00, 0xe0, 0xc7, 0x0f, 0x00, 0xc0, 0xcf, 0x07, 0x00, + 0x00, 0xdf, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/embedded/lib/Pictures/clover7.xbm b/embedded/lib/Pictures/clover7.xbm new file mode 100644 index 0000000..ff0324d --- /dev/null +++ b/embedded/lib/Pictures/clover7.xbm @@ -0,0 +1,14 @@ +#define clover7_width 26 +#define clover7_height 32 +static unsigned char clover7_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, + 0x00, 0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, + 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, + 0x30, 0xfc, 0x18, 0x00, 0xf0, 0x30, 0x1e, 0x00, 0xf0, 0x01, 0x1f, 0x00, + 0xf0, 0x83, 0x0f, 0x00, 0xe0, 0xc7, 0x07, 0x00, 0xc0, 0xcf, 0x03, 0x00, + 0x00, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x10, 0x01, 0x00, 0x90, 0x89, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/embedded/lib/Pictures/clover8.xbm b/embedded/lib/Pictures/clover8.xbm new file mode 100644 index 0000000..4c66ade --- /dev/null +++ b/embedded/lib/Pictures/clover8.xbm @@ -0,0 +1,14 @@ +#define clover8_width 26 +#define clover8_height 32 +static unsigned char clover8_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, + 0x00, 0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, + 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, + 0x20, 0xfc, 0x18, 0x00, 0xe0, 0x30, 0x1e, 0x00, 0xe0, 0x03, 0x1f, 0x00, + 0xe0, 0x87, 0x0f, 0x00, 0xc0, 0xc7, 0x07, 0x00, 0x00, 0xcf, 0x03, 0x00, + 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, + 0x44, 0x54, 0xa5, 0x00, 0x98, 0x89, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/embedded/lib/Pictures/clover9.xbm b/embedded/lib/Pictures/clover9.xbm new file mode 100644 index 0000000..b7e5c38 --- /dev/null +++ b/embedded/lib/Pictures/clover9.xbm @@ -0,0 +1,14 @@ +#define clover9_width 26 +#define clover9_height 32 +static unsigned char clover9_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, + 0x00, 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, + 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, + 0xe0, 0xfc, 0x1c, 0x00, 0xe0, 0x33, 0x1f, 0x00, 0xc0, 0x87, 0x0f, 0x00, + 0xc0, 0x87, 0x0f, 0x00, 0x80, 0xcf, 0x07, 0x00, 0x00, 0xcf, 0x03, 0x00, + 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x44, 0x54, 0x6d, 0x00, + 0x44, 0x54, 0xa5, 0x00, 0x98, 0x89, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/embedded/lib/ServerHandler/ServerHandler.cpp b/embedded/lib/ServerHandler/ServerHandler.cpp index 8da17e4..64aad9a 100644 --- a/embedded/lib/ServerHandler/ServerHandler.cpp +++ b/embedded/lib/ServerHandler/ServerHandler.cpp @@ -44,6 +44,7 @@ void ServerHandler::loop() bool ServerHandler::showNext() { return (display_time >= MAX_TIME); } bool ServerHandler::isConnected() { return _connected; } +bool ServerHandler::showBoot() { return (display_time >= MAX_TIME); } void ServerHandler::handleRoot() { diff --git a/embedded/lib/ServerHandler/ServerHandler.hpp b/embedded/lib/ServerHandler/ServerHandler.hpp index 20a390b..068e755 100644 --- a/embedded/lib/ServerHandler/ServerHandler.hpp +++ b/embedded/lib/ServerHandler/ServerHandler.hpp @@ -23,6 +23,7 @@ public: // Return if the screen needs to be changed. bool showNext(); bool isConnected(); + bool showBoot(); private: // Singleton diff --git a/embedded/src/main.cpp b/embedded/src/main.cpp index 83b1a66..09121e3 100644 --- a/embedded/src/main.cpp +++ b/embedded/src/main.cpp @@ -28,15 +28,22 @@ void loop() auto& dataHandler = DataHandler::GetInstance(); auto& screen = Display::Screen::GetInstance(); - // If could not connect, show screen failure + // Could not connect, show screen failure if(!serverHandler.isConnected()) { screen.notConnected(); return; } + // Is booting + if(screen.isBooting() && serverHandler.showBoot()) + { + screen.boot(); + delay(166); + } + // If serverHandler finished showing ip. - if (serverHandler.showNext()) + if (!screen.isBooting()) screen.loop(); dataHandler.updateTemperatureData(random(1800, 2200) / 100.0); @@ -44,7 +51,7 @@ void loop() dataHandler.updateHumidityData(static_cast(std::any_cast(humidity.getValue()))); Serial.println(dataHandler.getJsonData()); // When showing IP, delay is faster. - delay(serverHandler.showNext() ? 1000 : 250); + delay(serverHandler.showNext() ? 0 : 250); serverHandler.loop(); } \ No newline at end of file From 0fe4c2ecee06ad5809996e92f77bb82bdd5caf8c Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Wed, 13 Dec 2023 18:47:35 +0100 Subject: [PATCH 21/23] Main: Loop function is more readable/understandable. Server: Added a specific function to show IP. Fixed some constexpr typo and initialisation warnings. --- embedded/lib/Display/Screen.cpp | 8 ++--- embedded/lib/Display/Screen.hpp | 3 +- embedded/lib/ServerHandler/ServerHandler.cpp | 12 +++---- embedded/lib/ServerHandler/ServerHandler.hpp | 3 +- embedded/src/main.cpp | 36 +++++++++++++------- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/embedded/lib/Display/Screen.cpp b/embedded/lib/Display/Screen.cpp index 4b5497d..a63594d 100644 --- a/embedded/lib/Display/Screen.cpp +++ b/embedded/lib/Display/Screen.cpp @@ -7,7 +7,7 @@ using namespace Display; -Screen::Screen() : _booted(0), _bootFrame(0) +Screen::Screen() : _bootFrame(0), _booted(0) { _screen = new U8G2_SSD1306_128X64_NONAME_F_HW_I2C(U8G2_R0, U8X8_PIN_NONE, SCL, SDA); _screen->begin(); @@ -36,7 +36,7 @@ void Screen::Setup(uint8_t *font) std::make_shared(TextBox("Connected to Wi-Fi !", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), std::make_shared(TextBox("IP address: ", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), std::make_shared(TextBox("addr", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))}); - bootWindow.Add(std::make_shared(SpriteBox(clover_frames[0].data, clover_frames[0].height, clover_frames[0].width, StyleWidth::CENTERED, StyleHeight::CENTERED))); + bootWindow.Add(std::make_shared(SpriteBox(CLOVER_FRAMES[0].data, CLOVER_FRAMES[0].height, CLOVER_FRAMES[0].width, StyleWidth::CENTERED, StyleHeight::CENTERED))); loopWindow.Add(std::make_shared(TextBox("Welcome to Clover!", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))); } @@ -100,7 +100,7 @@ void Screen::boot() // Component bootWindow.Display(); _bootFrame++; - bootWindow.Update(0,clover_frames[(_bootFrame >= 10 ? 10 : _bootFrame)]); + bootWindow.Update(0,CLOVER_FRAMES[(_bootFrame >= 10 ? 10 : _bootFrame)]); _screen->sendBuffer(); } @@ -117,4 +117,4 @@ uint16_t Screen::getHeight() { return _height; } uint16_t Screen::getWidth() { return _width; } U8G2_SSD1306_128X64_NONAME_F_HW_I2C &Screen::getScreen() { return *_screen; } uint16_t Screen::getTextWidth(const char *str) { return _screen->getStrWidth(str); } -bool Screen::isBooting() { return (_bootFrame<=20); } \ No newline at end of file +bool Screen::isBooting() { return (_bootFrame<=MAX_BOOT_FRAMES); } \ No newline at end of file diff --git a/embedded/lib/Display/Screen.hpp b/embedded/lib/Display/Screen.hpp index 0fb39d1..0794b3d 100644 --- a/embedded/lib/Display/Screen.hpp +++ b/embedded/lib/Display/Screen.hpp @@ -22,7 +22,7 @@ namespace Display { - constexpr Picture clover_frames[] = { + constexpr Picture CLOVER_FRAMES[] = { {clover1_bits, clover1_width, clover1_height}, {clover2_bits, clover2_width, clover2_height}, {clover3_bits, clover3_width, clover3_height}, @@ -35,6 +35,7 @@ namespace Display {clover10_bits, clover10_width, clover10_height}, {clover11_bits, clover11_width, clover11_height}, }; + constexpr uint8_t MAX_BOOT_FRAMES = 25; class Screen { diff --git a/embedded/lib/ServerHandler/ServerHandler.cpp b/embedded/lib/ServerHandler/ServerHandler.cpp index 64aad9a..1d9f55f 100644 --- a/embedded/lib/ServerHandler/ServerHandler.cpp +++ b/embedded/lib/ServerHandler/ServerHandler.cpp @@ -34,15 +34,15 @@ void ServerHandler::setup(const char *ssid, const char *password) void ServerHandler::loop() { - if (display_time < MAX_TIME) - { - Display::Screen::GetInstance().connected(WiFi.localIP().toString().c_str(), display_time); - display_time++; - } server.handleClient(); } -bool ServerHandler::showNext() { return (display_time >= MAX_TIME); } +void ServerHandler::showIp() +{ + Display::Screen::GetInstance().connected(WiFi.localIP().toString().c_str(), display_time); + display_time++; +} + bool ServerHandler::isConnected() { return _connected; } bool ServerHandler::showBoot() { return (display_time >= MAX_TIME); } diff --git a/embedded/lib/ServerHandler/ServerHandler.hpp b/embedded/lib/ServerHandler/ServerHandler.hpp index 068e755..f628550 100644 --- a/embedded/lib/ServerHandler/ServerHandler.hpp +++ b/embedded/lib/ServerHandler/ServerHandler.hpp @@ -19,9 +19,8 @@ public: } // Public functions void setup(const char* ssid, const char* password); + void showIp(); void loop(); - // Return if the screen needs to be changed. - bool showNext(); bool isConnected(); bool showBoot(); diff --git a/embedded/src/main.cpp b/embedded/src/main.cpp index 09121e3..c6ba53e 100644 --- a/embedded/src/main.cpp +++ b/embedded/src/main.cpp @@ -24,34 +24,46 @@ void setup() void loop() { + // Creating variables to access singletons auto& serverHandler = ServerHandler::GetInstance(); auto& dataHandler = DataHandler::GetInstance(); auto& screen = Display::Screen::GetInstance(); - // Could not connect, show screen failure + // Could not connect after setup: Showing screen failure if(!serverHandler.isConnected()) { screen.notConnected(); return; } - // Is booting + // Server showing IP + if(!serverHandler.showBoot()) + { + serverHandler.showIp(); + delay(250); + return; + } + + // When Screen can boot (isBooting) and Server finished showing IP (showBoot) if(screen.isBooting() && serverHandler.showBoot()) { screen.boot(); - delay(166); + delay(100); + return; } - // If serverHandler finished showing ip. - if (!screen.isBooting()) - screen.loop(); - - dataHandler.updateTemperatureData(random(1800, 2200) / 100.0); + // Data gathered from various sensors // 0 -> air(0), 0-300 -> dry(20), 300-700 -> humid (580), 700-950 -> water(940) - dataHandler.updateHumidityData(static_cast(std::any_cast(humidity.getValue()))); - Serial.println(dataHandler.getJsonData()); - // When showing IP, delay is faster. - delay(serverHandler.showNext() ? 0 : 250); + auto humidityData = static_cast(std::any_cast(humidity.getValue())); + auto temperatureData = random(300, 150) / 10.0; + // Updating the data handler + dataHandler.updateTemperatureData(temperatureData); + dataHandler.updateHumidityData(humidityData); + // (debug) Printing to serial the data + Serial.println(dataHandler.getJsonData()); + // Screen showing + screen.loop(); + // Server sending data serverHandler.loop(); } \ No newline at end of file From 36fc6b40fb2fd33893b672f78c3d0343edbabbbe Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Wed, 13 Dec 2023 19:20:16 +0100 Subject: [PATCH 22/23] DataHandler: Rearanged data acquisition to handle more sensors. Screen: Showing example screen. --- embedded/lib/DataHandler/DataHandler.cpp | 17 ++++++++--------- embedded/lib/DataHandler/DataHandler.hpp | 16 ++++++++++++---- embedded/lib/Display/Screen.cpp | 12 ++++++++++-- embedded/lib/Display/Screen.hpp | 2 +- embedded/src/main.cpp | 14 +++++++++----- 5 files changed, 40 insertions(+), 21 deletions(-) diff --git a/embedded/lib/DataHandler/DataHandler.cpp b/embedded/lib/DataHandler/DataHandler.cpp index 8c6a5b2..46bd849 100644 --- a/embedded/lib/DataHandler/DataHandler.cpp +++ b/embedded/lib/DataHandler/DataHandler.cpp @@ -4,13 +4,10 @@ DataHandler::DataHandler() {} DataHandler::~DataHandler() {} -void DataHandler::updateTemperatureData(float temp) { - temperature = temp; -} - -void DataHandler::updateHumidityData(float hum) { - humidity = hum; -} +void DataHandler::updatePlantHumidityData(float humidity) { plantHumidity = humidity; } +void DataHandler::updateAirTemperatureData(float temperature) { airTemperature = temperature; } +void DataHandler::updateAirHumidityData(float humidity) { airHumidity = humidity; } +void DataHandler::updateLightData(float light) { this->light = light; } String DataHandler::getJsonData() { return buildJson(); @@ -18,8 +15,10 @@ String DataHandler::getJsonData() { String DataHandler::buildJson() { StaticJsonDocument<200> document; // Taille = 200 - document["temperature"] = temperature; - document["humidity"] = humidity; + document["plantHumidity"] = plantHumidity; + document["airTemperature"] = airTemperature; + document["airHumidity"] = airHumidity; + document["light"] = light; String jsonFormattedData; serializeJson(document, jsonFormattedData); diff --git a/embedded/lib/DataHandler/DataHandler.hpp b/embedded/lib/DataHandler/DataHandler.hpp index 5335e3a..be89006 100644 --- a/embedded/lib/DataHandler/DataHandler.hpp +++ b/embedded/lib/DataHandler/DataHandler.hpp @@ -13,8 +13,10 @@ public: } // Public functions String getJsonData(); - void updateTemperatureData(float temperature); - void updateHumidityData(float humidity); + void updatePlantHumidityData(float humidity); + void updateAirTemperatureData(float temperature); + void updateAirHumidityData(float humidity); + void updateLightData(float light); private: // Singleton @@ -22,8 +24,14 @@ private: ~DataHandler(); DataHandler(const DataHandler&) = delete; DataHandler& operator=(const DataHandler&) = delete; - float temperature; - float humidity; + + // Variables + float plantHumidity; + float airTemperature; + float airHumidity; + float light; + + // Fonctions String buildJson(); }; diff --git a/embedded/lib/Display/Screen.cpp b/embedded/lib/Display/Screen.cpp index a63594d..94c39e4 100644 --- a/embedded/lib/Display/Screen.cpp +++ b/embedded/lib/Display/Screen.cpp @@ -37,7 +37,10 @@ void Screen::Setup(uint8_t *font) std::make_shared(TextBox("IP address: ", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), std::make_shared(TextBox("addr", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))}); bootWindow.Add(std::make_shared(SpriteBox(CLOVER_FRAMES[0].data, CLOVER_FRAMES[0].height, CLOVER_FRAMES[0].width, StyleWidth::CENTERED, StyleHeight::CENTERED))); - loopWindow.Add(std::make_shared(TextBox("Welcome to Clover!", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))); + loopWindow.Add({std::make_shared(TextBox("plantHumidity", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), + std::make_shared(TextBox("airTemperature", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), + std::make_shared(TextBox("airHumidity", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), + std::make_shared(TextBox("light", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))}); } void Screen::connecting(uint8_t state) @@ -104,9 +107,14 @@ void Screen::boot() _screen->sendBuffer(); } -void Screen::loop() +void Screen::loop(const float plantHumidity, const float airTemperature, const float airHumidity, const float light) { _screen->clearBuffer(); + // Updating with values + loopWindow.Update(0,String("Humidity: ")+String(plantHumidity,2)+String("%")); + loopWindow.Update(1,String("Air Temperature: ")+String(airTemperature,2)+String("°C")); + loopWindow.Update(2,String("Air Humidity: ")+String(airHumidity,2)+String("%")); + loopWindow.Update(3,String("Light: ")+String(light,2)+String("%")); // Component loopWindow.Display(); // Displaying diff --git a/embedded/lib/Display/Screen.hpp b/embedded/lib/Display/Screen.hpp index 0794b3d..ad45663 100644 --- a/embedded/lib/Display/Screen.hpp +++ b/embedded/lib/Display/Screen.hpp @@ -52,7 +52,7 @@ namespace Display void notConnected(); void connected(const char *ipaddress, uint8_t timing); void boot(); - void loop(); + void loop(const float plantHumidity, const float airTemperature, const float airHumidity, const float light); // Getters uint16_t getHeight(); uint16_t getWidth(); diff --git a/embedded/src/main.cpp b/embedded/src/main.cpp index c6ba53e..1a65f2b 100644 --- a/embedded/src/main.cpp +++ b/embedded/src/main.cpp @@ -54,16 +54,20 @@ void loop() // Data gathered from various sensors // 0 -> air(0), 0-300 -> dry(20), 300-700 -> humid (580), 700-950 -> water(940) - auto humidityData = static_cast(std::any_cast(humidity.getValue())); - auto temperatureData = random(300, 150) / 10.0; + auto plantHumidityData = static_cast(std::any_cast(humidity.getValue())); + auto airTemperatureData = random(150, 300) / 10.0; + auto airHumidityData = random(0, 1000) / 10.0; + auto lightData = random(0, 1000) / 10.0; // Updating the data handler - dataHandler.updateTemperatureData(temperatureData); - dataHandler.updateHumidityData(humidityData); + dataHandler.updatePlantHumidityData(plantHumidityData); + dataHandler.updateAirTemperatureData(airTemperatureData); + dataHandler.updateAirHumidityData(airHumidityData); + dataHandler.updateLightData(lightData); // (debug) Printing to serial the data Serial.println(dataHandler.getJsonData()); // Screen showing - screen.loop(); + screen.loop(plantHumidityData,airTemperatureData,airHumidityData,lightData); // Server sending data serverHandler.loop(); } \ No newline at end of file From d96c5a670e1ca6880a5a14bcf54cfde5d6a6aa39 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Thu, 14 Dec 2023 10:14:56 +0100 Subject: [PATCH 23/23] Screen: Added icons for sensors. Added offset control for all Boxes. Created window for icons. Stylized main loop. --- embedded/lib/Display/Components/Box.hpp | 10 ++++- embedded/lib/Display/Components/SpriteBox.cpp | 8 ++-- embedded/lib/Display/Components/TextBox.cpp | 8 ++-- embedded/lib/Display/Screen.cpp | 40 ++++++++++++++----- embedded/lib/Display/Screen.hpp | 4 +- embedded/lib/Pictures/air_humidity.xbm | 6 +++ embedded/lib/Pictures/humidity.xbm | 6 +++ embedded/lib/Pictures/luminosity.xbm | 6 +++ embedded/lib/Pictures/thermometer.xbm | 6 +++ 9 files changed, 77 insertions(+), 17 deletions(-) create mode 100644 embedded/lib/Pictures/air_humidity.xbm create mode 100644 embedded/lib/Pictures/humidity.xbm create mode 100644 embedded/lib/Pictures/luminosity.xbm create mode 100644 embedded/lib/Pictures/thermometer.xbm diff --git a/embedded/lib/Display/Components/Box.hpp b/embedded/lib/Display/Components/Box.hpp index 5b7b426..ffc029d 100644 --- a/embedded/lib/Display/Components/Box.hpp +++ b/embedded/lib/Display/Components/Box.hpp @@ -44,7 +44,7 @@ namespace Display * @brief Construct a new Box object, can be ignored. */ Box(StyleHeight sh, u8g2_uint_t h_padding, uint16_t height) - : _styleHeight(sh), _paddingHeight(h_padding), _height(height) {}; + : _styleHeight(sh), _paddingHeight(h_padding), _height(height), _xOffset(0), _yOffset(0){}; /** * @brief Used to display the element on the screen. @@ -81,10 +81,18 @@ namespace Display virtual uint16_t getHeight() { return _height; } + virtual void SetOffset(uint16_t xOffset, uint16_t yOffset=0) + { + _xOffset = xOffset; + _yOffset = yOffset; + } + protected: StyleHeight _styleHeight; u8g2_uint_t _paddingHeight; uint16_t _height; + uint16_t _xOffset; + uint16_t _yOffset; }; } diff --git a/embedded/lib/Display/Components/SpriteBox.cpp b/embedded/lib/Display/Components/SpriteBox.cpp index ad77b37..94c2400 100644 --- a/embedded/lib/Display/Components/SpriteBox.cpp +++ b/embedded/lib/Display/Components/SpriteBox.cpp @@ -45,17 +45,19 @@ void SpriteBox::Calculate() void SpriteBox::Display(u8g2_uint_t size, u8g2_uint_t size_pos) { const auto centeredOffset = (Screen::GetInstance().getHeight() - size); + auto x = _x + this->_xOffset; + auto y = size_pos + this->_yOffset; switch(this->_styleHeight) { case StyleHeight::CENTERED: case StyleHeight::FORCE_CENTERED: // idk must be the size of all the above - Screen::GetInstance().getScreen().drawXBM(_x, static_cast((centeredOffset / 2)) + size_pos,_width,_height,_sprite); + Screen::GetInstance().getScreen().drawXBM(x, static_cast((centeredOffset / 2)) + y,_width,_height,_sprite); break; case StyleHeight::BOTTOM: - Screen::GetInstance().getScreen().drawXBM(_x, centeredOffset + size_pos,_width,_height,_sprite); + Screen::GetInstance().getScreen().drawXBM(x, centeredOffset + y,_width,_height,_sprite); break; default: - Screen::GetInstance().getScreen().drawXBM(_x, size_pos,_width,_height,_sprite); + Screen::GetInstance().getScreen().drawXBM(x, y,_width,_height,_sprite); } } \ No newline at end of file diff --git a/embedded/lib/Display/Components/TextBox.cpp b/embedded/lib/Display/Components/TextBox.cpp index 9494fd1..b0eddfe 100644 --- a/embedded/lib/Display/Components/TextBox.cpp +++ b/embedded/lib/Display/Components/TextBox.cpp @@ -43,16 +43,18 @@ void TextBox::Calculate() void TextBox::Display(u8g2_uint_t size, u8g2_uint_t size_pos) { const auto centeredOffset = (Screen::GetInstance().getHeight() - size); + const auto x = _paddingWidth + _x + this->_xOffset; + const auto y = size_pos + _height + this->_yOffset; switch (this->_styleHeight) { case StyleHeight::CENTERED: case StyleHeight::FORCE_CENTERED: - Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, static_cast((centeredOffset / 2)) + size_pos + _height, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); + Screen::GetInstance().getScreen().drawButtonUTF8(x, static_cast((centeredOffset / 2)) + y, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); break; case StyleHeight::BOTTOM: - Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, centeredOffset + size_pos + _height, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); + Screen::GetInstance().getScreen().drawButtonUTF8(x, centeredOffset + y, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); break; default: - Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, size_pos + _height, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); + Screen::GetInstance().getScreen().drawButtonUTF8(x, y, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); } } \ No newline at end of file diff --git a/embedded/lib/Display/Screen.cpp b/embedded/lib/Display/Screen.cpp index 94c39e4..22af48d 100644 --- a/embedded/lib/Display/Screen.cpp +++ b/embedded/lib/Display/Screen.cpp @@ -4,6 +4,9 @@ // XBM Files #include "../Pictures/failed.xbm" +#include "../Pictures/humidity.xbm" +#include "../Pictures/thermometer.xbm" +#include "../Pictures/air_humidity.xbm" using namespace Display; @@ -25,7 +28,23 @@ void Screen::Setup(uint8_t *font) _font = font; _screen->setFont(_font); - headerSetup = TextBox("Clover Setup", StyleWidth::LEFT, StyleHeight::TOP, U8G2_BTN_INV, 2, 5, true); + // Creating Boxes + auto headerSetup = TextBox("Clover Setup", StyleWidth::LEFT, StyleHeight::TOP, U8G2_BTN_INV, 2, 5, true); + auto plantHumidity = TextBox("plantHumidity", StyleWidth::LEFT, StyleHeight::TOP, U8G2_BTN_BW0, 0, 0); + auto airTemperature = TextBox("airTemperature", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 0); + auto airHumidity = TextBox("airHumidity", StyleWidth::LEFT, StyleHeight::BOTTOM, U8G2_BTN_BW0, 0, 6); + auto humidityPicture = SpriteBox(humidity_bits,humidity_width,humidity_height,StyleWidth::LEFT,StyleHeight::CENTERED); + auto thermometerPicture = SpriteBox(thermometer_bits,thermometer_width,thermometer_height,StyleWidth::LEFT,StyleHeight::CENTERED); + auto airHumidityPicture = SpriteBox(air_humidity_bits,air_humidity_width,air_humidity_height,StyleWidth::LEFT,StyleHeight::CENTERED); + + // Config Boxes + plantHumidity.SetOffset(OFFSET_TEXT,12); + airTemperature.SetOffset(OFFSET_TEXT); + airHumidity.SetOffset(OFFSET_TEXT); + humidityPicture.SetOffset(OFFSET_ICONS); + thermometerPicture.SetOffset(OFFSET_ICONS); + airHumidityPicture.SetOffset(OFFSET_ICONS); + // Static Components connectingWindow.Add({std::make_shared(headerSetup), std::make_shared(TextBox("connect", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0))}); @@ -37,10 +56,12 @@ void Screen::Setup(uint8_t *font) std::make_shared(TextBox("IP address: ", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), std::make_shared(TextBox("addr", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))}); bootWindow.Add(std::make_shared(SpriteBox(CLOVER_FRAMES[0].data, CLOVER_FRAMES[0].height, CLOVER_FRAMES[0].width, StyleWidth::CENTERED, StyleHeight::CENTERED))); - loopWindow.Add({std::make_shared(TextBox("plantHumidity", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), - std::make_shared(TextBox("airTemperature", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), - std::make_shared(TextBox("airHumidity", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), - std::make_shared(TextBox("light", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))}); + loopWindow.Add({std::make_shared(plantHumidity), + std::make_shared(airTemperature), + std::make_shared(airHumidity)}); + iconWindow.Add({std::make_shared(humidityPicture), + std::make_shared(thermometerPicture), + std::make_shared(airHumidityPicture)}); } void Screen::connecting(uint8_t state) @@ -111,12 +132,13 @@ void Screen::loop(const float plantHumidity, const float airTemperature, const f { _screen->clearBuffer(); // Updating with values - loopWindow.Update(0,String("Humidity: ")+String(plantHumidity,2)+String("%")); - loopWindow.Update(1,String("Air Temperature: ")+String(airTemperature,2)+String("°C")); - loopWindow.Update(2,String("Air Humidity: ")+String(airHumidity,2)+String("%")); - loopWindow.Update(3,String("Light: ")+String(light,2)+String("%")); + loopWindow.Update(0,String("Hum: ")+String(plantHumidity,1)+String("%")); + loopWindow.Update(1,String("Tem: ")+String(airTemperature,1)+String("°C")); + loopWindow.Update(2,String("Hum: ")+String(airHumidity,1)+String("%")); + //loopWindow.Update(3,String("Light: ")+String(light,1)+String("%")); // Component loopWindow.Display(); + iconWindow.Display(); // Displaying _screen->sendBuffer(); } diff --git a/embedded/lib/Display/Screen.hpp b/embedded/lib/Display/Screen.hpp index ad45663..c92c9c5 100644 --- a/embedded/lib/Display/Screen.hpp +++ b/embedded/lib/Display/Screen.hpp @@ -36,6 +36,8 @@ namespace Display {clover11_bits, clover11_width, clover11_height}, }; constexpr uint8_t MAX_BOOT_FRAMES = 25; + constexpr uint8_t OFFSET_ICONS = 55; + constexpr uint8_t OFFSET_TEXT = 75; class Screen { @@ -77,12 +79,12 @@ namespace Display bool _booted; // Static Components - TextBox headerSetup; Components connectingWindow; Components connectionfailedWindow; Components connectedWindow; Components bootWindow; Components loopWindow; + Components iconWindow; }; } diff --git a/embedded/lib/Pictures/air_humidity.xbm b/embedded/lib/Pictures/air_humidity.xbm new file mode 100644 index 0000000..1e05f61 --- /dev/null +++ b/embedded/lib/Pictures/air_humidity.xbm @@ -0,0 +1,6 @@ +#define air_humidity_width 16 +#define air_humidity_height 16 +static unsigned char air_humidity_bits[] = { + 0x60, 0x00, 0x90, 0x00, 0x18, 0x01, 0x24, 0x02, 0x42, 0x0a, 0x42, 0x0a, + 0x04, 0x19, 0xf8, 0x3c, 0x00, 0x3e, 0x00, 0x7f, 0xe0, 0x7f, 0xe0, 0x7f, + 0xc0, 0x3f, 0x80, 0x1f, 0x00, 0x0f, 0x00, 0x00 }; diff --git a/embedded/lib/Pictures/humidity.xbm b/embedded/lib/Pictures/humidity.xbm new file mode 100644 index 0000000..1b8eed4 --- /dev/null +++ b/embedded/lib/Pictures/humidity.xbm @@ -0,0 +1,6 @@ +#define humidity_width 16 +#define humidity_height 16 +static unsigned char humidity_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x80, 0x01, 0x40, 0x03, 0x40, 0x03, + 0xa0, 0x07, 0xd0, 0x0f, 0xf0, 0x0f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, + 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x00, 0x00 }; diff --git a/embedded/lib/Pictures/luminosity.xbm b/embedded/lib/Pictures/luminosity.xbm new file mode 100644 index 0000000..8894479 --- /dev/null +++ b/embedded/lib/Pictures/luminosity.xbm @@ -0,0 +1,6 @@ +#define luminosity_width 16 +#define luminosity_height 16 +static unsigned char luminosity_bits[] = { + 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, 0x18, 0x18, 0xc8, 0x13, 0xe0, 0x07, + 0xf4, 0x2f, 0xf6, 0x6f, 0xf6, 0x6f, 0xf4, 0x2f, 0xe0, 0x07, 0xc8, 0x13, + 0x18, 0x18, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00 }; diff --git a/embedded/lib/Pictures/thermometer.xbm b/embedded/lib/Pictures/thermometer.xbm new file mode 100644 index 0000000..2576f17 --- /dev/null +++ b/embedded/lib/Pictures/thermometer.xbm @@ -0,0 +1,6 @@ +#define thermometer_width 16 +#define thermometer_height 16 +static unsigned char thermometer_bits[] = { + 0x00, 0x00, 0x80, 0x01, 0x40, 0x02, 0xc0, 0x02, 0x40, 0x02, 0xc0, 0x02, + 0x40, 0x02, 0xc0, 0x02, 0x40, 0x02, 0x20, 0x04, 0x10, 0x08, 0xf0, 0x0f, + 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x00, 0x00 };