From 318d3b63459abff7b643adee9beeb89949a78ddd Mon Sep 17 00:00:00 2001 From: TD-er Date: Mon, 25 Mar 2024 14:55:42 +0100 Subject: [PATCH] [Display] Reduce ESP8266 'display' build size --- src/src/CustomBuild/define_plugin_sets.h | 6 +++++ src/src/PluginStructs/P036_data_struct.cpp | 28 ++++++++++++---------- src/src/PluginStructs/P036_data_struct.h | 6 ----- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/src/CustomBuild/define_plugin_sets.h b/src/src/CustomBuild/define_plugin_sets.h index 1a3a6dbc55..03c274eb92 100644 --- a/src/src/CustomBuild/define_plugin_sets.h +++ b/src/src/CustomBuild/define_plugin_sets.h @@ -1701,6 +1701,12 @@ To create/register a plugin, you have to : #ifndef PLUGIN_BUILD_MAX_ESP32 #define LIMIT_BUILD_SIZE // Reduce buildsize (on ESP8266 / pre-IDF4.x) to fit in all Display plugins #define KEEP_I2C_MULTIPLEXER + #ifndef P036_LIMIT_BUILD_SIZE + #define P036_LIMIT_BUILD_SIZE // Reduce build size for P036 (FramedOLED) only + #endif + #ifndef P037_LIMIT_BUILD_SIZE + #define P037_LIMIT_BUILD_SIZE // Reduce build size for P037 (MQTT Import) only + #endif #endif #endif #if defined(ESP8266) diff --git a/src/src/PluginStructs/P036_data_struct.cpp b/src/src/PluginStructs/P036_data_struct.cpp index 483501fb91..431adef6d8 100644 --- a/src/src/PluginStructs/P036_data_struct.cpp +++ b/src/src/PluginStructs/P036_data_struct.cpp @@ -146,7 +146,7 @@ const __FlashStringHelper * tFontSettings::FontName() const { // This is very precious memory, so we must find something other way to define this. /* *INDENT-OFF* */ -const tFontSizes FontSizes[P36_MaxFontCount] = { +const tFontSizes FontSizes[] = { { getArialMT_Plain_24(), 24, 28 }, // 9643 # ifndef P036_LIMIT_BUILD_SIZE { getDialog_plain_18(), 19, 22 }, // 7399 @@ -159,7 +159,7 @@ const tFontSizes FontSizes[P36_MaxFontCount] = { }; /* *INDENT-ON* */ -constexpr tSizeSettings SizeSettings[P36_MaxSizesCount] = { +constexpr tSizeSettings SizeSettings[] = { { P36_MaxDisplayWidth, P36_MaxDisplayHeight, 0, // 128x64 4, // max. line count 113, 15 // WiFi indicator @@ -178,7 +178,7 @@ constexpr tSizeSettings SizeSettings[P36_MaxSizesCount] = { const tSizeSettings& P036_data_struct::getDisplaySizeSettings(p036_resolution disp_resolution) { int index = static_cast(disp_resolution); - if ((index < 0) || (index >= P36_MaxSizesCount)) { index = 0; } + if ((index < 0) || (index >= static_cast(NR_ELEMENTS(SizeSettings)))) { index = 0; } return SizeSettings[index]; } @@ -1019,7 +1019,7 @@ tIndividualFontSettings P036_data_struct::CalculateIndividualFontSettings(uint8_ for (uint8_t i = LineNo; i < P36_Nlines; ++i) { // calculate individual font settings - int8_t lFontIndex = FontIndex; + uint8_t lFontIndex = FontIndex; const eModifyFont iModifyFont = static_cast(get3BitFromUL(LineContent->DisplayLinesV1[i].ModifyLayout, P036_FLAG_ModifyLayout_Font)); @@ -1028,9 +1028,11 @@ tIndividualFontSettings P036_data_struct::CalculateIndividualFontSettings(uint8_ if (ScrollingPages.linesPerFrameDef > 1) { // Font can only be enlarged if more than 1 line is displayed - lFontIndex--; - - if (lFontIndex < IdxForBiggestFont) { lFontIndex = IdxForBiggestFont; } + if (lFontIndex > IdxForBiggestFont) { + lFontIndex--; + } else { + lFontIndex = IdxForBiggestFont; + } result.IdxForBiggestFontUsed = lFontIndex; } break; @@ -1045,12 +1047,12 @@ tIndividualFontSettings P036_data_struct::CalculateIndividualFontSettings(uint8_ case eModifyFont::eReduce: lFontIndex++; - if (lFontIndex > (P36_MaxFontCount - 1)) { - lFontIndex = P36_MaxFontCount - 1; + if (lFontIndex >= NR_ELEMENTS(FontSizes)) { + lFontIndex = NR_ELEMENTS(FontSizes) - 1; } break; case eModifyFont::eMinimize: - lFontIndex = P36_MaxFontCount - 1; + lFontIndex = NR_ELEMENTS(FontSizes) - 1; break; case eModifyFont::eNone: lFontIndex = FontIndex; @@ -1090,7 +1092,7 @@ tIndividualFontSettings P036_data_struct::CalculateIndividualFontSettings(uint8_ lSpace = -1; // allow overlapping by 1 pix if (deltaHeight < (-1 * (lLinesPerFrame - 1))) { - if ((result.IdxForBiggestFontUsed == (P36_MaxFontCount - 1)) && + if ((result.IdxForBiggestFontUsed == (NR_ELEMENTS(FontSizes) - 1)) && (LinesPerFrame == SizeSettings[static_cast(disp_resolution)].MaxLines)) { // max lines for used display and smallest font reached -> use special space between the lines and return 'fits' // overlapping (lSpace<0) depends on the absolute display height @@ -1187,7 +1189,7 @@ tFontSettings P036_data_struct::CalculateFontSettings(uint8_t lDefaultLines) { log1.reserve(80); # endif // ifdef P036_FONT_CALC_LOG - for (i = 0; i < P36_MaxFontCount - 1; ++i) { + for (i = 0; i < NR_ELEMENTS(FontSizes) - 1; ++i) { // check available fonts for the line setting # ifdef P036_FONT_CALC_LOG @@ -1246,7 +1248,7 @@ tFontSettings P036_data_struct::CalculateFontSettings(uint8_t lDefaultLines) { case p036_resolution::pix64x48: result.Space = -1; break; } - iFontIndex = P36_MaxFontCount - 1; + iFontIndex = NR_ELEMENTS(FontSizes) - 1; } if (lDefaultLines == 0) { diff --git a/src/src/PluginStructs/P036_data_struct.h b/src/src/PluginStructs/P036_data_struct.h index 800b128714..cb7091c9c6 100644 --- a/src/src/PluginStructs/P036_data_struct.h +++ b/src/src/PluginStructs/P036_data_struct.h @@ -85,12 +85,6 @@ # define P36_Nlines 12 // The number of different lines which can be displayed - each line is 64 chars max # define P36_NcharsV0 32 // max chars per line up to 22.11.2019 (V0) # define P36_NcharsV1 64 // max chars per line from 22.11.2019 (V1) -# define P36_MaxSizesCount 3 // number of different OLED sizes -# ifdef P036_LIMIT_BUILD_SIZE -# define P36_MaxFontCount 3 // number of different fonts -# else // ifdef P036_LIMIT_BUILD_SIZE -# define P36_MaxFontCount 5 // number of different fonts -# endif // ifdef P036_LIMIT_BUILD_SIZE # define P36_MaxDisplayWidth 128 # define P36_MaxDisplayHeight 64