aboutsummaryrefslogtreecommitdiff
path: root/lcdprint.cpp
diff options
context:
space:
mode:
authorDmitry Mikhirev2014-10-23 22:57:51 +0400
committerDmitry Mikhirev2014-10-23 22:57:51 +0400
commit6a6d104f35b57f1dcdd966f354b2beca73310fe4 (patch)
tree4e8d8802baabdcb59713e80fd50375d1e2413fb4 /lcdprint.cpp
parent89711b175e318ba17b9e1504382e16c88cafbeea (diff)
downloadbrainuino-6a6d104f35b57f1dcdd966f354b2beca73310fe4.tar.gz
brainuino-6a6d104f35b57f1dcdd966f354b2beca73310fe4.tar.bz2
brainuino-6a6d104f35b57f1dcdd966f354b2beca73310fe4.tar.xz
brainuino-6a6d104f35b57f1dcdd966f354b2beca73310fe4.zip
major code revision
Diffstat (limited to 'lcdprint.cpp')
-rw-r--r--lcdprint.cpp67
1 files changed, 45 insertions, 22 deletions
diff --git a/lcdprint.cpp b/lcdprint.cpp
index af0eaeb..c53118a 100644
--- a/lcdprint.cpp
+++ b/lcdprint.cpp
@@ -1,7 +1,7 @@
/*
Brainuino Aleph
- Copyright (C) 2011-2012 Dmitry Mikhirev
+ Copyright (C) 2011, 2012, 2014 Dmitry Mikhirev
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -21,31 +21,54 @@
#include "lcdprint.h"
#include "font.h"
-size_t uprint(char* rawstr, LiquidCrystal *lcd)
+size_t uprint(const char* rawstr, Print* out)
{
- int32_t ucode;
- int i, j;
- int numcodes = sizeof(charmap)/sizeof(charcode);
utf8 str = utf8(rawstr);
- char result[str.chars()];
-
- for (i = 0; i < str.chars(); i++) {
- ucode = str.get();
- if (ucode > 0x0000) {
- if (ucode <= 0x007d) {
- result[i] = ucode;
- } else {
- result[i] = 0xff;
- for (j = 0; (j < numcodes) && (pgm_read_dword(&charmap[j].uni) <= ucode); j++) {
- if (pgm_read_dword(&charmap[j].uni) == ucode) {
- result[i] = pgm_read_byte(&charmap[j].font);
- }
- }
- }
+ return utf8print(&str, out);
+}
+
+size_t uprint(const __FlashStringHelper* rawstr, Print* out)
+{
+ utf8 str = utf8(rawstr);
+ return utf8print(&str, out);
+}
+
+size_t utf8print(utf8* str, Print* out)
+{
+ char result[str->chars() + 1];
+ wchar_t ucode;
+ int i;
+
+ for (i = 0; i < (str->chars()); i++) {
+ ucode = str->get();
+ if (ucode != 0x0000) {
+ result[i] = codeOf(ucode);
} else {
break;
}
}
- result[i] = 0;
- return lcd->print(result);
+ result[i] = '\0';
+ return out->print(result);
+}
+
+char codeOf(wchar_t ucode)
+{
+ if (ucode > 0x0000 && ucode <= 0x007d) // ASCII symbol
+ return char(ucode);
+
+ int low, high, mid;
+
+ low = 0;
+ high = sizeof(charmap)/sizeof(charcode) - 1;
+ while (low <= high) {
+ mid = (low + high) >> 1;
+ wchar_t u = pgm_read_word(&charmap[mid].uni);
+ if (wchar_t(u) > ucode)
+ high = mid - 1;
+ else if (u < ucode)
+ low = mid + 1;
+ else
+ return pgm_read_byte(&charmap[mid].font);
+ }
+ return NOCHAR;
}