Fixed #154 - Cleaned up UTF-8 conversion, tweaked screen.cpp to replace a hardcoded constant
pull/223/head^2
Kevin Hester 2020-06-24 08:22:29 -07:00 zatwierdzone przez GitHub
commit caafddfdfa
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 35 dodań i 1 usunięć

Wyświetl plik

@ -514,6 +514,9 @@ void Screen::setup()
// Store a pointer to Screen so we can get to it from static functions.
ui.getUiState()->userData = this;
// Set the utf8 conversion function
dispdev.setFontTableLookupFunction(customFontTableLookup);
// Add frames.
static FrameCallback bootFrames[] = {drawBootScreen};
static const int bootFrameCount = sizeof(bootFrames) / sizeof(bootFrames[0]);
@ -720,7 +723,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
}
const char *fields[] = {channelStr, nullptr};
uint32_t yo = drawRows(display, x, y + 12, fields);
uint32_t yo = drawRows(display, x, y + FONT_HEIGHT, fields);
display->drawLogBuffer(x, yo);
}

Wyświetl plik

@ -149,6 +149,37 @@ class Screen : public PeriodicTask
}
}
/// Overrides the default utf8 character conversion, to replace empty space with question marks
static char customFontTableLookup(const uint8_t ch) {
// UTF-8 to font table index converter
// Code form http://playground.arduino.cc/Main/Utf8ascii
static uint8_t LASTCHAR;
static bool SKIPREST; // Only display a single unconvertable-character symbol per sequence of unconvertable characters
if (ch < 128) { // Standard ASCII-set 0..0x7F handling
LASTCHAR = 0;
SKIPREST = false;
return ch;
}
uint8_t last = LASTCHAR; // get last char
LASTCHAR = ch;
switch (last) { // conversion depnding on first UTF8-character
case 0xC2: { SKIPREST = false; return (uint8_t) ch; }
case 0xC3: { SKIPREST = false; return (uint8_t) (ch | 0xC0); }
}
// We want to strip out prefix chars for two-byte char formats
if (ch == 0xC2 || ch == 0xC3 || ch == 0x82) return (uint8_t) 0;
// If we already returned an unconvertable-character symbol for this unconvertable-character sequence, return NULs for the rest of it
if (SKIPREST) return (uint8_t) 0;
SKIPREST = true;
return (uint8_t) 191; // otherwise: return ¿ if character can't be converted (note that the font map we're using doesn't stick to standard EASCII codes)
}
/// Returns a handle to the DebugInfo screen.
//
// Use this handle to set things like battery status, user count, GPS status, etc.