Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/companion_radio/ui-new/UITask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ class SplashScreen : public UIScreen {
display.drawTextCentered(display.width()/2, 22, _version_info);

display.setTextSize(1);
#ifdef OLED_RU
char filtered_date[sizeof(FIRMWARE_BUILD_DATE)];
display.translateUTF8ToBlocks(filtered_date, FIRMWARE_BUILD_DATE, sizeof(filtered_date));
display.drawTextCentered(display.width()/2, 42, filtered_date);
#else
display.drawTextCentered(display.width()/2, 42, FIRMWARE_BUILD_DATE);
#endif

return 1000;
}
Expand Down
63 changes: 63 additions & 0 deletions src/helpers/ui/DisplayDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,75 @@ class DisplayDriver {
// convert UTF-8 characters to displayable block characters for compatibility
virtual void translateUTF8ToBlocks(char* dest, const char* src, size_t dest_size) {
size_t j = 0;
#ifdef OLED_RU
char last_char = 0;
char cc = 0;
#endif
for (size_t i = 0; src[i] != 0 && j < dest_size - 1; i++) {
unsigned char c = (unsigned char)src[i];
if (c >= 32 && c <= 126) {
#ifdef OLED_RU
last_char = 0;
dest[j++] = c; // ASCII printable
} else if (c == 0xC2 || c == 0xC3 || c == 0xD0 || c == 0xD1 || c == 0xD2) { // Cyrillic UTF-8 convert
last_char = c;
c = src[++i]; // Get next char

if (c != 0) { // Not end of a string
switch (last_char) {
case 0xC3: {
cc = (c | 0xC0);
break;
}
// map UTF-8 cyrillic cars to it Windows-1251 (CP-1251) ASCII codes
case 0xD0: {
if (c == 132)
cc = (170); // Є
if (c == 134)
cc = (178); // І
if (c == 135)
cc = (175); // Ї
if (c == 129)
cc = (168); // Ё
if (c > 143 && c < 192)
cc = (c + 48);
break;
}
case 0xD1: {
if (c == 148)
cc = (186); // є
if (c == 150)
cc = (179); // і
if (c == 151)
cc = (191); // ї
if (c == 145)
cc = (184); // ё
if (c > 127 && c < 144)
cc = (c + 112);
break;
}
case 0xD2: {
if (c == 144)
cc = (165); // Ґ
if (c == 145)
cc = (180); // ґ
break;
}
}
if (cc > 0) {
dest[j++] = cc;
} else {
dest[j++] = '\xAE'; // CP1251 smile emoji replace
}
}
} else if (c >= 0x80) {
last_char = 0;
dest[j++] = '\xAE'; // CP1251 smile emoji replace
#else
dest[j++] = c; // ASCII printable
} else if (c >= 0x80) {
dest[j++] = '\xDB'; // CP437 full block █
#endif
while (src[i+1] && (src[i+1] & 0xC0) == 0x80)
i++; // skip UTF-8 continuation bytes
}
Expand Down
16 changes: 16 additions & 0 deletions src/helpers/ui/SSD1306Display.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "SSD1306Display.h"
#ifdef OLED_RU
#include "glcdfont6x8.h"
#endif

bool SSD1306Display::i2c_probe(TwoWire& wire, uint8_t addr) {
wire.beginTransmission(addr);
Expand Down Expand Up @@ -31,13 +34,22 @@ void SSD1306Display::clear() {
void SSD1306Display::startFrame(Color bkg) {
display.clearDisplay(); // TODO: apply 'bkg'
_color = SSD1306_WHITE;
#ifdef OLED_RU
display.setFont(&glcdfont6x8);
#endif
display.setTextColor(_color);
display.setTextSize(1);
display.cp437(true); // Use full 256 char 'Code Page 437' font
#ifdef OLED_RU
display.setCursor(0, 7);
#endif
}

void SSD1306Display::setTextSize(int sz) {
display.setTextSize(sz);
#ifdef OLED_RU
_size = sz;
#endif
}

void SSD1306Display::setColor(Color c) {
Expand All @@ -46,7 +58,11 @@ void SSD1306Display::setColor(Color c) {
}

void SSD1306Display::setCursor(int x, int y) {
#ifdef OLED_RU
display.setCursor(x, y + (_size * 7));
#else
display.setCursor(x, y);
#endif
}

void SSD1306Display::print(const char* str) {
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/ui/SSD1306Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class SSD1306Display : public DisplayDriver {
Adafruit_SSD1306 display;
bool _isOn;
uint8_t _color;
#ifdef OLED_RU
uint8_t _size;
#endif

bool i2c_probe(TwoWire& wire, uint8_t addr);
public:
Expand Down
Loading