#include "epd2in7.h" #include "epdpaint.h" // b/w e-Paper #define COLORED 0 #define UNCOLORED 1 Epd epd; // style of the frame shown 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; /* 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, 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(), 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