Skip to content

Commit

Permalink
UI abstraction cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
NachtRaveVL authored and NachtRaveVL committed Mar 5, 2023
1 parent 22d7870 commit 1929ec4
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 57 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions examples/FullSystem/FullSystem.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions examples/VerticalNFT/VerticalNFT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/HydroInterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
struct HydroJSONSerializableInterface;

class HydroObjInterface;
class HydruinoUIInterface;
class HydoUIInterface;
class HydroRTCInterface;

struct HydroDigitalInputPinInterface;
Expand Down Expand Up @@ -94,7 +94,7 @@ class HydroObjInterface {
};

// UI Interface
class HydruinoUIInterface {
class HydoUIInterface {
public:
virtual bool begin() = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/HydroUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/HydroUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ inline HydroPublisher *getPublisher()

#ifdef HYDRO_USE_GUI

inline HydruinoUIInterface *getUI()
inline HydoUIInterface *getUI()
{
return Hydruino::_activeInstance ? Hydruino::_activeInstance->_activeUIInstance : nullptr;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Hydruino.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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;
Expand Down
10 changes: 1 addition & 9 deletions src/full/HydruinoUI.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
/* Hydruino: Simple automation controller for hydroponic grow systems.
Copyright (C) 2022-2023 NachtRaveVL <[email protected]>
Hydruino Full UI
Hydruino Full/RW UI
*/

#include "Hydruino.h"
#include "HydruinoUI.h"

bool HydruinoFullUI::begin()
{
return false;
}

void HydruinoFullUI::setNeedsLayout()
{ }
20 changes: 12 additions & 8 deletions src/full/HydruinoUI.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
/* Hydruino: Simple automation controller for hydroponic grow systems.
Copyright (C) 2022-2023 NachtRaveVL <[email protected]>
Hydruino Full UI
Hydruino Full/RW UI
*/

#include <Hydruino.h>
#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
10 changes: 1 addition & 9 deletions src/min/HydruinoUI.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
/* Hydruino: Simple automation controller for hydroponic grow systems.
Copyright (C) 2022-2023 NachtRaveVL <[email protected]>
Hydruino Minimal UI
Hydruino Minimal/RO UI
*/

#include "Hydruino.h"
#include "HydruinoUI.h"

bool HydruinoMinUI::begin()
{
return false;
}

void HydruinoMinUI::setNeedsLayout()
{ }
20 changes: 12 additions & 8 deletions src/min/HydruinoUI.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
/* Hydruino: Simple automation controller for hydroponic grow systems.
Copyright (C) 2022-2023 NachtRaveVL <[email protected]>
Hydruino Minimal UI
Hydruino Minimal/RO UI
*/

#include <Hydruino.h>
#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
15 changes: 15 additions & 0 deletions src/shared/HydruinoUI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Hydruino: Simple automation controller for hydroponic grow systems.
Copyright (C) 2022-2023 NachtRaveVL <[email protected]>
Hydruino Base UI
*/

#include "Hydruino.h"
#include "HydruinoUI.h"

bool HydruinoBaseUI::begin()
{
return false;
}

void HydruinoBaseUI::setNeedsLayout()
{ }
21 changes: 21 additions & 0 deletions src/shared/HydruinoUI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Hydruino: Simple automation controller for hydroponic grow systems.
Copyright (C) 2022-2023 NachtRaveVL <[email protected]>
Hydruino Base UI
*/

#include <Hydruino.h>
#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

0 comments on commit 1929ec4

Please sign in to comment.