From 1929ec4eac15a6bf2c1dc61706ae543d4003fa31 Mon Sep 17 00:00:00 2001 From: NachtRaveVL Date: Sat, 4 Mar 2023 21:03:41 -0800 Subject: [PATCH] UI abstraction cleanup --- README.md | 8 ++++---- examples/FullSystem/FullSystem.ino | 8 ++++---- examples/VerticalNFT/VerticalNFT.ino | 10 ++++------ src/HydroInterfaces.h | 4 ++-- src/HydroUtils.h | 2 +- src/HydroUtils.hpp | 2 +- src/Hydruino.h | 10 +++++----- src/full/HydruinoUI.cpp | 10 +--------- src/full/HydruinoUI.h | 20 ++++++++++++-------- src/min/HydruinoUI.cpp | 10 +--------- src/min/HydruinoUI.h | 20 ++++++++++++-------- src/shared/HydruinoUI.cpp | 15 +++++++++++++++ src/shared/HydruinoUI.h | 21 +++++++++++++++++++++ 13 files changed, 83 insertions(+), 57 deletions(-) create mode 100644 src/shared/HydruinoUI.cpp create mode 100644 src/shared/HydruinoUI.h diff --git a/README.md b/README.md index be6a0d9..2e47356 100644 --- a/README.md +++ b/README.md @@ -356,7 +356,7 @@ Included below is the default system setup defines of the Vertical NFT example ( #define SETUP_SD_CARD_SPI_CS -1 // SD card CS pin, else -1 #define SETUP_SD_CARD_SPI_SPEED F_SPD // SD card SPI speed, in Hz (ignored on Teensy) #define SETUP_LCD_I2C_ADDR 0b000 // LCD i2c address -#define SETUP_CTRL_INPUT_PINS {(pintype_t)-1} // Control input pin ribbon, else {-1} +#define SETUP_CTRL_INPUT_PINS {(pintype_t)-1} // Control input pins, else {-1} #define SETUP_I2C_WIRE Wire // I2C wire class instance #define SETUP_I2C_SPEED 400000U // I2C speed, in Hz #define SETUP_ESP_I2C_SDA SDA // I2C SDA pin, if on ESP @@ -391,9 +391,9 @@ Included below is the default system setup defines of the Vertical NFT example ( #define SETUP_SYS_NAME "Hydruino" // System name #define SETUP_SYS_TIMEZONE +0 // System timezone offset #define SETUP_SYS_LOGLEVEL All // System log level filter (All, Warnings, Errors, None) -#define SETUP_SYS_STATIC_LAT DBL_UNDEF // System static latitude (if not using GPS, else DBL_UNDEF), in degrees -#define SETUP_SYS_STATIC_LONG DBL_UNDEF // System static longitude (if not using GPS, else DBL_UNDEF), in minutes -#define SETUP_SYS_STATIC_ALT DBL_UNDEF // System static altitude (if not using GPS, else DBL_UNDEF), in meters above sea level (msl) +#define SETUP_SYS_STATIC_LAT DBL_UNDEF // System static latitude (if not using GPS/UI, else DBL_UNDEF), in degrees +#define SETUP_SYS_STATIC_LONG DBL_UNDEF // System static longitude (if not using GPS/UI, else DBL_UNDEF), in minutes +#define SETUP_SYS_STATIC_ALT DBL_UNDEF // System static altitude (if not using GPS/UI, else DBL_UNDEF), in meters above sea level (msl) // System Saves Settings (note: only one primary and one fallback mechanism may be enabled at a time) #define SETUP_SAVES_CONFIG_FILE "hydruino.cfg" // System config file name for system saves diff --git a/examples/FullSystem/FullSystem.ino b/examples/FullSystem/FullSystem.ino index a2f5244..836cb56 100644 --- a/examples/FullSystem/FullSystem.ino +++ b/examples/FullSystem/FullSystem.ino @@ -29,7 +29,7 @@ SoftwareSerial SWSerial(RX, TX); // Replace with Rx/Tx pi #define SETUP_SD_CARD_SPI_CS -1 // SD card CS pin, else -1 #define SETUP_SD_CARD_SPI_SPEED F_SPD // SD card SPI speed, in Hz (ignored on Teensy) #define SETUP_LCD_I2C_ADDR 0b000 // LCD i2c address -#define SETUP_CTRL_INPUT_PINS {(pintype_t)-1} // Control input pin ribbon, else {-1} +#define SETUP_CTRL_INPUT_PINS {(pintype_t)-1} // Control input pins, else {-1} #define SETUP_I2C_WIRE Wire // I2C wire class instance #define SETUP_I2C_SPEED 400000U // I2C speed, in Hz #define SETUP_ESP_I2C_SDA SDA // I2C SDA pin, if on ESP @@ -54,9 +54,9 @@ SoftwareSerial SWSerial(RX, TX); // Replace with Rx/Tx pi #define SETUP_GPS_I2C_ADDR 0b000 // GPS i2c address, if using i2c #define SETUP_GPS_SPI SPI // GPS SPI class instance, if using spi #define SETUP_GPS_SPI_CS SS // GPS CS pin, if using spi -#define SETUP_SYS_STATIC_LAT DBL_UNDEF // System static latitude (if not using GPS, else DBL_UNDEF), in degrees -#define SETUP_SYS_STATIC_LONG DBL_UNDEF // System static longitude (if not using GPS, else DBL_UNDEF), in minutes -#define SETUP_SYS_STATIC_ALT DBL_UNDEF // System static altitude (if not using GPS, else DBL_UNDEF), in meters above sea level (msl) +#define SETUP_SYS_STATIC_LAT DBL_UNDEF // System static latitude (if not using GPS/UI, else DBL_UNDEF), in degrees +#define SETUP_SYS_STATIC_LONG DBL_UNDEF // System static longitude (if not using GPS/UI, else DBL_UNDEF), in minutes +#define SETUP_SYS_STATIC_ALT DBL_UNDEF // System static altitude (if not using GPS/UI, else DBL_UNDEF), in meters above sea level (msl) // System Settings #define SETUP_SYSTEM_MODE Recycling // System run mode (Recycling, DrainToWaste) diff --git a/examples/VerticalNFT/VerticalNFT.ino b/examples/VerticalNFT/VerticalNFT.ino index fb49e60..2cc55eb 100644 --- a/examples/VerticalNFT/VerticalNFT.ino +++ b/examples/VerticalNFT/VerticalNFT.ino @@ -22,7 +22,7 @@ SoftwareSerial SWSerial(RX, TX); // Replace with Rx/Tx pi #define SETUP_SD_CARD_SPI_CS -1 // SD card CS pin, else -1 #define SETUP_SD_CARD_SPI_SPEED F_SPD // SD card SPI speed, in Hz (ignored on Teensy) #define SETUP_LCD_I2C_ADDR 0b000 // LCD i2c address -#define SETUP_CTRL_INPUT_PINS {(pintype_t)-1} // Control input pin ribbon, else {-1} +#define SETUP_CTRL_INPUT_PINS {(pintype_t)-1} // Control input pins, else {-1} #define SETUP_I2C_WIRE Wire // I2C wire class instance #define SETUP_I2C_SPEED 400000U // I2C speed, in Hz #define SETUP_ESP_I2C_SDA SDA // I2C SDA pin, if on ESP @@ -57,9 +57,9 @@ SoftwareSerial SWSerial(RX, TX); // Replace with Rx/Tx pi #define SETUP_SYS_NAME "Hydruino" // System name #define SETUP_SYS_TIMEZONE +0 // System timezone offset #define SETUP_SYS_LOGLEVEL All // System log level filter (All, Warnings, Errors, None) -#define SETUP_SYS_STATIC_LAT DBL_UNDEF // System static latitude (if not using GPS, else DBL_UNDEF), in degrees -#define SETUP_SYS_STATIC_LONG DBL_UNDEF // System static longitude (if not using GPS, else DBL_UNDEF), in minutes -#define SETUP_SYS_STATIC_ALT DBL_UNDEF // System static altitude (if not using GPS, else DBL_UNDEF), in meters above sea level (msl) +#define SETUP_SYS_STATIC_LAT DBL_UNDEF // System static latitude (if not using GPS/UI, else DBL_UNDEF), in degrees +#define SETUP_SYS_STATIC_LONG DBL_UNDEF // System static longitude (if not using GPS/UI, else DBL_UNDEF), in minutes +#define SETUP_SYS_STATIC_ALT DBL_UNDEF // System static altitude (if not using GPS/UI, else DBL_UNDEF), in meters above sea level (msl) // System Saves Settings (note: only one primary and one fallback mechanism may be enabled at a time) #define SETUP_SAVES_CONFIG_FILE "hydruino.cfg" // System config file name for system saves @@ -173,10 +173,8 @@ MQTTClient mqttClient; #if defined(HYDRO_USE_GUI) && SETUP_DISPLAY_OUT_MODE != Disabled #if SETUP_SYS_UI_MODE == Minimal #include "min/HydruinoUI.h" -typedef HydruinoMinUI HydruinoUI; #elif SETUP_SYS_UI_MODE == Full #include "full/HydruinoUI.h" -typedef HydruinoFullUI HydruinoUI; #endif #endif diff --git a/src/HydroInterfaces.h b/src/HydroInterfaces.h index bca96fa..62c33c9 100644 --- a/src/HydroInterfaces.h +++ b/src/HydroInterfaces.h @@ -9,7 +9,7 @@ struct HydroJSONSerializableInterface; class HydroObjInterface; -class HydruinoUIInterface; +class HydoUIInterface; class HydroRTCInterface; struct HydroDigitalInputPinInterface; @@ -94,7 +94,7 @@ class HydroObjInterface { }; // UI Interface -class HydruinoUIInterface { +class HydoUIInterface { public: virtual bool begin() = 0; diff --git a/src/HydroUtils.h b/src/HydroUtils.h index 07a475f..99131f1 100644 --- a/src/HydroUtils.h +++ b/src/HydroUtils.h @@ -146,7 +146,7 @@ inline HydroLogger *getLogger(); inline HydroPublisher *getPublisher(); #ifdef HYDRO_USE_GUI // Returns the active UI instance. Not guaranteed to be non-null. -inline HydruinoUIInterface *getUI(); +inline HydoUIInterface *getUI(); #endif // Publishes latest data from sensor to Publisher output. diff --git a/src/HydroUtils.hpp b/src/HydroUtils.hpp index dc83ab3..ca0e067 100644 --- a/src/HydroUtils.hpp +++ b/src/HydroUtils.hpp @@ -311,7 +311,7 @@ inline HydroPublisher *getPublisher() #ifdef HYDRO_USE_GUI -inline HydruinoUIInterface *getUI() +inline HydoUIInterface *getUI() { return Hydruino::_activeInstance ? Hydruino::_activeInstance->_activeUIInstance : nullptr; } diff --git a/src/Hydruino.h b/src/Hydruino.h index 1befb40..4540c00 100644 --- a/src/Hydruino.h +++ b/src/Hydruino.h @@ -339,10 +339,10 @@ class Hydruino : public HydroFactory, public HydroAdditives, public HydroCalibra #ifdef HYDRO_USE_GUI // Enables UI to run with passed instance. - // Minimal UI only allows the user to edit existing objects, not create nor delete them. - // Full UI allows the user to add/remove system objects, customize features, change settings, etc. + // Minimal/RO UI only allows the user to edit existing objects, not create nor delete them. + // Full/RW UI allows the user to add/remove system objects, customize features, change settings, etc. // Note: Be sure to manually include the appropriate UI system header file (e.g. #include "min/HydruinoUI.h") in Arduino sketch. - inline bool enableUI(HydruinoUIInterface *ui) { _activeUIInstance = ui; return ui->begin(); } + inline bool enableUI(HydoUIInterface *ui) { _activeUIInstance = ui; return ui->begin(); } #endif // Mutators. @@ -485,7 +485,7 @@ class Hydruino : public HydroFactory, public HydroAdditives, public HydroCalibra protected: static Hydruino *_activeInstance; // Current active instance (set after init, weak) #ifdef HYDRO_USE_GUI - HydruinoUIInterface *_activeUIInstance; // Current active UI instance (owned) + HydoUIInterface *_activeUIInstance; // Current active UI instance (owned) #endif HydroSystemData *_systemData; // System data (owned, saved to storage) @@ -568,7 +568,7 @@ class Hydruino : public HydroFactory, public HydroAdditives, public HydroCalibra friend HydroLogger *::getLogger(); friend HydroPublisher *::getPublisher(); #ifdef HYDRO_USE_GUI - friend HydruinoUIInterface *::getUI(); + friend HydoUIInterface *::getUI(); #endif friend class HydroCalibrations; friend class HydroCropsLibrary; diff --git a/src/full/HydruinoUI.cpp b/src/full/HydruinoUI.cpp index 0d15b05..05b07d2 100644 --- a/src/full/HydruinoUI.cpp +++ b/src/full/HydruinoUI.cpp @@ -1,15 +1,7 @@ /* Hydruino: Simple automation controller for hydroponic grow systems. Copyright (C) 2022-2023 NachtRaveVL - Hydruino Full UI + Hydruino Full/RW UI */ #include "Hydruino.h" #include "HydruinoUI.h" - -bool HydruinoFullUI::begin() -{ - return false; -} - -void HydruinoFullUI::setNeedsLayout() -{ } diff --git a/src/full/HydruinoUI.h b/src/full/HydruinoUI.h index 59fe4b3..efebbb4 100644 --- a/src/full/HydruinoUI.h +++ b/src/full/HydruinoUI.h @@ -1,17 +1,21 @@ /* Hydruino: Simple automation controller for hydroponic grow systems. Copyright (C) 2022-2023 NachtRaveVL - Hydruino Full UI + Hydruino Full/RW UI */ +#include +#ifdef HYDRO_USE_GUI +#ifndef HydroUI_H +#define HydroUI_H + class HydruinoFullUI; +typedef HydruinoFullUI HydruinoUI; -#include "Hydruino.h" +#include "..\shared\HydruinoUI.h" -class HydruinoFullUI : HydruinoUIInterface { +class HydruinoFullUI : public HydruinoBaseUI { public: - virtual bool begin() override; - - virtual void setNeedsLayout() override; - -protected: }; + +#endif // /ifndef HydroUI_H +#endif diff --git a/src/min/HydruinoUI.cpp b/src/min/HydruinoUI.cpp index 8806277..63fd986 100644 --- a/src/min/HydruinoUI.cpp +++ b/src/min/HydruinoUI.cpp @@ -1,15 +1,7 @@ /* Hydruino: Simple automation controller for hydroponic grow systems. Copyright (C) 2022-2023 NachtRaveVL - Hydruino Minimal UI + Hydruino Minimal/RO UI */ #include "Hydruino.h" #include "HydruinoUI.h" - -bool HydruinoMinUI::begin() -{ - return false; -} - -void HydruinoMinUI::setNeedsLayout() -{ } diff --git a/src/min/HydruinoUI.h b/src/min/HydruinoUI.h index 73383b7..1112ce5 100644 --- a/src/min/HydruinoUI.h +++ b/src/min/HydruinoUI.h @@ -1,17 +1,21 @@ /* Hydruino: Simple automation controller for hydroponic grow systems. Copyright (C) 2022-2023 NachtRaveVL - Hydruino Minimal UI + Hydruino Minimal/RO UI */ +#include +#ifdef HYDRO_USE_GUI +#ifndef HydroUI_H +#define HydroUI_H + class HydruinoMinUI; +typedef HydruinoMinUI HydruinoUI; -#include "Hydruino.h" +#include "..\shared\HydruinoUI.h" -class HydruinoMinUI : HydruinoUIInterface { +class HydruinoMinUI : public HydruinoBaseUI { public: - virtual bool begin() override; - - virtual void setNeedsLayout() override; - -protected: }; + +#endif // /ifndef HydroUI_H +#endif diff --git a/src/shared/HydruinoUI.cpp b/src/shared/HydruinoUI.cpp new file mode 100644 index 0000000..52a18e8 --- /dev/null +++ b/src/shared/HydruinoUI.cpp @@ -0,0 +1,15 @@ +/* Hydruino: Simple automation controller for hydroponic grow systems. + Copyright (C) 2022-2023 NachtRaveVL + Hydruino Base UI +*/ + +#include "Hydruino.h" +#include "HydruinoUI.h" + +bool HydruinoBaseUI::begin() +{ + return false; +} + +void HydruinoBaseUI::setNeedsLayout() +{ } diff --git a/src/shared/HydruinoUI.h b/src/shared/HydruinoUI.h new file mode 100644 index 0000000..9fc01d7 --- /dev/null +++ b/src/shared/HydruinoUI.h @@ -0,0 +1,21 @@ +/* Hydruino: Simple automation controller for hydroponic grow systems. + Copyright (C) 2022-2023 NachtRaveVL + Hydruino Base UI +*/ + +#include +#ifdef HYDRO_USE_GUI +#ifndef HydroBaseUI_H +#define HydroBaseUI_H + +class HydruinoBaseUI : public HydoUIInterface { +public: + virtual bool begin() override; + + virtual void setNeedsLayout() override; + +protected: +}; + +#endif // /ifndef HydroBaseUI_H +#endif