[AdaGFX helper] Only compile when used/needed

This commit is contained in:
Ton Huisman
2021-08-14 10:44:02 +02:00
parent 41adaba62a
commit 56dccd187a
5 changed files with 119 additions and 102 deletions
+1 -1
View File
@@ -7,4 +7,4 @@ paragraph=This is a library for the Adafruit ST7735 and ST7789 SPI displays.
category=Display
url=https://github.com/adafruit/Adafruit-ST7735-Library
architectures=*
depends=Adafruit GFX Library, Adafruit seesaw Library, SD
depends=Adafruit GFX Library
+1
View File
@@ -177,6 +177,7 @@
// #define USE_SETTINGS_ARCHIVE
// #define FEATURE_I2CMULTIPLEXER
// #define USE_TRIGONOMETRIC_FUNCTIONS_RULES
// #define PLUGIN_USES_ADAFRUITGFX // Used by Display plugins using Adafruit GFX library
/*
#######################################################################################################
+8
View File
@@ -1175,6 +1175,9 @@ To create/register a plugin, you have to :
#if !defined(LIMIT_BUILD_SIZE) && defined(ESP8266)
#define LIMIT_BUILD_SIZE // Redice buildsize on ESP8266 to fit in all Display plugins
#endif
#ifndef USES_ADAFRUITGFX_HELPER
#define USES_ADAFRUITGFX_HELPER
#endif
#ifndef USES_P012
#define USES_P012 // LCD
#endif
@@ -1494,6 +1497,11 @@ To create/register a plugin, you have to :
#define DISABLE_SOFTWARE_SERIAL
#endif
#if defined(USES_P095) || defined(USES_P096) || defined(USES_P116)
#ifndef PLUGIN_USES_ADAFRUITGFX
#define PLUGIN_USES_ADAFRUITGFX // Ensure AdafruitGFX_helper is available for graphics displays (only)
#endif
#endif
/*
#if defined(USES_P00x) || defined(USES_P00y)
+66 -61
View File
@@ -1,28 +1,31 @@
#include "../Helpers/AdafruitGFX_helper.h"
#include "../Helpers/StringConverter.h"
#include "../WebServer/Markup_Forms.h"
#ifdef ADAGFX_FONTS_INCLUDED
# include "src/Static/Fonts/Seven_Segment24pt7b.h"
# include "src/Static/Fonts/Seven_Segment18pt7b.h"
# include "src/Static/Fonts/FreeSans9pt7b.h"
# ifdef ADAGFX_FONTS_EXTRA_8PT_INCLUDED
# include "src/Static/Fonts/angelina8pt7b.h"
# include "src/Static/Fonts/NovaMono8pt7b.h"
# include "src/Static/Fonts/RepetitionScrolling8pt7b.h"
# include "src/Static/Fonts/unispace8pt7b.h"
# include "src/Static/Fonts/unispace_italic8pt7b.h"
# include "src/Static/Fonts/whitrabt8pt7b.h"
# endif // ifdef ADAGFX_FONTS_EXTRA_8PT_INCLUDED
# ifdef ADAGFX_FONTS_EXTRA_12PT_INCLUDED
# include "src/Static/Fonts/angelina12pt7b.h"
# include "src/Static/Fonts/NovaMono12pt7b.h"
# include "src/Static/Fonts/RepetitionScrolling12pt7b.h"
# include "src/Static/Fonts/unispace12pt7b.h"
# include "src/Static/Fonts/unispace_italic12pt7b.h"
# include "src/Static/Fonts/whitrabt12pt7b.h"
# endif // ifdef ADAGFX_FONTS_EXTRA_12PT_INCLUDED
#endif // ifdef ADAGFX_FONTS_INCLUDED
#ifdef PLUGIN_USES_ADAFRUITGFX
# include "../Helpers/StringConverter.h"
# include "../WebServer/Markup_Forms.h"
# ifdef ADAGFX_FONTS_INCLUDED
# include "src/Static/Fonts/Seven_Segment24pt7b.h"
# include "src/Static/Fonts/Seven_Segment18pt7b.h"
# include "src/Static/Fonts/FreeSans9pt7b.h"
# ifdef ADAGFX_FONTS_EXTRA_8PT_INCLUDED
# include "src/Static/Fonts/angelina8pt7b.h"
# include "src/Static/Fonts/NovaMono8pt7b.h"
# include "src/Static/Fonts/RepetitionScrolling8pt7b.h"
# include "src/Static/Fonts/unispace8pt7b.h"
# include "src/Static/Fonts/unispace_italic8pt7b.h"
# include "src/Static/Fonts/whitrabt8pt7b.h"
# endif // ifdef ADAGFX_FONTS_EXTRA_8PT_INCLUDED
# ifdef ADAGFX_FONTS_EXTRA_12PT_INCLUDED
# include "src/Static/Fonts/angelina12pt7b.h"
# include "src/Static/Fonts/NovaMono12pt7b.h"
# include "src/Static/Fonts/RepetitionScrolling12pt7b.h"
# include "src/Static/Fonts/unispace12pt7b.h"
# include "src/Static/Fonts/unispace_italic12pt7b.h"
# include "src/Static/Fonts/whitrabt12pt7b.h"
# endif // ifdef ADAGFX_FONTS_EXTRA_12PT_INCLUDED
# endif // ifdef ADAGFX_FONTS_INCLUDED
/******************************************************************************************
* get the display text for a 'text print mode' enum value
@@ -100,7 +103,7 @@ bool AdafruitGFX_helper::processCommand(const String& string) {
validIntFromString(sParams[argCount], nParams[argCount]);
loop = !sParams[argCount].isEmpty();
#ifndef BUILD_NO_DEBUG
# ifndef BUILD_NO_DEBUG
if (loglevelActiveFor(LOG_LEVEL_DEBUG_DEV)) {
log = ':';
@@ -109,13 +112,13 @@ bool AdafruitGFX_helper::processCommand(const String& string) {
log += sParams[argCount];
addLog(LOG_LEVEL_DEBUG_DEV, log);
}
#endif // ifndef BUILD_NO_DEBUG
# endif // ifndef BUILD_NO_DEBUG
if (loop) { argCount++; }
}
success = true; // If we get this far, we'll flip the flag if something wrong is found
#ifndef BUILD_NO_DEBUG
# ifndef BUILD_NO_DEBUG
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
log.reserve(90);
@@ -127,7 +130,7 @@ bool AdafruitGFX_helper::processCommand(const String& string) {
log += string;
addLog(LOG_LEVEL_INFO, log);
}
#endif // ifndef BUILD_NO_DEBUG
# endif // ifndef BUILD_NO_DEBUG
if (subcommand.equals(F("txt")))
{
@@ -208,7 +211,7 @@ bool AdafruitGFX_helper::processCommand(const String& string) {
_display->fillScreen(ADAGFX_BLACK);
}
else if (subcommand.equals(F("font")) && (argCount == 1)) {
#ifdef ADAGFX_FONTS_INCLUDED
# ifdef ADAGFX_FONTS_INCLUDED
sParams[0].toLowerCase();
if (sParams[0].equals(F("sevenseg24"))) {
@@ -222,82 +225,82 @@ bool AdafruitGFX_helper::processCommand(const String& string) {
calculateTextMetrics(10, 21);
// Extra 8pt fonts:
# ifdef ADAGFX_FONTS_EXTRA_8PT_INCLUDED
# ifdef ADAGFX_FONTS_EXTRA_8PT_ANGELINA
# ifdef ADAGFX_FONTS_EXTRA_8PT_INCLUDED
# ifdef ADAGFX_FONTS_EXTRA_8PT_ANGELINA
} else if (sParams[0].equals(F("angelina8prop"))) { // Proportional font!
_display->setFont(&angelina8pt7b);
calculateTextMetrics(6, 16);
# endif // ifdef ADAGFX_FONTS_EXTRA_8PT_ANGELINA
# ifdef ADAGFX_FONTS_EXTRA_8PT_NOVAMONO
# endif // ifdef ADAGFX_FONTS_EXTRA_8PT_ANGELINA
# ifdef ADAGFX_FONTS_EXTRA_8PT_NOVAMONO
} else if (sParams[0].equals(F("novamono8pt"))) {
_display->setFont(&NovaMono8pt7b);
calculateTextMetrics(9, 16);
# endif // ifdef ADAGFX_FONTS_EXTRA_8PT_NOVAMONO
# ifdef ADAGFX_FONTS_EXTRA_8PT_REPETITIONSCROLLiNG
# endif // ifdef ADAGFX_FONTS_EXTRA_8PT_NOVAMONO
# ifdef ADAGFX_FONTS_EXTRA_8PT_REPETITIONSCROLLiNG
} else if (sParams[0].equals(F("repetitionscrolling8pt"))) {
_display->setFont(&RepetitionScrolling8pt7b);
calculateTextMetrics(9, 16);
# endif // ifdef ADAGFX_FONTS_EXTRA_8PT_REPETITIONSCROLLiNG
# ifdef ADAGFX_FONTS_EXTRA_8PT_UNISPACE
# endif // ifdef ADAGFX_FONTS_EXTRA_8PT_REPETITIONSCROLLiNG
# ifdef ADAGFX_FONTS_EXTRA_8PT_UNISPACE
} else if (sParams[0].equals(F("unispace8pt"))) {
_display->setFont(&unispace8pt7b);
calculateTextMetrics(12, 24);
# endif // ifdef ADAGFX_FONTS_EXTRA_8PT_UNISPACE
# ifdef ADAGFX_FONTS_EXTRA_8PT_UNISPACEITALIC
# endif // ifdef ADAGFX_FONTS_EXTRA_8PT_UNISPACE
# ifdef ADAGFX_FONTS_EXTRA_8PT_UNISPACEITALIC
} else if (sParams[0].equals(F("unispaceitalic8pt"))) {
_display->setFont(&unispace_italic8pt7b);
calculateTextMetrics(12, 24);
# endif // ifdef ADAGFX_FONTS_EXTRA_8PT_UNISPACEITALIC
# ifdef ADAGFX_FONTS_EXTRA_8PT_WHITERABBiT
# endif // ifdef ADAGFX_FONTS_EXTRA_8PT_UNISPACEITALIC
# ifdef ADAGFX_FONTS_EXTRA_8PT_WHITERABBiT
} else if (sParams[0].equals(F("whiterabbit8pt"))) {
_display->setFont(&whitrabt8pt7b);
calculateTextMetrics(12, 24);
# endif // ifdef ADAGFX_FONTS_EXTRA_8PT_WHITERABBiT
# endif // ifdef ADAGFX_FONTS_EXTRA_8PT_INCLUDED
# endif // ifdef ADAGFX_FONTS_EXTRA_8PT_WHITERABBiT
# endif // ifdef ADAGFX_FONTS_EXTRA_8PT_INCLUDED
// Extra 12pt fonts:
# ifdef ADAGFX_FONTS_EXTRA_12PT_INCLUDED
# ifdef ADAGFX_FONTS_EXTRA_12PT_ANGELINA
# ifdef ADAGFX_FONTS_EXTRA_12PT_INCLUDED
# ifdef ADAGFX_FONTS_EXTRA_12PT_ANGELINA
} else if (sParams[0].equals(F("angelina12prop"))) { // Proportional font!
_display->setFont(&angelina12pt7b);
calculateTextMetrics(8, 24);
# endif // ifdef ADAGFX_FONTS_EXTRA_12PT_ANGELINA
# ifdef ADAGFX_FONTS_EXTRA_12PT_NOVAMONO
# endif // ifdef ADAGFX_FONTS_EXTRA_12PT_ANGELINA
# ifdef ADAGFX_FONTS_EXTRA_12PT_NOVAMONO
} else if (sParams[0].equals(F("novamono12pt"))) {
_display->setFont(&NovaMono12pt7b);
calculateTextMetrics(13, 34);
# endif // ifdef ADAGFX_FONTS_EXTRA_12PT_NOVAMONO
# ifdef ADAGFX_FONTS_EXTRA_12PT_REPETITIONSCROLLiNG
# endif // ifdef ADAGFX_FONTS_EXTRA_12PT_NOVAMONO
# ifdef ADAGFX_FONTS_EXTRA_12PT_REPETITIONSCROLLiNG
} else if (sParams[0].equals(F("repetitionscrolling12pt"))) {
_display->setFont(&RepetitionScrolling12pt7b);
calculateTextMetrics(13, 24);
# endif // ifdef ADAGFX_FONTS_EXTRA_12PT_REPETITIONSCROLLiNG
# ifdef ADAGFX_FONTS_EXTRA_12PT_UNISPACE
# endif // ifdef ADAGFX_FONTS_EXTRA_12PT_REPETITIONSCROLLiNG
# ifdef ADAGFX_FONTS_EXTRA_12PT_UNISPACE
} else if (sParams[0].equals(F("unispace12pt"))) {
_display->setFont(&unispace12pt7b);
calculateTextMetrics(13, 18);
# endif // ifdef ADAGFX_FONTS_EXTRA_12PT_UNISPACE
# ifdef ADAGFX_FONTS_EXTRA_12PT_UNISPACEITALIC
# endif // ifdef ADAGFX_FONTS_EXTRA_12PT_UNISPACE
# ifdef ADAGFX_FONTS_EXTRA_12PT_UNISPACEITALIC
} else if (sParams[0].equals(F("unispaceitalic12pt"))) {
_display->setFont(&unispace_italic12pt7b);
calculateTextMetrics(13, 18);
# endif // ifdef ADAGFX_FONTS_EXTRA_12PT_UNISPACEITALIC
# ifdef ADAGFX_FONTS_EXTRA_12PT_WHITERABBiT
# endif // ifdef ADAGFX_FONTS_EXTRA_12PT_UNISPACEITALIC
# ifdef ADAGFX_FONTS_EXTRA_12PT_WHITERABBiT
} else if (sParams[0].equals(F("whiterabbir12pt"))) {
_display->setFont(&whitrabt12pt7b);
calculateTextMetrics(13, 18);
# endif // ifdef ADAGFX_FONTS_EXTRA_12PT_WHITERABBiT
# endif // ifdef ADAGFX_FONTS_EXTRA_12PT_INCLUDED
# endif // ifdef ADAGFX_FONTS_EXTRA_12PT_WHITERABBiT
# endif // ifdef ADAGFX_FONTS_EXTRA_12PT_INCLUDED
} else if (sParams[0].equals(F("default"))) { // font,default is always available!
_display->setFont();
calculateTextMetrics(6, 10);
} else {
success = false;
}
#else // ifdef ADAGFX_FONTS_INCLUDED
# else // ifdef ADAGFX_FONTS_INCLUDED
success = false;
#endif // ifdef ADAGFX_FONTS_INCLUDED
# endif // ifdef ADAGFX_FONTS_INCLUDED
}
else if (subcommand.equals(F("l")) && (argCount == 5)) { // line
else if (subcommand.equals(F("l")) && (argCount == 5)) { // line
_display->drawLine(nParams[0], nParams[1], nParams[2], nParams[3], parseColor(sParams[4]));
}
else if (subcommand.equals(F("lh")) && (argCount == 3)) { // Horizontal line
@@ -524,7 +527,7 @@ void AdafruitGFX_helper::calculateTextMetrics(uint8_t fontwidth, uint8_t fonthei
_textcols = _res_x / (_fontwidth * _fontscaling);
_textrows = _res_y / (_fontheight * _fontscaling);
#ifndef BUILD_NO_DEBUG
# ifndef BUILD_NO_DEBUG
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
String log;
@@ -535,5 +538,7 @@ void AdafruitGFX_helper::calculateTextMetrics(uint8_t fontwidth, uint8_t fonthei
log += _textrows;
addLog(LOG_LEVEL_INFO, log);
}
#endif // ifndef BUILD_NO_DEBUG
# endif // ifndef BUILD_NO_DEBUG
}
#endif // ifdef PLUGIN_USES_ADAFRUITGFX
+43 -40
View File
@@ -1,61 +1,63 @@
#ifndef HELPERS_ADAFRUITGFX_HELPER_H
#define HELPERS_ADAFRUITGFX_HELPER_H
#ifdef PLUGIN_USES_ADAFRUITGFX
/****************************************************************************
* helper class and functions for displays that use Adafruit_GFX library
***************************************************************************/
#include <Arduino.h>
#include <Adafruit_GFX.h>
# include <Arduino.h>
# include <Adafruit_GFX.h>
#include "../Helpers/Numerical.h"
#include "../ESPEasyCore/ESPEasy_Log.h"
# include "../Helpers/Numerical.h"
# include "../ESPEasyCore/ESPEasy_Log.h"
#define ADAGFX_PARSE_MAX_ARGS 8 // Maximum number of arguments needed and supported
#define ADAGFX_FONTS_INCLUDED // 3 extra fonts, also controls enable/disable of below 8pt/12pt fonts
# define ADAGFX_PARSE_MAX_ARGS 8 // Maximum number of arguments needed and supported
# define ADAGFX_FONTS_INCLUDED // 3 extra fonts, also controls enable/disable of below 8pt/12pt fonts
// #define ADAGFX_FONTS_EXTRA_8PT_INCLUDED // 6 extra 8pt fonts, should probably only be enabled in a private custom build, adds ~11,8 kB
// #define ADAGFX_FONTS_EXTRA_12PT_INCLUDED // 6 extra 12pt fonts, should probably only be enabled in a private custom build, adds ~19,8 kB
// To enable/disable 8pt fonts separately: (will only be enabled if ADAGFX_FONTS_EXTRA_8PT_INCLUDED is defined)
#define ADAGFX_FONTS_EXTRA_8PT_ANGELINA // This font is proportinally spaced!
#define ADAGFX_FONTS_EXTRA_8PT_NOVAMONO
#define ADAGFX_FONTS_EXTRA_8PT_REPETITIONSCROLLiNG
#define ADAGFX_FONTS_EXTRA_8PT_UNISPACE
#define ADAGFX_FONTS_EXTRA_8PT_UNISPACEITALIC
#define ADAGFX_FONTS_EXTRA_8PT_WHITERABBiT
# define ADAGFX_FONTS_EXTRA_8PT_ANGELINA // This font is proportinally spaced!
# define ADAGFX_FONTS_EXTRA_8PT_NOVAMONO
# define ADAGFX_FONTS_EXTRA_8PT_REPETITIONSCROLLiNG
# define ADAGFX_FONTS_EXTRA_8PT_UNISPACE
# define ADAGFX_FONTS_EXTRA_8PT_UNISPACEITALIC
# define ADAGFX_FONTS_EXTRA_8PT_WHITERABBiT
// To enable/disable 12pt fonts separately: (will only be enabled if ADAGFX_FONTS_EXTRA_12PT_INCLUDED is defined)
#define ADAGFX_FONTS_EXTRA_12PT_ANGELINA // This font is proportinally spaced!
#define ADAGFX_FONTS_EXTRA_12PT_NOVAMONO
#define ADAGFX_FONTS_EXTRA_12PT_REPETITIONSCROLLiNG
#define ADAGFX_FONTS_EXTRA_12PT_UNISPACE
#define ADAGFX_FONTS_EXTRA_12PT_UNISPACEITALIC
#define ADAGFX_FONTS_EXTRA_12PT_WHITERABBiT
# define ADAGFX_FONTS_EXTRA_12PT_ANGELINA // This font is proportinally spaced!
# define ADAGFX_FONTS_EXTRA_12PT_NOVAMONO
# define ADAGFX_FONTS_EXTRA_12PT_REPETITIONSCROLLiNG
# define ADAGFX_FONTS_EXTRA_12PT_UNISPACE
# define ADAGFX_FONTS_EXTRA_12PT_UNISPACEITALIC
# define ADAGFX_FONTS_EXTRA_12PT_WHITERABBiT
#if defined(LIMIT_BUILD_SIZE) && defined(ADAGFX_FONTS_INCLUDED)
# undef ADAGFX_FONTS_INCLUDED
#endif // if defined(LIMIT_BUILD_SIZE) && defined(ADAGFX_FONTS_INCLUDED)
# if defined(LIMIT_BUILD_SIZE) && defined(ADAGFX_FONTS_INCLUDED)
# undef ADAGFX_FONTS_INCLUDED
# endif // if defined(LIMIT_BUILD_SIZE) && defined(ADAGFX_FONTS_INCLUDED)
// Color definitions, borrowed from Adafruit_ILI9341.h
#define ADAGFX_BLACK 0x0000 ///< 0, 0, 0
#define ADAGFX_NAVY 0x000F ///< 0, 0, 123
#define ADAGFX_DARKGREEN 0x03E0 ///< 0, 125, 0
#define ADAGFX_DARKCYAN 0x03EF ///< 0, 125, 123
#define ADAGFX_MAROON 0x7800 ///< 123, 0, 0
#define ADAGFX_PURPLE 0x780F ///< 123, 0, 123
#define ADAGFX_OLIVE 0x7BE0 ///< 123, 125, 0
#define ADAGFX_LIGHTGREY 0xC618 ///< 198, 195, 198
#define ADAGFX_DARKGREY 0x7BEF ///< 123, 125, 123
#define ADAGFX_BLUE 0x001F ///< 0, 0, 255
#define ADAGFX_GREEN 0x07E0 ///< 0, 255, 0
#define ADAGFX_CYAN 0x07FF ///< 0, 255, 255
#define ADAGFX_RED 0xF800 ///< 255, 0, 0
#define ADAGFX_MAGENTA 0xF81F ///< 255, 0, 255
#define ADAGFX_YELLOW 0xFFE0 ///< 255, 255, 0
#define ADAGFX_WHITE 0xFFFF ///< 255, 255, 255
#define ADAGFX_ORANGE 0xFD20 ///< 255, 165, 0
#define ADAGFX_GREENYELLOW 0xAFE5 ///< 173, 255, 41
#define ADAGFX_PINK 0xFC18 ///< 255, 130, 198
# define ADAGFX_BLACK 0x0000 ///< 0, 0, 0
# define ADAGFX_NAVY 0x000F ///< 0, 0, 123
# define ADAGFX_DARKGREEN 0x03E0 ///< 0, 125, 0
# define ADAGFX_DARKCYAN 0x03EF ///< 0, 125, 123
# define ADAGFX_MAROON 0x7800 ///< 123, 0, 0
# define ADAGFX_PURPLE 0x780F ///< 123, 0, 123
# define ADAGFX_OLIVE 0x7BE0 ///< 123, 125, 0
# define ADAGFX_LIGHTGREY 0xC618 ///< 198, 195, 198
# define ADAGFX_DARKGREY 0x7BEF ///< 123, 125, 123
# define ADAGFX_BLUE 0x001F ///< 0, 0, 255
# define ADAGFX_GREEN 0x07E0 ///< 0, 255, 0
# define ADAGFX_CYAN 0x07FF ///< 0, 255, 255
# define ADAGFX_RED 0xF800 ///< 255, 0, 0
# define ADAGFX_MAGENTA 0xF81F ///< 255, 0, 255
# define ADAGFX_YELLOW 0xFFE0 ///< 255, 255, 0
# define ADAGFX_WHITE 0xFFFF ///< 255, 255, 255
# define ADAGFX_ORANGE 0xFD20 ///< 255, 165, 0
# define ADAGFX_GREENYELLOW 0xAFE5 ///< 173, 255, 41
# define ADAGFX_PINK 0xFC18 ///< 255, 130, 198
enum class AdaGFXTextPrintMode : uint8_t {
ContinueToNextLine = 0,
@@ -132,5 +134,6 @@ private:
uint8_t _p095_compensation = 0;
bool _columnRowMode = false;
};
#endif // ifdef PLUGIN_USES_ADAFRUITGFX
#endif // ifndef HELPERS_ADAFRUITGFX_HELPER_H