diff --git a/examples/companion_radio/ui-tiny/UITask.cpp b/examples/companion_radio/ui-tiny/UITask.cpp index b6bdbcf4..01fc59ac 100644 --- a/examples/companion_radio/ui-tiny/UITask.cpp +++ b/examples/companion_radio/ui-tiny/UITask.cpp @@ -154,13 +154,13 @@ public: char tmp[80]; if (_page == HomePage::FIRST) { - // // node name - // display.setTextSize(1); - // display.setColor(DisplayDriver::GREEN); - // char filtered_name[sizeof(_node_prefs->node_name)]; - // display.translateUTF8ToBlocks(filtered_name, _node_prefs->node_name, sizeof(filtered_name)); - // display.setCursor(0, 0); - // display.print(filtered_name); + // node name + display.setTextSize(1); + display.setColor(UIColor::primary_txt); + char filtered_name[sizeof(_node_prefs->node_name)]; + display.translateUTF8ToBlocks(filtered_name, _node_prefs->node_name, sizeof(filtered_name)); + display.setCursor(0, 0); + display.print(filtered_name); display.setColor(UIColor::primary_txt); diff --git a/examples/simple_repeater/UITask.cpp b/examples/simple_repeater/UITask.cpp index e7225557..fe1c8103 100644 --- a/examples/simple_repeater/UITask.cpp +++ b/examples/simple_repeater/UITask.cpp @@ -95,7 +95,9 @@ void UITask::renderCurrScreen() { _display->setCursor(0, 0); _display->setTextSize(1); _display->setColor(UIColor::primary_txt); - _display->print(_node_prefs->node_name); + char filtered_name[sizeof(_node_prefs->node_name)]; + _display->translateUTF8ToBlocks(filtered_name, _node_prefs->node_name, sizeof(filtered_name)); + _display->print(filtered_name); // freq / sf _display->setCursor(0, 20); diff --git a/examples/simple_room_server/UITask.cpp b/examples/simple_room_server/UITask.cpp index 8e4c2fcf..1c283bdc 100644 --- a/examples/simple_room_server/UITask.cpp +++ b/examples/simple_room_server/UITask.cpp @@ -77,7 +77,9 @@ void UITask::renderCurrScreen() { _display->setCursor(0, 0); _display->setTextSize(1); _display->setColor(UIColor::primary_txt); - _display->print(_node_prefs->node_name); + char filtered_name[sizeof(_node_prefs->node_name)]; + _display->translateUTF8ToBlocks(filtered_name, _node_prefs->node_name, sizeof(filtered_name)); + _display->print(filtered_name); // freq / sf _display->setCursor(0, 20); diff --git a/examples/simple_sensor/UITask.cpp b/examples/simple_sensor/UITask.cpp index 75a0b465..391c305e 100644 --- a/examples/simple_sensor/UITask.cpp +++ b/examples/simple_sensor/UITask.cpp @@ -77,7 +77,9 @@ void UITask::renderCurrScreen() { _display->setCursor(0, 0); _display->setTextSize(1); _display->setColor(UIColor::primary_txt); - _display->print(_node_prefs->node_name); + char filtered_name[sizeof(_node_prefs->node_name)]; + _display->translateUTF8ToBlocks(filtered_name, _node_prefs->node_name, sizeof(filtered_name)); + _display->print(filtered_name); // freq / sf _display->setCursor(0, 20); diff --git a/src/helpers/ui/DisplayDriver.h b/src/helpers/ui/DisplayDriver.h index 0dbe3b47..5cf21684 100644 --- a/src/helpers/ui/DisplayDriver.h +++ b/src/helpers/ui/DisplayDriver.h @@ -59,6 +59,9 @@ public: char cc = 0; #endif for (size_t i = 0; src[i] != 0 && j < dest_size - 1; i++) { +#ifdef OLED_RU + cc = 0; // сброс на каждом символе: иначе нераспознанный код повторит предыдущую букву +#endif unsigned char c = (unsigned char)src[i]; if (c >= 32 && c <= 126) { #ifdef OLED_RU @@ -109,7 +112,7 @@ public: break; } } - if (cc > 0) { + if (cc != 0) { dest[j++] = cc; } else { dest[j++] = '\xAE'; // CP1251 smile emoji replace diff --git a/src/helpers/ui/SH1106Display.cpp b/src/helpers/ui/SH1106Display.cpp index c9b41171..fa37b19c 100644 --- a/src/helpers/ui/SH1106Display.cpp +++ b/src/helpers/ui/SH1106Display.cpp @@ -67,11 +67,14 @@ void SH1106Display::startFrame(ColorVal bkg) display.clearDisplay(); // TODO: apply 'bkg' _color = SH110X_WHITE; #ifdef OLED_RU + // glcdfont6x8 несёт карту CP1251, поэтому CP437 не нужен (он действует + // только для встроенного шрифта Adafruit) display.setFont(&glcdfont6x8); +#else + display.cp437(true); // встроенный шрифт: полный Code Page 437 (нужен для █ 0xDB) #endif display.setTextColor(_color); - display.setTextSize(1); - display.cp437(true); // Use full 256 char 'Code Page 437' font + setTextSize(1); // через свой override, чтобы _size не разъезжался #ifdef OLED_RU display.setCursor(0, 7); #endif diff --git a/src/helpers/ui/SSD1306Display.cpp b/src/helpers/ui/SSD1306Display.cpp index 4c3b302c..4caa763b 100644 --- a/src/helpers/ui/SSD1306Display.cpp +++ b/src/helpers/ui/SSD1306Display.cpp @@ -62,11 +62,14 @@ void SSD1306Display::startFrame(ColorVal bkg) { display.clearDisplay(); // TODO: apply 'bkg' _color = SSD1306_WHITE; #ifdef OLED_RU + // glcdfont6x8 несёт карту CP1251, поэтому CP437 не нужен (он действует + // только для встроенного шрифта Adafruit) display.setFont(&glcdfont6x8); +#else + display.cp437(true); // встроенный шрифт: полный Code Page 437 (нужен для █ 0xDB) #endif display.setTextColor(_color); - display.setTextSize(1); - display.cp437(true); // Use full 256 char 'Code Page 437' font + setTextSize(1); // через свой override, чтобы _size не разъезжался #ifdef OLED_RU display.setCursor(0, 7); #endif diff --git a/src/helpers/ui/ST7735Display.cpp b/src/helpers/ui/ST7735Display.cpp index 13dde16f..99eafaee 100644 --- a/src/helpers/ui/ST7735Display.cpp +++ b/src/helpers/ui/ST7735Display.cpp @@ -627,14 +627,19 @@ void ST7735Display::clear() { void ST7735Display::startFrame(ColorVal bkg) { sprite->fillScreen(bkg); sprite->setTextColor(curr_color = UIColor::primary_txt); - sprite->setFreeFont(); - #ifdef OLED_RU +#ifdef OLED_RU + // Шрифт ставим один раз: setFreeFont() пересчитывает метрики glyph_ab/glyph_bb + // по всем 224 глифам, а шрифт между кадрами не меняется + if (!_ru_font) { sprite->setFreeFont(&glcdfont6x8); - #endif - sprite->setTextSize(1); // This one affects size of Please wait... message - //sprite->cp437(true); // Use full 256 char 'Code Page 437' font - sprite->setAttribute(CP437_SWITCH, true); - sprite->setAttribute(UTF8_SWITCH, false); + _ru_font = true; + } +#else + sprite->setFreeFont(); + sprite->setAttribute(CP437_SWITCH, true); // встроенный шрифт: полный CP437 +#endif + sprite->setAttribute(UTF8_SWITCH, false); // байты приходят уже в CP1251/ASCII + setTextSize(1); // This one affects size of Please wait... message #ifdef OLED_RU sprite->setCursor(0, 7); #endif diff --git a/src/helpers/ui/ST7735Display.h b/src/helpers/ui/ST7735Display.h index 1575a114..8643fd63 100644 --- a/src/helpers/ui/ST7735Display.h +++ b/src/helpers/ui/ST7735Display.h @@ -11,6 +11,7 @@ class ST7735Display : public DisplayDriver { RefCountedDigitalPin* _peripher_power; #ifdef OLED_RU uint8_t _size; + bool _ru_font; #endif bool i2c_probe(TwoWire& wire, uint8_t addr); @@ -23,6 +24,7 @@ public: _isOn = false; #ifdef OLED_RU _size = 1; + _ru_font = false; #endif } #else @@ -33,6 +35,7 @@ public: _isOn = false; #ifdef OLED_RU _size = 1; + _ru_font = false; #endif } #endif diff --git a/src/helpers/ui/ST7789LCDDisplay.cpp b/src/helpers/ui/ST7789LCDDisplay.cpp index a9f30dd5..e259a252 100644 --- a/src/helpers/ui/ST7789LCDDisplay.cpp +++ b/src/helpers/ui/ST7789LCDDisplay.cpp @@ -1,4 +1,7 @@ #include "ST7789LCDDisplay.h" +#ifdef OLED_RU + #include "glcdfont6x8.h" +#endif #ifndef PIN_TFT_MISO #define PIN_TFT_MISO -1 @@ -56,7 +59,9 @@ bool ST7789LCDDisplay::begin() { display.fillScreen(ST77XX_BLACK); display.setTextColor(ST77XX_WHITE); display.setTextSize(2 * DISPLAY_SCALE_X); +#ifndef OLED_RU display.cp437(true); // Use full 256 char 'Code Page 437' font +#endif _isOn = true; } @@ -92,12 +97,23 @@ void ST7789LCDDisplay::clear() { void ST7789LCDDisplay::startFrame(ColorVal bkg) { display.fillScreen(bkg); display.setTextColor(_color = UIColor::primary_txt); - display.setTextSize(1 * DISPLAY_SCALE_X); // This one affects size of Please wait... message +#ifdef OLED_RU + // glcdfont6x8 несёт карту CP1251; CP437 действует только для встроенного шрифта + if (!_ru_font) { + display.setFont(&glcdfont6x8); + _ru_font = true; + } +#else display.cp437(true); // Use full 256 char 'Code Page 437' font +#endif + setTextSize(1); // This one affects size of Please wait... message } void ST7789LCDDisplay::setTextSize(int sz) { display.setTextSize(sz * DISPLAY_SCALE_X); +#ifdef OLED_RU + _size = sz; +#endif } void ST7789LCDDisplay::setColor(ColorVal c) { @@ -105,7 +121,14 @@ void ST7789LCDDisplay::setColor(ColorVal c) { } void ST7789LCDDisplay::setCursor(int x, int y) { +#ifdef OLED_RU + // Кастомный шрифт Adafruit рисуется от базовой линии: глиф поднят над ней + // на 7 * фактический размер (setTextSize выше округляет sz * DISPLAY_SCALE_X) + int px_size = (int)(_size * DISPLAY_SCALE_X); + display.setCursor(x * DISPLAY_SCALE_X, y * DISPLAY_SCALE_Y + 7 * px_size); +#else display.setCursor(x * DISPLAY_SCALE_X, y * DISPLAY_SCALE_Y); +#endif } void ST7789LCDDisplay::print(const char* str) { diff --git a/src/helpers/ui/ST7789LCDDisplay.h b/src/helpers/ui/ST7789LCDDisplay.h index b5127d35..1adf9237 100644 --- a/src/helpers/ui/ST7789LCDDisplay.h +++ b/src/helpers/ui/ST7789LCDDisplay.h @@ -15,6 +15,10 @@ class ST7789LCDDisplay : public DisplayDriver { bool _isOn; uint16_t _color; RefCountedDigitalPin* _peripher_power; +#ifdef OLED_RU + uint8_t _size; + bool _ru_font; +#endif bool i2c_probe(TwoWire& wire, uint8_t addr); public: @@ -24,6 +28,10 @@ public: _peripher_power(peripher_power) { _isOn = false; +#ifdef OLED_RU + _size = 1; + _ru_font = false; +#endif } #elif defined(LILYGO_TDECK) || defined(HELTEC_LORA_V4_TFT) || defined(HELTEC_V4_R8_TFT) ST7789LCDDisplay(RefCountedDigitalPin* peripher_power=NULL) : DisplayDriver(128, 64), @@ -32,6 +40,10 @@ public: _peripher_power(peripher_power) { _isOn = false; +#ifdef OLED_RU + _size = 1; + _ru_font = false; +#endif } #else ST7789LCDDisplay(RefCountedDigitalPin* peripher_power=NULL) : DisplayDriver(128, 64), @@ -39,6 +51,10 @@ public: _peripher_power(peripher_power) { _isOn = false; +#ifdef OLED_RU + _size = 1; + _ru_font = false; +#endif } #endif bool begin(); diff --git a/src/helpers/ui/glcdfont6x8.h b/src/helpers/ui/glcdfont6x8.h index 7c634023..1aaad8a0 100644 --- a/src/helpers/ui/glcdfont6x8.h +++ b/src/helpers/ui/glcdfont6x8.h @@ -1,4 +1,6 @@ // Adafruit GFX font font size: 6x8 +// Кодировка карты глифов — CP1251 (0xC0-0xFF: А-Я, а-я; 0xA5/0xA8/0xAA/0xAF/0xB2/0xB8/0xBA/0xBF: Ґ/Ё/Є/Ї/і/ё/є/ї). +#pragma once const uint8_t glcdfont6x8Bitmaps[] PROGMEM = { 0x00,0x00,0x00,0x00,0x00,0x00, // 32