SHA256
ESP32: зафиксировать тесты и нерабочий LVGL/UI вариант
This commit is contained in:
+178
-17
@@ -299,44 +299,187 @@ static String normalizeLogin(const String &value) {
|
||||
return out;
|
||||
}
|
||||
|
||||
static void appendAsciiChar(String &out, char c) {
|
||||
if (c == '\n' || c == '\r' || c == '\t') {
|
||||
out += c;
|
||||
return;
|
||||
}
|
||||
uint8_t uc = (uint8_t)c;
|
||||
if (uc >= 32 && uc <= 126) {
|
||||
out += c;
|
||||
return;
|
||||
}
|
||||
out += '?';
|
||||
}
|
||||
|
||||
static void appendTranslit(String &out, const char *value) {
|
||||
out += value;
|
||||
}
|
||||
|
||||
static void appendUtf8Translit(String &out, uint8_t first, uint8_t second) {
|
||||
if (first == 0xD0) {
|
||||
switch (second) {
|
||||
case 0x81: appendTranslit(out, "Yo"); return;
|
||||
case 0x90: appendTranslit(out, "A"); return;
|
||||
case 0x91: appendTranslit(out, "B"); return;
|
||||
case 0x92: appendTranslit(out, "V"); return;
|
||||
case 0x93: appendTranslit(out, "G"); return;
|
||||
case 0x94: appendTranslit(out, "D"); return;
|
||||
case 0x95: appendTranslit(out, "E"); return;
|
||||
case 0x96: appendTranslit(out, "Zh"); return;
|
||||
case 0x97: appendTranslit(out, "Z"); return;
|
||||
case 0x98: appendTranslit(out, "I"); return;
|
||||
case 0x99: appendTranslit(out, "Y"); return;
|
||||
case 0x9A: appendTranslit(out, "K"); return;
|
||||
case 0x9B: appendTranslit(out, "L"); return;
|
||||
case 0x9C: appendTranslit(out, "M"); return;
|
||||
case 0x9D: appendTranslit(out, "N"); return;
|
||||
case 0x9E: appendTranslit(out, "O"); return;
|
||||
case 0x9F: appendTranslit(out, "P"); return;
|
||||
case 0xA0: appendTranslit(out, "R"); return;
|
||||
case 0xA1: appendTranslit(out, "S"); return;
|
||||
case 0xA2: appendTranslit(out, "T"); return;
|
||||
case 0xA3: appendTranslit(out, "U"); return;
|
||||
case 0xA4: appendTranslit(out, "F"); return;
|
||||
case 0xA5: appendTranslit(out, "Kh"); return;
|
||||
case 0xA6: appendTranslit(out, "Ts"); return;
|
||||
case 0xA7: appendTranslit(out, "Ch"); return;
|
||||
case 0xA8: appendTranslit(out, "Sh"); return;
|
||||
case 0xA9: appendTranslit(out, "Sch"); return;
|
||||
case 0xAA: appendTranslit(out, ""); return;
|
||||
case 0xAB: appendTranslit(out, "Y"); return;
|
||||
case 0xAC: appendTranslit(out, ""); return;
|
||||
case 0xAD: appendTranslit(out, "E"); return;
|
||||
case 0xAE: appendTranslit(out, "Yu"); return;
|
||||
case 0xAF: appendTranslit(out, "Ya"); return;
|
||||
case 0xB0: appendTranslit(out, "a"); return;
|
||||
case 0xB1: appendTranslit(out, "b"); return;
|
||||
case 0xB2: appendTranslit(out, "v"); return;
|
||||
case 0xB3: appendTranslit(out, "g"); return;
|
||||
case 0xB4: appendTranslit(out, "d"); return;
|
||||
case 0xB5: appendTranslit(out, "e"); return;
|
||||
case 0xB6: appendTranslit(out, "zh"); return;
|
||||
case 0xB7: appendTranslit(out, "z"); return;
|
||||
case 0xB8: appendTranslit(out, "i"); return;
|
||||
case 0xB9: appendTranslit(out, "y"); return;
|
||||
case 0xBA: appendTranslit(out, "k"); return;
|
||||
case 0xBB: appendTranslit(out, "l"); return;
|
||||
case 0xBC: appendTranslit(out, "m"); return;
|
||||
case 0xBD: appendTranslit(out, "n"); return;
|
||||
case 0xBE: appendTranslit(out, "o"); return;
|
||||
case 0xBF: appendTranslit(out, "p"); return;
|
||||
default: break;
|
||||
}
|
||||
} else if (first == 0xD1) {
|
||||
switch (second) {
|
||||
case 0x80: appendTranslit(out, "r"); return;
|
||||
case 0x81: appendTranslit(out, "s"); return;
|
||||
case 0x82: appendTranslit(out, "t"); return;
|
||||
case 0x83: appendTranslit(out, "u"); return;
|
||||
case 0x84: appendTranslit(out, "f"); return;
|
||||
case 0x85: appendTranslit(out, "kh"); return;
|
||||
case 0x86: appendTranslit(out, "ts"); return;
|
||||
case 0x87: appendTranslit(out, "ch"); return;
|
||||
case 0x88: appendTranslit(out, "sh"); return;
|
||||
case 0x89: appendTranslit(out, "sch"); return;
|
||||
case 0x8A: appendTranslit(out, ""); return;
|
||||
case 0x8B: appendTranslit(out, "y"); return;
|
||||
case 0x8C: appendTranslit(out, ""); return;
|
||||
case 0x8D: appendTranslit(out, "e"); return;
|
||||
case 0x8E: appendTranslit(out, "yu"); return;
|
||||
case 0x8F: appendTranslit(out, "ya"); return;
|
||||
case 0x91: appendTranslit(out, "yo"); return;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
out += '?';
|
||||
}
|
||||
|
||||
static String toDisplayAscii(const String &text) {
|
||||
String out;
|
||||
out.reserve(text.length() * 2);
|
||||
for (size_t i = 0; i < text.length(); i++) {
|
||||
uint8_t c = (uint8_t)text[i];
|
||||
if (c < 0x80) {
|
||||
appendAsciiChar(out, (char)c);
|
||||
continue;
|
||||
}
|
||||
if ((c == 0xD0 || c == 0xD1) && i + 1 < text.length()) {
|
||||
appendUtf8Translit(out, c, (uint8_t)text[i + 1]);
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
out += '?';
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static uint8_t fontScale(const uint8_t *font) {
|
||||
if (font == (const uint8_t *)FONT_HEAD) {
|
||||
return 2;
|
||||
}
|
||||
if (font == (const uint8_t *)FONT_BODY) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int defaultFontCharWidth(uint8_t scale) {
|
||||
return 6 * scale;
|
||||
}
|
||||
|
||||
static int defaultFontHeight(uint8_t scale) {
|
||||
return 8 * scale;
|
||||
}
|
||||
|
||||
static void setFont(const uint8_t *font) {
|
||||
gfx->setTextSize(1);
|
||||
gfx->setFont(font);
|
||||
gfx->setFont();
|
||||
gfx->setTextSize(fontScale(font));
|
||||
}
|
||||
|
||||
static void drawText(int x, int y, const String &text, uint16_t color, const uint8_t *font = (const uint8_t *)FONT_BODY) {
|
||||
String display = toDisplayAscii(text);
|
||||
setFont(font);
|
||||
gfx->setTextColor(color);
|
||||
gfx->setCursor(x, y);
|
||||
gfx->print(text);
|
||||
gfx->print(display);
|
||||
}
|
||||
|
||||
static void drawTextCentered(int x, int y, int w, int h, const String &text, uint16_t color, const uint8_t *font = (const uint8_t *)FONT_BODY) {
|
||||
String display = toDisplayAscii(text);
|
||||
uint8_t scale = fontScale(font);
|
||||
setFont(font);
|
||||
gfx->setTextColor(color);
|
||||
int16_t x1 = 0;
|
||||
int16_t y1 = 0;
|
||||
uint16_t textW = 0;
|
||||
uint16_t textH = 0;
|
||||
gfx->getTextBounds(text, 0, 0, &x1, &y1, &textW, &textH);
|
||||
int textX = x + (w - (int)textW) / 2 - x1;
|
||||
int textY = y + (h - (int)textH) / 2 - y1;
|
||||
int textW = display.length() * defaultFontCharWidth(scale);
|
||||
int textH = defaultFontHeight(scale);
|
||||
int textX = x + (w - textW) / 2;
|
||||
int textY = y + (h + textH) / 2 - 2;
|
||||
if (textX < x + 6) {
|
||||
textX = x + 6;
|
||||
}
|
||||
gfx->setCursor(textX, textY);
|
||||
gfx->print(text);
|
||||
gfx->print(display);
|
||||
}
|
||||
|
||||
static void drawWrappedText(int x, int y, int maxChars, int lineHeight, const String &text, uint16_t color, const uint8_t *font = (const uint8_t *)FONT_BODY) {
|
||||
String display = toDisplayAscii(text);
|
||||
uint8_t scale = fontScale(font);
|
||||
int effectiveLineHeight = lineHeight;
|
||||
int minLineHeight = defaultFontHeight(scale) + 4;
|
||||
if (effectiveLineHeight < minLineHeight) {
|
||||
effectiveLineHeight = minLineHeight;
|
||||
}
|
||||
setFont(font);
|
||||
gfx->setTextColor(color);
|
||||
String line;
|
||||
int lineY = y;
|
||||
for (size_t i = 0; i < text.length(); i++) {
|
||||
char c = text[i];
|
||||
for (size_t i = 0; i < display.length(); i++) {
|
||||
char c = display[i];
|
||||
if (c == '\n') {
|
||||
gfx->setCursor(x, lineY);
|
||||
gfx->print(line);
|
||||
line = "";
|
||||
lineY += lineHeight;
|
||||
lineY += effectiveLineHeight;
|
||||
continue;
|
||||
}
|
||||
line += c;
|
||||
@@ -344,7 +487,7 @@ static void drawWrappedText(int x, int y, int maxChars, int lineHeight, const St
|
||||
gfx->setCursor(x, lineY);
|
||||
gfx->print(line);
|
||||
line = "";
|
||||
lineY += lineHeight;
|
||||
lineY += effectiveLineHeight;
|
||||
}
|
||||
}
|
||||
if (line.length() > 0) {
|
||||
@@ -466,8 +609,26 @@ static void drawNoticeBox() {
|
||||
if (gNotice.length() == 0) {
|
||||
return;
|
||||
}
|
||||
drawPanel(20, 420, 440, 42, C_CARD, C_BORDER, 10);
|
||||
drawWrappedText(32, 444, 52, 16, gNotice, C_MUTE, (const uint8_t *)FONT_SMALL);
|
||||
const int noticeX = 20;
|
||||
const int noticeW = 440;
|
||||
const int noticeH = 42;
|
||||
int noticeY = 420;
|
||||
for (uint8_t i = 0; i < gButtonCount; i++) {
|
||||
const Button &btn = gButtons[i];
|
||||
bool overlapX = btn.x < (noticeX + noticeW) && (btn.x + btn.w) > noticeX;
|
||||
bool overlapY = btn.y < (noticeY + noticeH) && (btn.y + btn.h) > noticeY;
|
||||
if (overlapX && overlapY) {
|
||||
int candidateY = btn.y - noticeH - 6;
|
||||
if (candidateY < noticeY) {
|
||||
noticeY = candidateY;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (noticeY < 82) {
|
||||
noticeY = 82;
|
||||
}
|
||||
drawPanel(noticeX, noticeY, noticeW, noticeH, C_CARD, C_BORDER, 10);
|
||||
drawWrappedText(noticeX + 12, noticeY + 24, 52, 16, gNotice, C_MUTE, (const uint8_t *)FONT_SMALL);
|
||||
}
|
||||
|
||||
static const char *base58Alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||
|
||||
Reference in New Issue
Block a user