Skip to content

Commit c2e5441

Browse files
authored
Merge branch 'master' into rak_wismeshtag
2 parents 98e0a73 + beba1b4 commit c2e5441

37 files changed

+4009
-966
lines changed

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ lib_deps =
108108
[device-ui_base]
109109
lib_deps =
110110
# renovate: datasource=git-refs depName=meshtastic/device-ui packageName=https://github.com/meshtastic/device-ui gitBranch=master
111-
https://github.com/meshtastic/device-ui/archive/c9a55f661a735d1f393a02657e5183ccf39cf1a2.zip
111+
https://github.com/meshtastic/device-ui/archive/405ca495322b7dc3b61f7588d28267d49b2ebc38.zip
112112

113113
; Common libs for environmental measurements in telemetry module
114114
[environmental_base]

src/graphics/niche/Fonts/FreeSans6pt7b.h

Lines changed: 193 additions & 124 deletions
Large diffs are not rendered by default.

src/graphics/niche/Fonts/FreeSans6pt8bCyrillic.h

Lines changed: 0 additions & 302 deletions
This file was deleted.

src/graphics/niche/Fonts/FreeSans6pt_Win1250.h

Lines changed: 457 additions & 0 deletions
Large diffs are not rendered by default.

src/graphics/niche/Fonts/FreeSans6pt_Win1251.h

Lines changed: 457 additions & 0 deletions
Large diffs are not rendered by default.

src/graphics/niche/Fonts/FreeSans6pt_Win1252.h

Lines changed: 457 additions & 0 deletions
Large diffs are not rendered by default.

src/graphics/niche/Fonts/FreeSans9pt_Win1250.h

Lines changed: 494 additions & 0 deletions
Large diffs are not rendered by default.

src/graphics/niche/Fonts/FreeSans9pt_Win1251.h

Lines changed: 493 additions & 0 deletions
Large diffs are not rendered by default.

src/graphics/niche/Fonts/FreeSans9pt_Win1252.h

Lines changed: 494 additions & 0 deletions
Large diffs are not rendered by default.

src/graphics/niche/InkHUD/Applet.cpp

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -263,22 +263,10 @@ uint16_t InkHUD::Applet::Y(float f)
263263
// Print text, specifying the position of any edge / corner of the textbox
264264
void InkHUD::Applet::printAt(int16_t x, int16_t y, const char *text, HorizontalAlignment ha, VerticalAlignment va)
265265
{
266-
printAt(x, y, std::string(text), ha, va);
267-
}
268-
269-
// Print text, specifying the position of any edge / corner of the textbox
270-
void InkHUD::Applet::printAt(int16_t x, int16_t y, std::string text, HorizontalAlignment ha, VerticalAlignment va)
271-
{
272-
// Custom font
273-
// - set with AppletFont::addSubstitution
274-
// - find certain UTF8 chars
275-
// - replace with glyph from custom font (or suitable ASCII addSubstitution?)
276-
getFont().applySubstitutions(&text);
277-
278266
// We do still have to run getTextBounds to find the width
279267
int16_t textOffsetX, textOffsetY;
280268
uint16_t textWidth, textHeight;
281-
getTextBounds(text.c_str(), 0, 0, &textOffsetX, &textOffsetY, &textWidth, &textHeight);
269+
getTextBounds(text, 0, 0, &textOffsetX, &textOffsetY, &textWidth, &textHeight);
282270

283271
int16_t cursorX = 0;
284272
int16_t cursorY = 0;
@@ -310,7 +298,13 @@ void InkHUD::Applet::printAt(int16_t x, int16_t y, std::string text, HorizontalA
310298
}
311299

312300
setCursor(cursorX, cursorY);
313-
print(text.c_str());
301+
print(text);
302+
}
303+
304+
// Print text, specifying the position of any edge / corner of the textbox
305+
void InkHUD::Applet::printAt(int16_t x, int16_t y, std::string text, HorizontalAlignment ha, VerticalAlignment va)
306+
{
307+
printAt(x, y, text.c_str(), ha, va);
314308
}
315309

316310
// Set which font should be used for subsequent drawing
@@ -328,11 +322,52 @@ InkHUD::AppletFont InkHUD::Applet::getFont()
328322
return currentFont;
329323
}
330324

