From 33c663b66fd0932569437ede057b63c77c099077 Mon Sep 17 00:00:00 2001 From: BlueAndi Date: Thu, 14 Dec 2023 21:49:49 +0100 Subject: [PATCH] Small runtime improvements. --- .../src/IconTextLampPlugin.cpp | 36 ++++++++++--------- lib/IconTextPlugin/src/IconTextPlugin.cpp | 26 ++++++++------ lib/ThreeIconPlugin/src/ThreeIconPlugin.cpp | 27 ++++++++------ 3 files changed, 51 insertions(+), 38 deletions(-) diff --git a/lib/IconTextLampPlugin/src/IconTextLampPlugin.cpp b/lib/IconTextLampPlugin/src/IconTextLampPlugin.cpp index 7ea183ce..be10500d 100644 --- a/lib/IconTextLampPlugin/src/IconTextLampPlugin.cpp +++ b/lib/IconTextLampPlugin/src/IconTextLampPlugin.cpp @@ -373,12 +373,14 @@ bool IconTextLampPlugin::isUploadAccepted(const String& topic, const String& src void IconTextLampPlugin::start(uint16_t width, uint16_t height) { - uint16_t tcHeight = 0U; - uint16_t lampWidth = 0U; - uint16_t lampDistance = 0U; - const uint16_t minDistance = 1U; /* Min. distance between lamps. */ - const uint16_t minBorder = 1U; /* Min. border left and right of all lamps. */ - const uint16_t canvasWidth = width - ICON_WIDTH; + uint16_t tcHeight = 0U; + uint16_t lampWidth = 0U; + uint16_t lampDistance = 0U; + const uint16_t minDistance = 1U; /* Min. distance between lamps. */ + const uint16_t minBorder = 1U; /* Min. border left and right of all lamps. */ + const uint16_t canvasWidth = width - ICON_WIDTH; + String bitmapFullPath = getFileName(FILE_EXT_BITMAP); + String spriteSheetFullPath = getFileName(FILE_EXT_SPRITE_SHEET); MutexGuard guard(m_mutex); m_iconCanvas.setPosAndSize(0, 0, ICON_WIDTH, ICON_HEIGHT); @@ -391,17 +393,17 @@ void IconTextLampPlugin::start(uint16_t width, uint16_t height) m_iconPath.clear(); m_spriteSheetPath.clear(); - if (false == m_bitmapWidget.loadSpriteSheet(FILESYSTEM, getFileName(FILE_EXT_SPRITE_SHEET), getFileName(FILE_EXT_BITMAP))) + if (false == m_bitmapWidget.loadSpriteSheet(FILESYSTEM, spriteSheetFullPath, bitmapFullPath)) { - if (true == m_bitmapWidget.load(FILESYSTEM, getFileName(FILE_EXT_BITMAP))) + if (true == m_bitmapWidget.load(FILESYSTEM, bitmapFullPath)) { - m_iconPath = getFileName(FILE_EXT_BITMAP); + m_iconPath = bitmapFullPath; } } else { - m_iconPath = getFileName(FILE_EXT_BITMAP); - m_spriteSheetPath = getFileName(FILE_EXT_SPRITE_SHEET); + m_iconPath = bitmapFullPath; + m_spriteSheetPath = spriteSheetFullPath; } /* The text canvas is left aligned to the icon canvas and aligned to the @@ -445,18 +447,20 @@ void IconTextLampPlugin::start(uint16_t width, uint16_t height) void IconTextLampPlugin::stop() { - MutexGuard guard(m_mutex); + String bitmapFullPath = getFileName(FILE_EXT_BITMAP); + String spriteSheetFullPath = getFileName(FILE_EXT_SPRITE_SHEET); + MutexGuard guard(m_mutex); /* Remove icon which is specific for the plugin instance. */ - if (false != FILESYSTEM.remove(getFileName(FILE_EXT_BITMAP))) + if (false != FILESYSTEM.remove(bitmapFullPath)) { - LOG_INFO("File %s removed", getFileName(FILE_EXT_BITMAP).c_str()); + LOG_INFO("File %s removed", bitmapFullPath.c_str()); } /* Remove spritesheet which is specific for the plugin instance. */ - if (false != FILESYSTEM.remove(getFileName(FILE_EXT_SPRITE_SHEET))) + if (false != FILESYSTEM.remove(spriteSheetFullPath)) { - LOG_INFO("File %s removed", getFileName(FILE_EXT_SPRITE_SHEET).c_str()); + LOG_INFO("File %s removed", spriteSheetFullPath.c_str()); } } diff --git a/lib/IconTextPlugin/src/IconTextPlugin.cpp b/lib/IconTextPlugin/src/IconTextPlugin.cpp index 0a72427f..89519a9e 100644 --- a/lib/IconTextPlugin/src/IconTextPlugin.cpp +++ b/lib/IconTextPlugin/src/IconTextPlugin.cpp @@ -274,7 +274,9 @@ bool IconTextPlugin::isUploadAccepted(const String& topic, const String& srcFile void IconTextPlugin::start(uint16_t width, uint16_t height) { - MutexGuard guard(m_mutex); + String bitmapFullPath = getFileName(FILE_EXT_BITMAP); + String spriteSheetFullPath = getFileName(FILE_EXT_SPRITE_SHEET); + MutexGuard guard(m_mutex); m_iconCanvas.setPosAndSize(0, 0, ICON_WIDTH, ICON_HEIGHT); (void)m_iconCanvas.addWidget(m_bitmapWidget); @@ -286,17 +288,17 @@ void IconTextPlugin::start(uint16_t width, uint16_t height) m_iconPath.clear(); m_spriteSheetPath.clear(); - if (false == m_bitmapWidget.loadSpriteSheet(FILESYSTEM, getFileName(FILE_EXT_SPRITE_SHEET), getFileName(FILE_EXT_BITMAP))) + if (false == m_bitmapWidget.loadSpriteSheet(FILESYSTEM, spriteSheetFullPath, bitmapFullPath)) { - if (true == m_bitmapWidget.load(FILESYSTEM, getFileName(FILE_EXT_BITMAP))) + if (true == m_bitmapWidget.load(FILESYSTEM, bitmapFullPath)) { - m_iconPath = getFileName(FILE_EXT_BITMAP); + m_iconPath = bitmapFullPath; } } else { - m_iconPath = getFileName(FILE_EXT_BITMAP); - m_spriteSheetPath = getFileName(FILE_EXT_SPRITE_SHEET); + m_iconPath = bitmapFullPath; + m_spriteSheetPath = spriteSheetFullPath; } /* The text canvas is left aligned to the icon canvas and it spans over @@ -322,18 +324,20 @@ void IconTextPlugin::start(uint16_t width, uint16_t height) void IconTextPlugin::stop() { - MutexGuard guard(m_mutex); + String bitmapFullPath = getFileName(FILE_EXT_BITMAP); + String spriteSheetFullPath = getFileName(FILE_EXT_SPRITE_SHEET); + MutexGuard guard(m_mutex); /* Remove icon which is specific for the plugin instance. */ - if (false != FILESYSTEM.remove(getFileName(FILE_EXT_BITMAP))) + if (false != FILESYSTEM.remove(bitmapFullPath)) { - LOG_INFO("File %s removed", getFileName(FILE_EXT_BITMAP).c_str()); + LOG_INFO("File %s removed", bitmapFullPath.c_str()); } /* Remove spritesheet which is specific for the plugin instance. */ - if (false != FILESYSTEM.remove(getFileName(FILE_EXT_SPRITE_SHEET))) + if (false != FILESYSTEM.remove(spriteSheetFullPath)) { - LOG_INFO("File %s removed", getFileName(FILE_EXT_SPRITE_SHEET).c_str()); + LOG_INFO("File %s removed", spriteSheetFullPath.c_str()); } } diff --git a/lib/ThreeIconPlugin/src/ThreeIconPlugin.cpp b/lib/ThreeIconPlugin/src/ThreeIconPlugin.cpp index 0744de01..9527df5e 100644 --- a/lib/ThreeIconPlugin/src/ThreeIconPlugin.cpp +++ b/lib/ThreeIconPlugin/src/ThreeIconPlugin.cpp @@ -352,7 +352,9 @@ void ThreeIconPlugin::start(uint16_t width, uint16_t height) for(iconId = 0U; iconId < MAX_ICONS; ++iconId) { - int16_t x = (ICON_WIDTH + DISTANCE) * iconId + DISTANCE; + int16_t x = (ICON_WIDTH + DISTANCE) * iconId + DISTANCE; + String bitmapFullPath = getFileName(iconId, FILE_EXT_BITMAP); + String spriteSheetFullPath = getFileName(iconId, FILE_EXT_SPRITE_SHEET); (void)m_threeIconCanvas.addWidget(m_bitmapWidgets[iconId]); m_bitmapWidgets[iconId].move(x, 0); @@ -364,17 +366,17 @@ void ThreeIconPlugin::start(uint16_t width, uint16_t height) m_iconPaths[iconId].clear(); m_spriteSheetPaths[iconId].clear(); - if (false == m_bitmapWidgets[iconId].loadSpriteSheet(FILESYSTEM, getFileName(iconId, FILE_EXT_SPRITE_SHEET), getFileName(iconId, FILE_EXT_BITMAP))) + if (false == m_bitmapWidgets[iconId].loadSpriteSheet(FILESYSTEM, spriteSheetFullPath, bitmapFullPath)) { - if (true == m_bitmapWidgets[iconId].load(FILESYSTEM, getFileName(iconId, FILE_EXT_BITMAP))) + if (true == m_bitmapWidgets[iconId].load(FILESYSTEM, bitmapFullPath)) { - m_iconPaths[iconId] = getFileName(iconId, FILE_EXT_BITMAP); + m_iconPaths[iconId] = bitmapFullPath; } } else { - m_iconPaths[iconId] = getFileName(iconId, FILE_EXT_BITMAP); - m_spriteSheetPaths[iconId] = getFileName(iconId, FILE_EXT_SPRITE_SHEET); + m_iconPaths[iconId] = bitmapFullPath; + m_spriteSheetPaths[iconId] = spriteSheetFullPath; } } } @@ -385,15 +387,18 @@ void ThreeIconPlugin::stop() MutexGuard guard(m_mutex); for(iconId = 0U; iconId < MAX_ICONS; ++iconId) - { - if (false != FILESYSTEM.remove(getFileName(iconId, FILE_EXT_BITMAP))) + { + String bitmapFullPath = getFileName(iconId, FILE_EXT_BITMAP); + String spriteSheetFullPath = getFileName(iconId, FILE_EXT_SPRITE_SHEET); + + if (false != FILESYSTEM.remove(bitmapFullPath)) { - LOG_INFO("File %s removed", getFileName(iconId, FILE_EXT_BITMAP).c_str()); + LOG_INFO("File %s removed", bitmapFullPath.c_str()); } - if (false != FILESYSTEM.remove(getFileName(iconId, FILE_EXT_SPRITE_SHEET))) + if (false != FILESYSTEM.remove(spriteSheetFullPath)) { - LOG_INFO("File %s removed", getFileName(iconId, FILE_EXT_SPRITE_SHEET).c_str()); + LOG_INFO("File %s removed", spriteSheetFullPath.c_str()); } } }