From 5161cca503a89a4de2d8e5021a396e6a4e4e4611 Mon Sep 17 00:00:00 2001 From: Blue Fox Date: Sun, 21 Aug 2022 17:04:44 +0200 Subject: [PATCH] Added display functinality --- losungepaper.ino | 128 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 123 insertions(+), 5 deletions(-) diff --git a/losungepaper.ino b/losungepaper.ino index afe72bb..2238c31 100755 --- a/losungepaper.ino +++ b/losungepaper.ino @@ -8,27 +8,141 @@ Epd epd; // style of the frame shown -sFONT TITLE_FONT = Font16; +sFONT TITLE_FONT = Font20; char TITLE_TEXT[] = "Losung heute"; +sFONT TEXT_FONT = Font12; // for the daily text +int TEXT_WIDTH = 168; // width of the box around the text; should be a multiple of the width of the font (eg. Font8 => multiple of 8) +int TEXT_PADDING_TOP = 40; +int TEXT_PADDING_BETWEEN_BLOCKS = 20; // pixels between the lines +int TEXT_PADDING_BETWEEN_LINES = 1; // pixels between the lines +sFONT SOURCE_FONT = Font8; // for the position in bible + + +String pad(String text, int pad_length, char pad_letter) { + if(text.length() >= pad_length) return text; // if theres nothing to fill, return the text unmodified + + for(int i = 0; text.length()maxRowsFloor) maxRows = maxRowsFloor+1.0; // if maxRows is e.g. 5.2, write the next-bigger integer into maxRows + + return maxRows; +} + +/* text_of_row_x tells which row shall be given, 0 for first row */ +String getRow(String text, int width, int letter_width, int text_of_row_x) { // width should be a multiple of letter_width to fit perfect + // calculate needed vars + int lettersPerRow = width / letter_width; + int maxRows = getMaxRows(text, width, letter_width); + text = pad(text, maxRows*lettersPerRow, ' '); + + // some tests + if(text_of_row_x > maxRows) return String(); + if(text_of_row_x < 0) return String(); + + return text.substring(lettersPerRow*text_of_row_x, lettersPerRow*(text_of_row_x+1)); +} + +// remove special characters (ä,ö,ü,ß) +String removeSpecialChars(String text) { + text.replace("ä", "ae"); + text.replace("Ä", "AE"); + text.replace("ö", "oe"); + text.replace("Ö", "OE"); + text.replace("ü", "ue"); + text.replace("Ü", "UE"); + text.replace("ß", "ss"); + text.replace("ẞ", "SS"); + + return text; +} + +// show the daily text on the epd +void showDailyText(String losung, String lehrtext, String losungPosition, String lehrtextPosition) { + // clean the strings for + losung = removeSpecialChars(losung); + lehrtext = removeSpecialChars(lehrtext); + + Serial.println(lehrtext); + + // position vars + int text_x = 0; + int text_y = 0; -void showDailyText() { /* This clears the SRAM of the e-paper display and displays it */ epd.ClearFrame(); epd.DisplayFrame(); // now the drawing init unsigned char image[2048]; - Paint paint(image, 176, 30); // width should be the multiple of 8 + Paint paint(image, 176, TITLE_FONT.Height+2); // width should be the multiple of 8 + // display title paint.Clear(UNCOLORED); int startTitleAtX = round((paint.GetWidth()-strlen(TITLE_TEXT)*TITLE_FONT.Width)/2); paint.DrawStringAt(startTitleAtX, 2, TITLE_TEXT, &TITLE_FONT, COLORED); paint.DrawHorizontalLine(startTitleAtX+15, TITLE_FONT.Height+1, paint.GetWidth()-(startTitleAtX+15)*2, COLORED); - epd.TransmitPartialData(paint.GetImage(), 0, 0, paint.GetWidth(), paint.GetHeight()); - epd.RefreshPartial(0, 0, paint.GetWidth(), paint.GetHeight()); + epd.TransmitPartialData(paint.GetImage(), text_x, text_y, paint.GetWidth(), paint.GetHeight()); + text_y += TITLE_FONT.Height+2; + + // Losung + paint.SetWidth(TEXT_WIDTH); + paint.SetHeight(TEXT_FONT.Height); + text_y += TEXT_PADDING_TOP; + + for(int row = 0; row