#define PRG_TYPE 1
#define LCD_COL 20
#define FILE_SIZE 1400000
#define SF(string_literal) String(F(string_literal))
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C _lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 20 chars and 4 line display
void setup()
{
_lcd.init(); // initialize the 20x4 lcd module
//Naklikání bitů znaků
//https://projecthub.arduino.cc/tusindfryd/create-custom-animations-on-16x2-lcd-displays-57d776
//https://nonnullish.github.io/screenduino/
#if PRG_TYPE == 4
//Plné
byte image01[8] PROGMEM = { B01111, B10000, B10000, B10000, B10000, B10000, B10000, B01111 };
byte image02[8] PROGMEM = { B11111, B00000, B00000, B00000, B00000, B00000, B00000, B11111 };
byte image03[8] PROGMEM = { B11110, B00001, B00001, B00001, B00001, B00001, B00001, B11110 };
byte image04[8] PROGMEM = { B01111, B11111, B11111, B11111, B11111, B11111, B11111, B01111 };
byte image05[8] PROGMEM = { B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 };
byte image06[8] PROGMEM = { B11110, B11111, B11111, B11111, B11111, B11111, B11111, B11110 };
#endif
#if PRG_TYPE == 3
//šrafované
byte image01[8] PROGMEM = { B00111, B01000, B10000, B10000, B10000, B10000, B01000, B00111 };
byte image02[8] PROGMEM = { B11111, B00000, B00000, B00000, B00000, B00000, B00000, B11111 };
byte image03[8] PROGMEM = { B11100, B00010, B00001, B00001, B00001, B00001, B00010, B11100 };
byte image04[8] PROGMEM = { B00111, B01010, B10101, B11010, B10101, B11010, B01101, B00111 };
byte image05[8] PROGMEM = { B11111, B10101, B01010, B10101, B01010, B10101, B01010, B11111 };
byte image06[8] PROGMEM = { B11100, B10110, B01011, B10101, B01011, B10101, B01010, B11100 };
#endif
#if PRG_TYPE == 2
//čárky (plná výška)
byte image01[8] PROGMEM = {B00101, B01000, B10000, B10000, B10000, B10000, B01000, B00101};
byte image02[8] PROGMEM = {B10101, B00000, B00000, B00000, B00000, B00000, B00000, B10101};
byte image03[8] PROGMEM = {B10100, B00010, B00001, B00001, B00001, B00001, B00010, B10100};
byte image04[8] PROGMEM = {B00101, B00101, B10101, B10101, B10101, B10101, B00101, B00101};
byte image05[8] PROGMEM = {B10101, B10101, B10101, B10101, B10101, B10101, B10101, B10101};
byte image06[8] PROGMEM = {B10100, B10100, B10101, B10101, B10101, B10101, B10100, B10100};
#endif
#if PRG_TYPE == 1
//Bloky
byte image01[8] PROGMEM = {B00101, B01000, B10000, B10000, B10000, B10000, B01000, B00101};
byte image03[8] PROGMEM = {B10100, B00010, B00001, B00001, B00001, B00001, B00010, B10100};
byte image02[8] PROGMEM = {B10101, B00000, B00000, B00000, B00000, B00000, B00000, B10101};
byte image04[8] PROGMEM = {B00111, B01000, B10011, B10111, B10111, B10011, B01000, B00111};
byte image06[8] PROGMEM = {B11100, B00010, B11001, B11101, B11101, B11001, B00010, B11100};
byte image05[8] PROGMEM = {B11111, B00000, B11011, B11011, B11011, B11011, B00000, B11111};
#endif
_lcd.createChar(1, image01);
_lcd.createChar(2, image02);
_lcd.createChar(3, image03);
_lcd.createChar(4, image04);
_lcd.createChar(5, image05);
_lcd.createChar(6, image06);
_lcd.backlight(); // enable backlight for the LCD module
}
void loop()
{
for (uint32_t i = 0; i <= FILE_SIZE; i += (FILE_SIZE / 250)) //x kroků do velikosti souboru
{
PrintLCDFileTransfer("akvarko.dump", i, FILE_SIZE);
//delay(1000);
}
delay((3000));
}
//Stahovani 25.10%
//2000-10-10 10-~.dump
//|------------------|
//1023.1KiB/1023.1KiB
void PrintLCDFileTransfer(String fileName, uint32_t value, uint32_t maximum)
{
const String empty = F(" ");
String protocol = SF("UDP"); //Protokol
float percent = (float)value / (float)maximum * 100; //Procenta
_lcd.setCursor(0, 0);
//Stahovani UDP 25.10%
_lcd.print(SF("Stahovani") + empty + protocol + FormatPadLeft(String(percent, 2) + '%', 7, empty));
//2000-10-10 10-~.dump
_lcd.setCursor(0, 1);
_lcd.print(FormatPadLeft(String(fileName), LCD_COL, empty));
//|------------------|
_lcd.setCursor(0, 2);
uint16_t block = round(percent / (100 / LCD_COL));//0-20
char row[LCD_COL + 1]; //21 znaků (indxy 0-19) + index 20 = char 0
for (uint8_t i = 0; i <= LCD_COL; i++) //Iterace 0-20 (21 indexů)
{
byte ch = byte(0); //Výchozí (naplní konec pole)
if (i < LCD_COL) //Indexy 0-19 (20 = char(0))
{
//1,2,3 = Prázdný bloky
//4,5,6 = Plné bloky
ch = byte(2); //Střední blok je výchozí
if (i == 0) {
ch = byte(1); //Počáteční blok
}
if (i == LCD_COL - 1) {
ch = byte(3); //Koncový blok
}
if (block > 0 && i <= block - 1) {
ch += 3; //Plný blok
}
}
row[i] = ch;
}
_lcd.print(row);
//1023KiB/1023KiB
_lcd.setCursor(0, 3);
_lcd.print(FormatSize(value) + SF("/") + FormatSize(maximum) + empty);
}
//Z leva doplni zadanym znakem (případně ořízne na požadovanou délku)
String FormatPadLeft(String value, uint8_t len, String padChar)
{
String padString;
for (uint8_t i = 0; i < len; i++)
{
padString.concat(padChar);
}
padString.concat(value);
return padString.substring(padString.length() - len);
}
//Dynamicke zobrazeni velikosti na 9 znaku
//0000.0KiB
//0000.0MiB
String FormatSize(double bytes)
{
String units = F("B ");
String res = String(bytes, 0);
//KiB
bytes /= 1024;
if (bytes > 1) {
res = String(bytes);
units = F("KiB");
}
//MiB
bytes /= 1024;
if (bytes > 1) {
res = String(bytes);
units = F("MiB");
}
//GiB
bytes /= 1024;
if (bytes > 1) {
res = String(bytes);
units = F("GiB");
}
//TiB
bytes /= 1024;
if (bytes > 1) {
res = String(bytes);
units = F("TiB");
}
if (res.length() > 6) {
res = res.substring(0, 6); //Oriznuti desetinych mist
}
return FormatPadLeft(res + units, 9, F(" "));
}