325+
// Parse any text which might have "special characters"
326+
// Re-encodes UTF-8 characters to match our 8-bit encoded fonts
327+
std::string InkHUD::Applet::parse(std::string text)
328+
{
329+
return getFont().decodeUTF8(text);
330+
}
331+
332+
// Get the best version of a node's short name available to us
333+
// Parses any non-ascii chars
334+
// Swaps for last-four of node-id if the real short name is unknown or can't be rendered (emoji)
335+
std::string InkHUD::Applet::parseShortName(meshtastic_NodeInfoLite *node)
336+
{
337+
assert(node);
338+
339+
// Use the true shortname if known, and doesn't contain any unprintable characters (emoji, etc.)
340+
if (node->has_user) {
341+
std::string parsed = parse(node->user.short_name);
342+
if (isPrintable(parsed))
343+
return parsed;
344+
}
345+
346+
// Otherwise, use the "last 4" of node id
347+
// - if short name unknown, or
348+
// - if short name is emoji (we can't render this)
349+
std::string nodeID = hexifyNodeNum(node->num);
350+
return nodeID.substr(nodeID.length() - 4);
351+
}
352+
353+
// Determine if all characters of a string are printable using the current font
354+
bool InkHUD::Applet::isPrintable(std::string text)
355+
{
356+
// Scan for DEL (0x7F), which is the value assigned by AppletFont::applyEncoding if a unicode character is not handled
357+
// Todo: move this to from DEL to SUB, once the fonts have been changed for this
358+
for (char &c : text) {
359+
if (c == '\x7F')
360+
return false;
361+
}
362+
363+
// No unprintable characters found
364+
return true;
365+
}
366+
331367
// Gets rendered width of a string
332368
// Wrapper for getTextBounds
333369
uint16_t InkHUD::Applet::getTextWidth(const char *text)
334370
{
335-
336371
// We do still have to run getTextBounds to find the width
337372
int16_t textOffsetX, textOffsetY;
338373
uint16_t textWidth, textHeight;
@@ -345,8 +380,6 @@ uint16_t InkHUD::Applet::getTextWidth(const char *text)
345380
// Wrapper for getTextBounds
346381
uint16_t InkHUD::Applet::getTextWidth(std::string text)
347382
{
348-
getFont().applySubstitutions(&text);
349-
350383
return getTextWidth(text.c_str());
351384
}
352385

@@ -395,12 +428,6 @@ std::string InkHUD::Applet::hexifyNodeNum(NodeNum num)
395428
// Avoids splitting words in half, instead moving the entire word to a new line wherever possible
396429
void InkHUD::Applet::printWrapped(int16_t left, int16_t top, uint16_t width, std::string text)
397430
{
398-
// Custom font glyphs
399-
// - set with AppletFont::addSubstitution
400-
// - find certain UTF8 chars
401-
// - replace with glyph from custom font (or suitable ASCII addSubstitution?)
402-
getFont().applySubstitutions(&text);
403-
404431
// Place the AdafruitGFX cursor to suit our "top" coord
405432
setCursor(left, top + getFont().heightAboveCursor());
406433

src/graphics/niche/InkHUD/Applet.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,15 @@ class Applet : public GFX
133133
void drawLogo(int16_t centerX, int16_t centerY, uint16_t width, uint16_t height,
134134
Color color = BLACK); // Draw the Meshtastic logo
135135

136-
std::string hexifyNodeNum(NodeNum num); // Style as !0123abdc
137-
SignalStrength getSignalStrength(float snr, float rssi); // Interpret SNR and RSSI, as an easy to understand value
138-
std::string getTimeString(uint32_t epochSeconds); // Human readable
139-
std::string getTimeString(); // Current time, human readable
140-
uint16_t getActiveNodeCount(); // Duration determined by user, in onscreen menu
141-
std::string localizeDistance(uint32_t meters); // Human readable distance, imperial or metric
136+
std::string hexifyNodeNum(NodeNum num); // Style as !0123abdc
137+
SignalStrength getSignalStrength(float snr, float rssi); // Interpret SNR and RSSI, as an easy to understand value
138+
std::string getTimeString(uint32_t epochSeconds); // Human readable
139+
std::string getTimeString(); // Current time, human readable
140+
uint16_t getActiveNodeCount(); // Duration determined by user, in onscreen menu
141+
std::string localizeDistance(uint32_t meters); // Human readable distance, imperial or metric
142+
std::string parse(std::string text); // Handle text which might contain special chars
143+
std::string parseShortName(meshtastic_NodeInfoLite *node); // Get the shortname, or a substitute if has unprintable chars
144+
bool isPrintable(std::string); // Check for characters which the font can't print
142145

143146
// Convenient references
144147

0 commit comments

Comments
 (0)