diff --git a/firmware/layout2.c b/firmware/layout2.c index 6ea2b0a..739c233 100644 --- a/firmware/layout2.c +++ b/firmware/layout2.c @@ -252,9 +252,9 @@ void layoutAddress(const char *address) oledDrawString(68, 3 * 9, str[3]); static const char *btnYes = "Continue"; - oledDrawString(OLED_WIDTH - fontCharWidth('\xff') - 1, OLED_HEIGHT - 8, "\xff"); - oledDrawString(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\xff') - 3, OLED_HEIGHT - 8, btnYes); - oledInvert(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\xff') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1); + oledDrawString(OLED_WIDTH - fontCharWidth('\x06') - 1, OLED_HEIGHT - 8, "\x06"); + oledDrawString(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 3, OLED_HEIGHT - 8, btnYes); + oledInvert(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1); oledRefresh(); } diff --git a/gen/fonts.c b/gen/fonts.c index af05044..a82be16 100644 --- a/gen/fonts.c +++ b/gen/fonts.c @@ -7,7 +7,7 @@ const uint8_t *font_data[256] = { /* 0x03 _ */ (uint8_t *)"\x01\x00", /* 0x04 _ */ (uint8_t *)"\x01\x00", /* 0x05 _ */ (uint8_t *)"\x01\x00", - /* 0x06 _ */ (uint8_t *)"\x01\x00", + /* 0x06 _ */ (uint8_t *)"\x07\x18\x1c\x0e\x18\x30\x40\x80", /* 0x07 _ */ (uint8_t *)"\x01\x00", /* 0x08 _ */ (uint8_t *)"\x01\x00", /* 0x09 _ */ (uint8_t *)"\x01\x00", @@ -22,7 +22,7 @@ const uint8_t *font_data[256] = { /* 0x12 _ */ (uint8_t *)"\x01\x00", /* 0x13 _ */ (uint8_t *)"\x01\x00", /* 0x14 _ */ (uint8_t *)"\x01\x00", - /* 0x15 _ */ (uint8_t *)"\x01\x00", + /* 0x15 _ */ (uint8_t *)"\x07\x44\xee\x7c\x38\x7c\xee\x44", /* 0x16 _ */ (uint8_t *)"\x01\x00", /* 0x17 _ */ (uint8_t *)"\x01\x00", /* 0x18 _ */ (uint8_t *)"\x01\x00", @@ -255,8 +255,8 @@ const uint8_t *font_data[256] = { /* 0xfb _ */ (uint8_t *)"\x01\x00", /* 0xfc _ */ (uint8_t *)"\x01\x00", /* 0xfd _ */ (uint8_t *)"\x01\x00", - /* 0xfe _ */ (uint8_t *)"\x07\x44\xee\x7c\x38\x7c\xee\x44", - /* 0xff _ */ (uint8_t *)"\x07\x18\x1c\x0e\x18\x30\x40\x80", + /* 0xfe _ */ (uint8_t *)"\x01\x00", + /* 0xff _ */ (uint8_t *)"\x01\x00", }; int fontCharWidth(char c) { diff --git a/gen/fonts/font.png b/gen/fonts/font.png index 9537b46..b78c093 100644 Binary files a/gen/fonts/font.png and b/gen/fonts/font.png differ diff --git a/gen/fonts/generate.py b/gen/fonts/generate.py index c50765d..3bd5b8e 100755 --- a/gen/fonts/generate.py +++ b/gen/fonts/generate.py @@ -20,15 +20,15 @@ class Img(object): img = Img('font.png') cur = '' -idx = 0 -for i in range(img.w): - if img.pixel(i, 0) == None: - cur = '\\x%02x' % (len(cur) / 4) + cur - ch = chr(idx) if idx >= 32 and idx <= 126 else '_' - print '\t/* 0x%02x %c */ (uint8_t *)"%s",' % (idx, ch , cur) - cur = '' - idx += 1 - continue - val = img.pixel(i, 0) + img.pixel(i, 1) + img.pixel(i, 2) + img.pixel(i, 3) + img.pixel(i, 4) + img.pixel(i, 5) + img.pixel(i, 6) + img.pixel(i, 7) - cur += '\\x%02x' % int(val, 2) +for i in range(256): + x = (i % 16) * 10 + y = (i / 16) * 10 + cur = '' + while img.pixel(x, y) != None: + val = ''.join(img.pixel(x, y + j) for j in range(8)) + x += 1 + cur += '\\x%02x' % int(val, 2) + cur = '\\x%02x' % (len(cur) / 4) + cur + ch = chr(i) if i >= 32 and i <= 126 else '_' + print '\t/* 0x%02x %c */ (uint8_t *)"%s",' % (i, ch , cur) diff --git a/layout.c b/layout.c index 2d7f277..7848b49 100644 --- a/layout.c +++ b/layout.c @@ -67,14 +67,14 @@ void layoutDialog(LayoutDialogIcon icon, const char *btnNo, const char *btnYes, } } if (btnNo) { - oledDrawString(1, OLED_HEIGHT - 8, "\xfe"); - oledDrawString(fontCharWidth('\xfe') + 3, OLED_HEIGHT - 8, btnNo); - oledInvert(0, OLED_HEIGHT - 9, fontCharWidth('\xfe') + oledStringWidth(btnNo) + 2, OLED_HEIGHT - 1); + oledDrawString(1, OLED_HEIGHT - 8, "\x15"); + oledDrawString(fontCharWidth('\x15') + 3, OLED_HEIGHT - 8, btnNo); + oledInvert(0, OLED_HEIGHT - 9, fontCharWidth('\x15') + oledStringWidth(btnNo) + 2, OLED_HEIGHT - 1); } if (btnYes) { - oledDrawString(OLED_WIDTH - fontCharWidth('\xff') - 1, OLED_HEIGHT - 8, "\xff"); - oledDrawString(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\xff') - 3, OLED_HEIGHT - 8, btnYes); - oledInvert(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\xff') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1); + oledDrawString(OLED_WIDTH - fontCharWidth('\x06') - 1, OLED_HEIGHT - 8, "\x06"); + oledDrawString(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 3, OLED_HEIGHT - 8, btnYes); + oledInvert(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1); } oledRefresh(); } diff --git a/oled.c b/oled.c index 00405c0..6b3ef56 100644 --- a/oled.c +++ b/oled.c @@ -207,11 +207,25 @@ void oledDrawChar(int x, int y, char c) } } +char oledConvertChar(const char c) { + uint8_t a = c; + if (a < 0x80) return c; + // UTF-8 handling: https://en.wikipedia.org/wiki/UTF-8#Description + // bytes 11xxxxxx are first byte of UTF-8 characters + // bytes 10xxxxxx are successive UTF-8 characters + if (a >= 0xC0) return '_'; + return 0; +} + int oledStringWidth(const char *text) { if (!text) return 0; int l = 0; + char c; for (; *text; text++) { - l += fontCharWidth(*text) + 1; + c = oledConvertChar(*text); + if (c) { + l += fontCharWidth(c) + 1; + } } return l; } @@ -220,9 +234,13 @@ void oledDrawString(int x, int y, const char* text) { if (!text) return; int l = 0; + char c; for (; *text; text++) { - oledDrawChar(x + l, y, *text); - l += fontCharWidth(*text) + 1; + c = oledConvertChar(*text); + if (c) { + oledDrawChar(x + l, y, c); + l += fontCharWidth(c) + 1; + } } }