diff --git a/display.ino b/display.ino new file mode 100644 index 0000000..3ff1096 --- /dev/null +++ b/display.ino @@ -0,0 +1,123 @@ +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= 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