Skip to content
Snippets Groups Projects
Commit 2b705472 authored by egorguslyan's avatar egorguslyan
Browse files

Text now works (eng + rus)

parent 0e6ef410
No related branches found
No related tags found
No related merge requests found
...@@ -62,7 +62,7 @@ void setup() ...@@ -62,7 +62,7 @@ void setup()
co2.begin(CO2TX, CO2RX); co2.begin(CO2TX, CO2RX);
co2.setAutoCalibration(false); co2.setAutoCalibration(false);
delay(500); delay(500);
tb.setup("Ghbdtn vbh!", 0xFFFF, COLOR1, TB_BOUNCE, 1, 1, 14, 500, 2000); tb.setup("Ghbdtn vbh!", 0xFFFF, COLOR1, TB_LOOP_WITH_DELAY, 1, 1, 14, 100, 2000);
} }
void loop() void loop()
...@@ -103,6 +103,8 @@ void loop() ...@@ -103,6 +103,8 @@ void loop()
} }
} }
tb.render(); static uint64_t timer1 = 0;
timer(timer1, 99)
if(tb.render()) timer1 = millis();
matrix.show(); matrix.show();
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
const uint8_t font_null[] PROGMEM = {0}; const uint8_t font_null[] PROGMEM = {0};
const uint8_t font_notdef[] PROGMEM = {cords(5, 0, 5), 0b11111110, 0b11110111, 0b01011101, 0b11101111, 0b11100000}; const uint8_t font_notdef[] PROGMEM = {cords(5, 0, 5), 0b11111110, 0b11110111, 0b01011101, 0b11101111, 0b11100000};
const uint8_t font_space[] PROGMEM = {cords(1, 6, 1), 0b00000000}; const uint8_t font_space[] PROGMEM = {cords(1, 6, 1), 0b00000000};
const uint8_t font_exclamation[] PROGMEM = {cords(1, 0, 1), 0b11110100}; const uint8_t font_exclamation[] PROGMEM = {cords(1, 1, 1), 0b11110100};
const uint8_t font_quote[] PROGMEM = {cords(3, 0, 1), 0b10110100}; const uint8_t font_quote[] PROGMEM = {cords(3, 0, 1), 0b10110100};
const uint8_t font_hashtag[] PROGMEM = {cords(5, 2, 3), 0b01010111, 0b11010101, 0b11110101}; const uint8_t font_hashtag[] PROGMEM = {cords(5, 2, 3), 0b01010111, 0b11010101, 0b11110101};
const uint8_t font_promt[] PROGMEM = {cords(5, 0, 5), 0b00100011, 0b10101000, 0b11100010, 0b10111000, 0b10000000}; const uint8_t font_promt[] PROGMEM = {cords(5, 0, 5), 0b00100011, 0b10101000, 0b11100010, 0b10111000, 0b10000000};
...@@ -129,7 +129,7 @@ const uint8_t font_ru_ru_Ae[] PROGMEM = {cords(4, 0, 4), 0b11100001, 0b00 ...@@ -129,7 +129,7 @@ const uint8_t font_ru_ru_Ae[] PROGMEM = {cords(4, 0, 4), 0b11100001, 0b00
const uint8_t font_ru_ru_Yu[] PROGMEM = {cords(5, 0, 5), 0b10010101, 0b01101011, 0b11011010, 0b11010110, 0b01000000}; const uint8_t font_ru_ru_Yu[] PROGMEM = {cords(5, 0, 5), 0b10010101, 0b01101011, 0b11011010, 0b11010110, 0b01000000};
const uint8_t font_ru_ru_Ya[] PROGMEM = {cords(4, 0, 4), 0b01111001, 0b10010111, 0b00110101, 0b10010000}; const uint8_t font_ru_ru_Ya[] PROGMEM = {cords(4, 0, 4), 0b01111001, 0b10010111, 0b00110101, 0b10010000};
const uint8_t font_ru_ru_b[] PROGMEM = {cords(3, 0, 3), 0b01110001, 0b00111011, 0b01010000}; const uint8_t font_ru_ru_b[] PROGMEM = {cords(3, 0, 3), 0b01110001, 0b00111011, 0b01010000};
const uint8_t font_ru_ru_v[] PROGMEM = {cords(3, 0, 3), 0b01010111, 0b01011010, 0b10000000}; const uint8_t font_ru_ru_v[] PROGMEM = {cords(3, 1, 3), 0b01010111, 0b01011010, 0b10000000};
const uint8_t font_ru_ru_g[] PROGMEM = {cords(3, 2, 2), 0b11110010, 0b01001000}; const uint8_t font_ru_ru_g[] PROGMEM = {cords(3, 2, 2), 0b11110010, 0b01001000};
const uint8_t font_ru_ru_d[] PROGMEM = {cords(5, 2, 4), 0b00110010, 0b10010101, 0b11111000, 0b10000000}; const uint8_t font_ru_ru_d[] PROGMEM = {cords(5, 2, 4), 0b00110010, 0b10010101, 0b11111000, 0b10000000};
const uint8_t font_ru_ru_ye[] PROGMEM = {cords(4, 0, 4), 0b10010000, 0b01101001, 0b11101000, 0b01100000}; const uint8_t font_ru_ru_ye[] PROGMEM = {cords(4, 0, 4), 0b10010000, 0b01101001, 0b11101000, 0b01100000};
...@@ -139,6 +139,7 @@ const uint8_t font_ru_ru_i[] PROGMEM = {cords(5, 2, 4), 0b10001100, 0b11 ...@@ -139,6 +139,7 @@ const uint8_t font_ru_ru_i[] PROGMEM = {cords(5, 2, 4), 0b10001100, 0b11
const uint8_t font_ru_ru_yi[] PROGMEM = {cords(5, 0, 5), 0b01110000, 0b00100011, 0b00111010, 0b11100110, 0b00100000}; const uint8_t font_ru_ru_yi[] PROGMEM = {cords(5, 0, 5), 0b01110000, 0b00100011, 0b00111010, 0b11100110, 0b00100000};
const uint8_t font_ru_ru_k[] PROGMEM = {cords(4, 2, 3), 0b10011010, 0b11001010, 0b10010000}; const uint8_t font_ru_ru_k[] PROGMEM = {cords(4, 2, 3), 0b10011010, 0b11001010, 0b10010000};
const uint8_t font_ru_ru_l[] PROGMEM = {cords(4, 2, 3), 0b00110101, 0b01010101, 0b10010000}; const uint8_t font_ru_ru_l[] PROGMEM = {cords(4, 2, 3), 0b00110101, 0b01010101, 0b10010000};
const uint8_t font_ru_ru_m[] PROGMEM = {cords(5, 2, 4), 0b01010101, 0b01101011, 0b01011010, 0b10000000};
const uint8_t font_ru_ru_n[] PROGMEM = {cords(4, 2, 3), 0b10011001, 0b11111001, 0b10010000}; const uint8_t font_ru_ru_n[] PROGMEM = {cords(4, 2, 3), 0b10011001, 0b11111001, 0b10010000};
const uint8_t font_ru_ru_p[] PROGMEM = {cords(4, 0, 3), 0b11111001, 0b10011001, 0b10010000}; const uint8_t font_ru_ru_p[] PROGMEM = {cords(4, 0, 3), 0b11111001, 0b10011001, 0b10010000};
const uint8_t font_ru_ru_t[] PROGMEM = {cords(3, 2, 2), 0b11101001, 0b00100100}; const uint8_t font_ru_ru_t[] PROGMEM = {cords(3, 2, 2), 0b11101001, 0b00100100};
...@@ -341,7 +342,7 @@ const uint8_t* const font[] /*PROGMEM*/ = { font_notdef, // NONE NONE ...@@ -341,7 +342,7 @@ const uint8_t* const font[] /*PROGMEM*/ = { font_notdef, // NONE NONE
font_ru_ru_y, // ы 115 1 font_ru_ru_y, // ы 115 1
font_e, // е 116 1 font_e, // е 116 1
font_ru_ru_g, // г 117 1 font_ru_ru_g, // г 117 1
font_m, // м 118 1 font_ru_ru_m, // м 118 1
font_ru_ru_c, // ц 119 1 font_ru_ru_c, // ц 119 1
font_ru_ru_ch, // ч 120 1 font_ru_ru_ch, // ч 120 1
font_ru_ru_n, // н 121 1 font_ru_ru_n, // н 121 1
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
#include "font.h" #include "font.h"
enum TB_MODES enum TB_MODES {
{
TB_DISABLED, TB_DISABLED,
TB_STATIC, TB_STATIC,
TB_REPEAT, TB_REPEAT,
...@@ -12,8 +11,7 @@ enum TB_MODES ...@@ -12,8 +11,7 @@ enum TB_MODES
TB_BOUNCE, TB_BOUNCE,
}; };
class textbox class textbox {
{
private: private:
/* data */ /* data */
uint8_t cord_x; uint8_t cord_x;
...@@ -34,6 +32,7 @@ private: ...@@ -34,6 +32,7 @@ private:
bool native; bool native;
void getLetter(uint8_t i, bool skipBitmap = 0); void getLetter(uint8_t i, bool skipBitmap = 0);
uint64_t timer0; uint64_t timer0;
public: public:
textbox(void); textbox(void);
void setup(char _text[], uint64_t _langMask, void setup(char _text[], uint64_t _langMask,
...@@ -41,7 +40,7 @@ public: ...@@ -41,7 +40,7 @@ public:
uint8_t _mode, uint8_t _mode,
uint8_t _x, uint8_t _y, uint8_t _w, uint8_t _x, uint8_t _y, uint8_t _w,
uint8_t _reciprocal_speed = 0, uint16_t _delay = 0); uint8_t _reciprocal_speed = 0, uint16_t _delay = 0);
void render(void); uint8_t render(void);
void disable(void); void disable(void);
}; };
...@@ -57,15 +56,6 @@ textbox::textbox(void) ...@@ -57,15 +56,6 @@ textbox::textbox(void)
langMask = 0; langMask = 0;
// If 96th symbol is font_null there is no native language except for English // If 96th symbol is font_null there is no native language except for English
native = pgm_read_byte(font[96]) != 0; native = pgm_read_byte(font[96]) != 0;
uint8_t debugByte = pgm_read_byte(font[0]);
Serial.println(debugByte);
uint8_t debugCounter = 1;
while(debugByte != 0)
{
Serial.println(debugByte);
debugByte = pgm_read_byte(font[debugCounter]);
debugCounter++;
}
} }
void textbox::setup(char _text[], uint64_t _langMask, void textbox::setup(char _text[], uint64_t _langMask,
...@@ -79,8 +69,7 @@ void textbox::setup(char _text[], uint64_t _langMask, ...@@ -79,8 +69,7 @@ void textbox::setup(char _text[], uint64_t _langMask,
textlen = strlen(text); textlen = strlen(text);
langMask = _langMask; langMask = _langMask;
textwidth = 0; textwidth = 0;
for(uint16_t i = 0; i < textlen; i++) for (uint16_t i = 0; i < textlen; i++) {
{
getLetter(i, true); getLetter(i, true);
textwidth += letter[0] + 1; textwidth += letter[0] + 1;
} }
...@@ -91,8 +80,7 @@ void textbox::setup(char _text[], uint64_t _langMask, ...@@ -91,8 +80,7 @@ void textbox::setup(char _text[], uint64_t _langMask,
cord_y = _y; cord_y = _y;
w = _w; w = _w;
offset = 0; offset = 0;
switch(mode) switch (mode) {
{
case TB_LOOP: case TB_LOOP:
delay = 0; delay = 0;
goto NO_DELAY; goto NO_DELAY;
...@@ -114,47 +102,37 @@ void textbox::setup(char _text[], uint64_t _langMask, ...@@ -114,47 +102,37 @@ void textbox::setup(char _text[], uint64_t _langMask,
render(); render();
} }
void textbox::render(void) uint8_t textbox::render(void)
{ {
// Do nothing if disabled // Do nothing if disabled
if(mode != TB_DISABLED) if (mode != TB_DISABLED) {
{ if (timer0 == 0) {
if(timer0 == 0) offset = 0 + (mode == TB_REPEAT) * w + 1 * (mode == TB_LOOP);
{
offset = 0 + (mode == TB_REPEAT) * w;
direction = 0; direction = 0;
timer0 = millis(); timer0 = millis();
} } else {
else if ((millis() - timer0) > (((mode != TB_LOOP) && !state) ? delay : speed)) {
{
if((millis() - timer0) > (((mode != TB_LOOP) && !state) ? delay : speed))
{
state = 1; state = 1;
timer0 = millis(); timer0 = millis();
if(mode == TB_BOUNCE) if (mode == TB_BOUNCE) {
{ if ((!direction && offset == -textwidth + w) || (direction && offset == 0)) {
if((!direction && offset == -textwidth + w) || (direction && offset == 0))
{
direction = !direction; direction = !direction;
state = 0; state = 0;
} } else
else offset += direction ? 1 : -1; offset += direction ? 1 : -1;
} } else {
else
{
offset += -1; offset += -1;
if(offset < (-textwidth - 2 * (mode == TB_LOOP || mode == TB_LOOP_WITH_DELAY) + w * (mode == TB_REPEAT))) if (offset < ((int16_t)-textwidth - 2 * (mode == TB_LOOP || mode == TB_LOOP_WITH_DELAY) - w * (mode == TB_REPEAT))) {
{
offset = 0 + (mode == TB_REPEAT) * w; offset = 0 + (mode == TB_REPEAT) * w;
state = 0; state = 0;
} }
} }
} else
if(state != 0) return 0;
} }
else return; } else
} return 0;
}
else return;
// Clear spot // Clear spot
for (uint8_t i = cord_x; (i < cord_x + w) && (i < WIDTH); i++) for (uint8_t i = cord_x; (i < cord_x + w) && (i < WIDTH); i++)
for (uint8_t j = cord_y; (j < cord_y + 7) && (j < HEIGHT); j++) for (uint8_t j = cord_y; (j < cord_y + 7) && (j < HEIGHT); j++)
...@@ -164,8 +142,7 @@ void textbox::render(void) ...@@ -164,8 +142,7 @@ void textbox::render(void)
int16_t positionX = cord_x + offset; int16_t positionX = cord_x + offset;
int16_t positionY = cord_y; int16_t positionY = cord_y;
// Draw while in bounds // Draw while in bounds
while((positionX < cord_x + w) && (index < textlen)) while ((positionX < cord_x + w) && (index < textlen)) {
{
// Recieve letter // Recieve letter
getLetter(index); getLetter(index);
// Relative X and Y // Relative X and Y
...@@ -174,11 +151,9 @@ void textbox::render(void) ...@@ -174,11 +151,9 @@ void textbox::render(void)
// X bound // X bound
uint8_t maxX = letter[0]; uint8_t maxX = letter[0];
// Run thougth bytes // Run thougth bytes
for(uint8_t i = 0; (i < letter[2]) && (y < 7); i++) for (uint8_t i = 0; (i < letter[2]) && (y < 7); i++) {
{
// Run througth bits // Run througth bits
for(int8_t j = 7; (j >= 0) && (y < 7); j--) for (int8_t j = 7; (j >= 0) && (y < 7); j--) {
{
// Set pixel // Set pixel
bool state = bitRead(letter[i + 3], j); bool state = bitRead(letter[i + 3], j);
int16_t mx = x + positionX; int16_t mx = x + positionX;
...@@ -187,9 +162,9 @@ void textbox::render(void) ...@@ -187,9 +162,9 @@ void textbox::render(void)
matrix.set(mx, my, color); matrix.set(mx, my, color);
// Next pixel // Next pixel
x++; x++;
if(x >= maxX) if (x >= maxX) {
{ x = 0;
x = 0; y++; y++;
} }
} }
} }
...@@ -197,7 +172,7 @@ void textbox::render(void) ...@@ -197,7 +172,7 @@ void textbox::render(void)
positionX += maxX + 1; positionX += maxX + 1;
index++; index++;
} }
return 1;
} }
void textbox::disable(void) void textbox::disable(void)
...@@ -216,18 +191,18 @@ void textbox::getLetter(uint8_t i, bool skipBitmap = 0) ...@@ -216,18 +191,18 @@ void textbox::getLetter(uint8_t i, bool skipBitmap = 0)
memset(letter, 0, 8 * sizeof(uint8_t)); memset(letter, 0, 8 * sizeof(uint8_t));
uint8_t index; uint8_t index;
// Translate ASCII index to local // Translate ASCII index to local
if(ctoi >= 32 && ctoi <= 126) index = ctoi - 31 + 95 * lang * native; if (ctoi >= 32 && ctoi <= 126)
else index = 0; index = ctoi - 31 + 95 * lang * native;
else
index = 0;
// Read properties from semeric number // Read properties from semeric number
uint8_t readed = pgm_read_byte(font[index]); uint8_t readed = pgm_read_byte(font[index]);
letter[0] = readed / 49 + 1; // width letter[0] = readed / 49 + 1; // width
letter[1] = readed % 7; // offset letter[1] = readed % 7; // offset
letter[2] = readed / 7 % 7; // bytes letter[2] = readed / 7 % 7; // bytes
// Read bitmaps // Read bitmaps
if(!skipBitmap) if (!skipBitmap) {
{ for (uint8_t i = 0; i < letter[2]; i++) {
for(uint8_t i = 0; i < letter[2]; i++)
{
letter[i + 3] = pgm_read_byte(font[index] + (i + 1) * sizeof(uint8_t)); letter[i + 3] = pgm_read_byte(font[index] + (i + 1) * sizeof(uint8_t));
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment