mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-04 04:40:50 +00:00
Screensaver validates short name (#4115)
This commit is contained in:
parent
b1cf5778b4
commit
96be051bff
@ -277,6 +277,30 @@ static void drawFunctionOverlay(OLEDDisplay *display, OLEDDisplayUiState *state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if the display can render a string (detect special chars; emoji)
|
||||||
|
static bool haveGlyphs(const char *str)
|
||||||
|
{
|
||||||
|
#if defined(OLED_UA) || defined(OLED_RU)
|
||||||
|
// Don't want to make any assumptions about custom language support
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Check each character with the lookup function for the OLED library
|
||||||
|
// We're not really meant to use this directly..
|
||||||
|
bool have = true;
|
||||||
|
for (uint16_t i = 0; i < strlen(str); i++) {
|
||||||
|
uint8_t result = Screen::customFontTableLookup((uint8_t)str[i]);
|
||||||
|
// If font doesn't support a character, it is substituted for ¿
|
||||||
|
if (result == 191 && (uint8_t)str[i] != 191) {
|
||||||
|
have = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_DEBUG("haveGlyphs=%d\n", have);
|
||||||
|
return have;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_EINK
|
#ifdef USE_EINK
|
||||||
/// Used on eink displays while in deep sleep
|
/// Used on eink displays while in deep sleep
|
||||||
static void drawDeepSleepScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
static void drawDeepSleepScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
||||||
@ -301,14 +325,15 @@ static void drawScreensaverOverlay(OLEDDisplay *display, OLEDDisplayUiState *sta
|
|||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
const char *pauseText = "Screen Paused";
|
const char *pauseText = "Screen Paused";
|
||||||
const char *idText = owner.short_name;
|
const char *idText = owner.short_name;
|
||||||
|
const bool useId = haveGlyphs(idText); // This bool is used to hide the idText box if we can't render the short name
|
||||||
constexpr uint16_t padding = 5;
|
constexpr uint16_t padding = 5;
|
||||||
constexpr uint8_t dividerGap = 1;
|
constexpr uint8_t dividerGap = 1;
|
||||||
constexpr uint8_t imprecision = 5; // How far the box origins can drift from center. Combat burn-in.
|
constexpr uint8_t imprecision = 5; // How far the box origins can drift from center. Combat burn-in.
|
||||||
|
|
||||||
// Dimensions
|
// Dimensions
|
||||||
const uint16_t idTextWidth = display->getStringWidth(idText, strlen(idText));
|
const uint16_t idTextWidth = display->getStringWidth(idText, strlen(idText), true); // "true": handle utf8 chars
|
||||||
const uint16_t pauseTextWidth = display->getStringWidth(pauseText, strlen(pauseText));
|
const uint16_t pauseTextWidth = display->getStringWidth(pauseText, strlen(pauseText));
|
||||||
const uint16_t boxWidth = padding + idTextWidth + padding + padding + pauseTextWidth + padding;
|
const uint16_t boxWidth = padding + (useId ? idTextWidth + padding + padding : 0) + pauseTextWidth + padding;
|
||||||
const uint16_t boxHeight = padding + FONT_HEIGHT_SMALL + padding;
|
const uint16_t boxHeight = padding + FONT_HEIGHT_SMALL + padding;
|
||||||
|
|
||||||
// Position
|
// Position
|
||||||
@ -318,7 +343,7 @@ static void drawScreensaverOverlay(OLEDDisplay *display, OLEDDisplayUiState *sta
|
|||||||
const int16_t boxBottom = boxTop + boxHeight - 1;
|
const int16_t boxBottom = boxTop + boxHeight - 1;
|
||||||
const int16_t idTextLeft = boxLeft + padding;
|
const int16_t idTextLeft = boxLeft + padding;
|
||||||
const int16_t idTextTop = boxTop + padding;
|
const int16_t idTextTop = boxTop + padding;
|
||||||
const int16_t pauseTextLeft = boxLeft + padding + idTextWidth + padding + padding;
|
const int16_t pauseTextLeft = boxLeft + (useId ? padding + idTextWidth + padding : 0) + padding;
|
||||||
const int16_t pauseTextTop = boxTop + padding;
|
const int16_t pauseTextTop = boxTop + padding;
|
||||||
const int16_t dividerX = boxLeft + padding + idTextWidth + padding;
|
const int16_t dividerX = boxLeft + padding + idTextWidth + padding;
|
||||||
const int16_t dividerTop = boxTop + 1 + dividerGap;
|
const int16_t dividerTop = boxTop + 1 + dividerGap;
|
||||||
@ -331,11 +356,13 @@ static void drawScreensaverOverlay(OLEDDisplay *display, OLEDDisplayUiState *sta
|
|||||||
display->drawRect(boxLeft, boxTop, boxWidth, boxHeight);
|
display->drawRect(boxLeft, boxTop, boxWidth, boxHeight);
|
||||||
|
|
||||||
// Draw: Text
|
// Draw: Text
|
||||||
|
if (useId)
|
||||||
display->drawString(idTextLeft, idTextTop, idText);
|
display->drawString(idTextLeft, idTextTop, idText);
|
||||||
display->drawString(pauseTextLeft, pauseTextTop, pauseText);
|
display->drawString(pauseTextLeft, pauseTextTop, pauseText);
|
||||||
display->drawString(pauseTextLeft + 1, pauseTextTop, pauseText); // Faux bold
|
display->drawString(pauseTextLeft + 1, pauseTextTop, pauseText); // Faux bold
|
||||||
|
|
||||||
// Draw: divider
|
// Draw: divider
|
||||||
|
if (useId)
|
||||||
display->drawLine(dividerX, dividerTop, dividerX, dividerBottom);
|
display->drawLine(dividerX, dividerTop, dividerX, dividerBottom);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user