#include <LCDI2C_Multilingual_MCD.h>
LCDI2C_Vietnamese lcd(0x27, 20, 4);
char LineText[] = "kachnicka a slepicka9899987";
char CurTime[] = "26-01-05,21:12:35";
uint32_t timestamp;
typedef const __FlashStringHelper * FStringPtr;
// FStringPtr txtP;
class Disp {
public:
void LcdLine2(uint8_t line, FStringPtr txt) {
char Tline[21] = {};
lcd.setCursor(0, line);
lcd.print(F(" "));
strncpy_PF(Tline, txt, 20);
Serial.println("Fstring overload used");
lcd.setCursor(0, line);
lcd.print(Tline);
}
void LcdLine2(uint8_t line, char *txt) {
char Tline[21] = {};
lcd.setCursor(0, line);
lcd.print(F(" "));
strncpy(Tline, txt, 20);
Serial.println("pointer overload used");
lcd.setCursor(0, line);
lcd.print(Tline);
}
};
Disp DisplayP;
void setup() {
// typedef const __FlashStringHelper * FStringPtr;
// void LcdLineP(uint8_t line, const __FlashStringHelper * txt);
Serial.begin(115200);
lcd.init();
lcd.backlight();
lcd.println("____________________");
lcd.println("____________________");
lcd.println("____________________");
lcd.println("____________________");
timestamp = micros();
// LcdLine(0, "káchníčka ä slep");
// LcdLineU8(0, "káchníčká a slép");
// LcdLineU8(0, "25°C slépícka kohoutek");
LcdLineU8(0, "kvók");
// LcdLineU8(0, "Cao đẳng Việt Nam");
timestamp = micros() - timestamp;
Serial.print("Function LcdLineU8 time: ");
Serial.println(timestamp);
// timestamp = micros();
// LcdLine3(1, "kachnicka a slepicka");
// timestamp = micros() - timestamp;
// Serial.print("Function old time: ");
// Serial.println(timestamp);
// Serial.print("Printing affected array: ");
// Serial.println(LineText);
// lcd.print("X");
// LcdLine(1, "Slepicka");
timestamp = micros();
// LcdLineP(2, PSTR("kokrhacek a kdakalka kokodak"));
// LcdLineP(2, PSTR("kokrhacek P kdakalka"));
// LcdLineP(2, F("kokrhacek a kdakalka"));
LcdLinePU8(2, PSTR("kokrhacek"));
timestamp = micros() - timestamp;
Serial.print("Function PROGMEM time: ");
Serial.println(timestamp);
lcd.print("X");
// DisplayP.LcdLine2(1, F("kokrhacek Fstr kdakalka kokodak"));
// DisplayP.LcdLine2(3, "kokrhacek point kdakalka kokodak");
// strcpy(CurTime, CurTime + 9);
// Serial.println("Test of copying inplace:");
// Serial.println(CurTime);
}
void loop() {
// put your main code here, to run repeatedly:
}
// Print on empty line of LC display memory based char array.
void LcdLine(uint8_t line, char *txt) {
size_t ArrLen = strlen(txt);
// size_t ArrLen = strnlen(txt, 20);
lcd.setCursor(0, line);
lcd.print(txt);
for (uint8_t i = ArrLen; i < 20; i++) {
lcd.write(' ');
}
lcd.setCursor(ArrLen, line);
}
// Print UTF-8 text on a single line.
void LcdLineU8(uint8_t line, char *txt) {
char ExchangeMem = 0;
uint8_t CntChar = 0;
uint8_t CntCharU8 = 0;
while (true) {
if ((txt[CntChar]) == '\0') {
break;
}
if ((txt[CntChar] & 0xc0) != 0x80) {
CntCharU8++;
}
if (CntCharU8 > 20) {
ExchangeMem = txt[CntChar];
txt[CntChar] = '\0';
break;
}
CntChar++;
}
lcd.setCursor(0, line);
lcd.print(txt);
for (uint8_t i = CntCharU8; i < 20; i++) {
lcd.write(' ');
}
Serial.print("CntChar value: ");
Serial.println(CntChar);
lcd.setCursor(CntCharU8, line);
txt[CntChar] = ExchangeMem;
// Serial.print("index value: ");
// Serial.println(index);
// Serial.print("ExchangeMem: ");
// Serial.print(ExchangeMem);
// Serial.println("<");
Serial.print("txt variable at end: ");
Serial.print(txt);
Serial.println("<");
}
/* // Print on empty line of LC display Progmem based char array.
void LcdLineP(uint8_t line, const __FlashStringHelper *txt) {
char buffer[21];
strncpy_PF(buffer, (const char*)txt, 20);
size_t ArrLen = strlen(buffer);
lcd.setCursor(0, line);
buffer[ArrLen] = '\0';
// if (ArrLen > 20) {
// lcd.print(txt);
// return;
// }
lcd.print(buffer);
for (uint8_t i = ArrLen; i < 20; i++) {
lcd.write(' ');
}
lcd.setCursor(ArrLen, line);
} */
void LcdLineP(uint8_t line, char txt[]) {
char buf[21] = {};
strncpy_P(buf, txt, 20);
size_t ArrLen = strlen(buf);
Serial.print("Buffer size: ");
Serial.println(ArrLen);
lcd.setCursor(0, line);
txt[ArrLen] = '\0';
lcd.print(buf);
for (uint8_t i = ArrLen; i < 20; i++) {
lcd.write(' ');
}
lcd.setCursor(ArrLen, line);
}
void LcdLinePU8(uint8_t line, char txt[]) {
char buff[81];
uint8_t CntChar = 0;
uint8_t CntCharU8 = 0;
while (true) {
if (pgm_read_byte(&txt[CntChar]) == '\0') {
buff[CntChar] = '\0';
break;
}
if ((txt[CntChar] & 0xc0) != 0x80) {
CntCharU8++;
}
if (CntCharU8 > 20) {
buff[CntChar] = '\0';
break;
}
buff[CntChar] = pgm_read_byte(&txt[CntChar]);
CntChar++;
}
lcd.setCursor(0, line);
lcd.print(buff);
for (uint8_t i = CntCharU8; i < 20; i++) {
lcd.write(' ');
}
lcd.setCursor(CntCharU8, line);
// Serial.print("CntChar value: ");
// Serial.println(CntChar);
// Serial.print("index value: ");
// Serial.println(index);
// Serial.print("ExchangeMem: ");
// Serial.print(ExchangeMem);
// Serial.println("<");
Serial.print("Progmem txt variable at end: ");
Serial.print(buff);
Serial.println("<");
}
// pgm_read_byte(&key[i % keylen])
/*
void LcdLineP(uint8_t line, char *txt) {
size_t ArrLen = strlen(txt);
lcd.setCursor(0, line);
strncpy(txt, txt, 20);
if (ArrLen > 20) {
// DEBUG_PRINTLN("Shorting the P array");
txt[20] = '\0';
lcd.print(txt);
return;
}
// Serial.println(txt);
txt[ArrLen] = '\0';
lcd.print(txt);
for (uint8_t i = ArrLen; i < 20; i++) {
lcd.write(' ');
}
lcd.setCursor(ArrLen, line);
} */
// strcpy(text, CurTime + 9);