Skip to content

Commit

Permalink
Small runtime improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueAndi committed Dec 14, 2023
1 parent f57898d commit 33c663b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 38 deletions.
36 changes: 20 additions & 16 deletions lib/IconTextLampPlugin/src/IconTextLampPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MutexRecursive> guard(m_mutex);

m_iconCanvas.setPosAndSize(0, 0, ICON_WIDTH, ICON_HEIGHT);
Expand All @@ -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
Expand Down Expand Up @@ -445,18 +447,20 @@ void IconTextLampPlugin::start(uint16_t width, uint16_t height)

void IconTextLampPlugin::stop()
{
MutexGuard<MutexRecursive> guard(m_mutex);
String bitmapFullPath = getFileName(FILE_EXT_BITMAP);
String spriteSheetFullPath = getFileName(FILE_EXT_SPRITE_SHEET);
MutexGuard<MutexRecursive> 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());
}
}

Expand Down
26 changes: 15 additions & 11 deletions lib/IconTextPlugin/src/IconTextPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ bool IconTextPlugin::isUploadAccepted(const String& topic, const String& srcFile

void IconTextPlugin::start(uint16_t width, uint16_t height)
{
MutexGuard<MutexRecursive> guard(m_mutex);
String bitmapFullPath = getFileName(FILE_EXT_BITMAP);
String spriteSheetFullPath = getFileName(FILE_EXT_SPRITE_SHEET);
MutexGuard<MutexRecursive> guard(m_mutex);

m_iconCanvas.setPosAndSize(0, 0, ICON_WIDTH, ICON_HEIGHT);
(void)m_iconCanvas.addWidget(m_bitmapWidget);
Expand All @@ -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
Expand All @@ -322,18 +324,20 @@ void IconTextPlugin::start(uint16_t width, uint16_t height)

void IconTextPlugin::stop()
{
MutexGuard<MutexRecursive> guard(m_mutex);
String bitmapFullPath = getFileName(FILE_EXT_BITMAP);
String spriteSheetFullPath = getFileName(FILE_EXT_SPRITE_SHEET);
MutexGuard<MutexRecursive> 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());
}
}

Expand Down
27 changes: 16 additions & 11 deletions lib/ThreeIconPlugin/src/ThreeIconPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}
}
Expand All @@ -385,15 +387,18 @@ void ThreeIconPlugin::stop()
MutexGuard<MutexRecursive> 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());
}
}
}
Expand Down

0 comments on commit 33c663b

Please sign in to comment.