diff options
-rw-r--r-- | brainuino.ino | 58 | ||||
-rw-r--r-- | font.h (renamed from font_ru-en.h) | 8 | ||||
-rw-r--r-- | font_en.h | 0 | ||||
-rw-r--r-- | lcdprint.cpp | 16 | ||||
-rw-r--r-- | lcdprint.h | 2 | ||||
-rw-r--r-- | utf8.cpp | 41 | ||||
-rw-r--r-- | utf8.h | 3 |
7 files changed, 64 insertions, 64 deletions
diff --git a/brainuino.ino b/brainuino.ino index 7fb0233..557b023 100644 --- a/brainuino.ino +++ b/brainuino.ino @@ -1,7 +1,7 @@ /* Brainuino Aleph - Copyright (C) 2011 Dmitry Mikhirev + Copyright (C) 2011-2012 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 @@ -17,10 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <stdio.h> #include <LiquidCrystal.h> // undefine the following if your LCD does not support Russian font -//#define RUSSIAN +#define RUSSIAN #include "pinout.h" #include "game.h" @@ -51,12 +52,10 @@ void loop() timer = timer1; printGameType(); -/* // ensure that stop button is released while (digitalRead(CONTROL2) == LOW) { delay(20); } -*/ ask(); } @@ -69,7 +68,7 @@ void ask() digitalWrite(REDLAMP, LOW); #ifdef RUSSIAN - printState(convert("Задаётся вопрос ")); + printState("Задаётся вопрос "); #else printState("Asking question "); #endif @@ -131,7 +130,7 @@ void discuss() printGameType(); #ifdef RUSSIAN - printState(convert("Отсчёт: ")); + printState("Отсчёт: "); #else printState("Count: "); #endif @@ -183,7 +182,7 @@ void answer(uint8_t num) { printPlayer(num); #ifdef RUSSIAN - printState(convert("Ответ ")); + printState("Ответ "); #else printState("Answer "); #endif @@ -224,7 +223,7 @@ void falseStart(uint8_t num) { tone(SPEAKER, 1784, 1000); digitalWrite(REDLAMP, HIGH); #ifdef RUSSIAN - printState(convert(" Фальстарт ")); + printState(" Фальстарт "); #else printState(" False start "); #endif @@ -244,12 +243,12 @@ void refresh() { } -void printState(String state) { +void printState(char *state) { // displaying string in the beginning of LCD second row lcd.setCursor(0, 1); - lcd.print(state); + uprint(state, &lcd); } @@ -257,11 +256,11 @@ void printTime() { // displaying time passed after starting timer - String timestr; + char timestr[33]; - timestr = String(time/1000) + '.' + String((time%1000)/100); + sprintf(timestr, "%.1f", float(time)/1000; lcd.setCursor(8, 1); - lcd.print(timestr); + uprint(timestr, &lcd); } @@ -270,24 +269,24 @@ void printPreciseTime() { // displaying time passed after starting timer // or that it was not started yet - String timestr; + char timestr[33]; // if timer was started if (startTime > 0) { time = millis()-startTime; - timestr = String(time/1000) + '.' + String(time%1000); + sprintf(timestr, "%.3f", float(time)/1000); } // if it was not else #ifdef RUSSIAN - timestr = convert("досрочно"); + sprintf(timestr, "досрочно"); #else - timestr = "prematur"; + sprintf(timestr, "prematur"); #endif lcd.setCursor(8, 1); - lcd.print(timestr); + uprint(timestr, &lcd); } @@ -345,27 +344,27 @@ void printGameType() { case BRAIN: #ifdef RUSSIAN - lcd.print(convert(" Брейн-ринг ")); + uprint(" Брейн-ринг ", &lcd); #else - lcd.print(" Brain-ring "); + uprint(" Brain-ring ", &lcd); #endif break; case SI: #ifdef RUSSIAN - lcd.print(convert(" Своя игра ")); + uprint(" Своя игра ", &lcd); #else - lcd.print(" Jeopardy "); + uprint(" Jeopardy ", &lcd); #endif break; case CHGK: #ifdef RUSSIAN - lcd.print(convert("Что? Где? Когда?")); + uprint("Что? Где? Когда?", &lcd); #else - lcd.print("What?Where?When?"); + uprint("What?Where?When?", &lcd); #endif break; @@ -377,26 +376,29 @@ void printPlayer(uint8_t num) { // displaying number of player or team + char printstring[65]; + lcd.setCursor(0, 0); switch (gameType) { case BRAIN: #ifdef RUSSIAN - lcd.print(convert("Команда ") + String(int(num)) + " "); + sprintf(printstring, "Команда %u ", num); #else - lcd.print("Team " + String(int(num)) + " "); + sprintf(printstring, "Team %u ", num); #endif break; case SI: #ifdef RUSSIAN - lcd.print(convert("Игрок ") + String(int(num)) + " "); + sprintf(printstring, "Игрок %u ", num); #else - lcd.print("Player " + String(int(num) + " ")); + sprintf(printstring, "Player %u ", num); #endif break; } + uprint(printstring, &lcd); buttonPressed = 0; } @@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef en_ru_h -#define en_ru_h +#ifndef font_h +#define font_h #include <avr/pgmspace.h> @@ -27,7 +27,7 @@ struct charcode { const char font; }; -const charcode charmap[] PROGMEM = { +charcode charmap[] PROGMEM = { // tilde {0x007e, 0xe9}, // latin-1 supplement @@ -118,7 +118,7 @@ const charcode charmap[] PROGMEM = { {0x043c, 0xbc}, {0x043d, 0xbd}, {0x043e, 0x6f}, - {0x043f, 0xbf}, + {0x043f, 0xbe}, {0x0440, 0x70}, {0x0441, 0x63}, {0x0442, 0xbf}, diff --git a/font_en.h b/font_en.h deleted file mode 100644 index e69de29..0000000 --- a/font_en.h +++ /dev/null diff --git a/lcdprint.cpp b/lcdprint.cpp index 585b2de..c79bb1c 100644 --- a/lcdprint.cpp +++ b/lcdprint.cpp @@ -17,12 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ - +#include <LiquidCrystal.h> #include "lcdprint.h" -#include "font_ru-en.h" -//#include "font_en.h" +#include "font.h" -char* convert(utf8 str) +size_t uprint(utf8 str, LiquidCrystal *lcd) { int32_t ucode; int i, j; @@ -36,9 +35,9 @@ char* convert(utf8 str) result[i] = char(ucode); } else { result[i] = 0xff; - for (j = 0; j < numcodes && charmap[j].uni < ucode; j++) { - if (charmap[j].uni == ucode) { - result[i] = charmap[j].font; + 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); } } } @@ -47,6 +46,5 @@ char* convert(utf8 str) break; } } - - return result; + return lcd->print(result); } @@ -22,6 +22,6 @@ #include "utf8.h" -char* convert (utf8); +size_t uprint (utf8, LiquidCrystal*); #endif @@ -20,23 +20,22 @@ #include "utf8.h" #include <string.h> -utf8::utf8 (char* string) +utf8::utf8 (char* input) { - bytes = strlen(string); - _string = (char *)malloc(bytes + 1); - strcpy(_string, string); + bytes = strlen(input); + string = strdup(input); chars = 0; for (_index = 0; _index < bytes; _index++) { - if (_string[_index] & 0x80 == 0) { + if ((string[_index] & 0x80) == 0x00) { + chars++; + } else if ((string[_index] & 0x20) == 0x00) { + chars++; + _index ++; + } else if ((string[_index] & 0x10) == 0x00) { chars++; - } else if (_string[_index] & 0x20 == 0) { - chars += 2; - _index++; - } else if (_string[_index] & 0x10 == 0) { - chars += 3; _index += 2; - } else if (_string[_index] & 0x8 == 0) { - chars += 4; + } else if ((string[_index] & 0x08) == 0x00) { + chars++; _index += 3; } } @@ -46,18 +45,18 @@ utf8::utf8 (char* string) int32_t utf8::get() { int32_t code; - if (_string[_index] & 0x80 == 0) { - code = int32_t(_string[_index]); + if ((string[_index] & 0x80) == 0) { + code = int32_t(string[_index]); _index++; - } else if (_string[_index] & 0x20 == 0) { - code = int32_t(_string[_index] & 0x1f) << 6 | int32_t(_string[_index+1] & 0x3f); + } else if ((string[_index] & 0x20) == 0) { + code = int32_t(string[_index] & 0x1f) << 6 | int32_t(string[_index+1] & 0x3f); _index += 2; - } else if (_string[_index] & 0x10 == 0) { - code = int32_t(_string[_index] & 0xf) << 12 | int32_t(_string[_index+1] & 0x3f) << 6 | int32_t(_string[_index+2] & 0x3f); + } else if ((string[_index] & 0x10) == 0) { + code = int32_t(string[_index] & 0xf) << 12 | int32_t(string[_index+1] & 0x3f) << 6 | int32_t(string[_index+2] & 0x3f); _index += 3; - } else if (_string[_index] & 0x8 == 0) { - code = int32_t(_string[_index] & 0x7) << 18 | int32_t(_string[_index+1] & 0x3f) << 12 | int32_t(_string[_index+2] & 0x3f) << 6 | int32_t(_string[_index+3] & 0x3f); + } else if ((string[_index] & 0x8) == 0) { + code = int32_t(string[_index] & 0x7) << 18 | int32_t(string[_index+1] & 0x3f) << 12 | int32_t(string[_index+2] & 0x3f) << 6 | int32_t(string[_index+3] & 0x3f); } - if (_index > bytes) _index = 0; + if (_index >= bytes) _index = 0; return code; } @@ -28,8 +28,9 @@ class utf8 { uint16_t chars; uint16_t bytes; int32_t get(); + char* string; + private: - char* _string; uint16_t _index; }; |