From 241f8cc1c979520f9e1c7d6dce2bbfed8f5618ad Mon Sep 17 00:00:00 2001 From: Bill Greiman Date: Mon, 27 Jun 2022 11:09:58 -0700 Subject: [PATCH] Force CR/LF for Code Page 437 fonts --- library.properties | 2 +- src/SSD1306Ascii.cpp | 49 ++++++++++++++++++++-------------------- src/SSD1306Ascii.h | 4 ++-- src/fonts/Adafruit5x7.h | 2 ++ src/fonts/ZevvPeep8x16.h | 6 ++--- 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/library.properties b/library.properties index 3269ecb..c983d79 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SSD1306Ascii -version=1.3.2 +version=1.3.3 author=Bill Greiman maintainer=Bill Greiman sentence=Text display on small momochrome OLED modules. diff --git a/src/SSD1306Ascii.cpp b/src/SSD1306Ascii.cpp index 9829fb5..d408ffa 100644 --- a/src/SSD1306Ascii.cpp +++ b/src/SSD1306Ascii.cpp @@ -305,34 +305,35 @@ size_t SSD1306Ascii::write(uint8_t ch) { uint8_t count = readFontByte(m_font + FONT_CHAR_COUNT); const uint8_t* base = m_font + FONT_WIDTH_TABLE; - if (ch < first || ch >= (first + count)) { - if (ch == '\r') { - setCol(0); - return 1; - } - if (ch == '\n') { - setCol(0); - uint8_t fr = m_magFactor*nr; + if (ch == '\r') { + setCol(0); + return 1; + } + if (ch == '\n') { + setCol(0); + uint8_t fr = m_magFactor*nr; #if INCLUDE_SCROLLING - uint8_t dr = displayRows(); - uint8_t tmpRow = m_row + fr; - int8_t delta = tmpRow + fr - dr; - if (m_scrollMode == SCROLL_MODE_OFF || delta <= 0) { - setRow(tmpRow); - } else { - m_pageOffset = (m_pageOffset + delta) & 7; - m_row = dr - fr; - // Cursor will be positioned by clearToEOL. - clearToEOL(); - if (m_scrollMode == SCROLL_MODE_AUTO) { - setStartLine(8*m_pageOffset); - } + uint8_t dr = displayRows(); + uint8_t tmpRow = m_row + fr; + int8_t delta = tmpRow + fr - dr; + if (m_scrollMode == SCROLL_MODE_OFF || delta <= 0) { + setRow(tmpRow); + } else { + m_pageOffset = (m_pageOffset + delta) & 7; + m_row = dr - fr; + // Cursor will be positioned by clearToEOL. + clearToEOL(); + if (m_scrollMode == SCROLL_MODE_AUTO) { + setStartLine(8*m_pageOffset); } + } #else // INCLUDE_SCROLLING - setRow(m_row + fr); + setRow(m_row + fr); #endif // INCLUDE_SCROLLING - return 1; - } + return 1; + } + // Error if not in font. + if (ch < first || (first + count) <= ch) { return 0; } ch -= first; diff --git a/src/SSD1306Ascii.h b/src/SSD1306Ascii.h index c15d5ea..bbf9e13 100644 --- a/src/SSD1306Ascii.h +++ b/src/SSD1306Ascii.h @@ -28,7 +28,7 @@ #include "fonts/allFonts.h" //------------------------------------------------------------------------------ /** SSD1306Ascii version */ -#define SDD1306_ASCII_VERSION 10302 +#define SDD1306_ASCII_VERSION 10303 //------------------------------------------------------------------------------ // Configuration options. /** Set Scrolling mode for newline. @@ -443,7 +443,7 @@ class SSD1306Ascii : public Print { * @brief Advance ticker by one pixel. * * @param[in,out] state Ticker state. - * @return Number of entries in text pointer queue. + * @return Number of entries in text pointer queue or -1 if an error occurs. */ int8_t tickerTick(TickerState* state); /** diff --git a/src/fonts/Adafruit5x7.h b/src/fonts/Adafruit5x7.h index 4d1a29e..563de6d 100644 --- a/src/fonts/Adafruit5x7.h +++ b/src/fonts/Adafruit5x7.h @@ -3,7 +3,9 @@ // standard ascii 5x7 font // Restrict to 96 characters +#ifndef ADAFRUIT_ASCII96 #define ADAFRUIT_ASCII96 1 +#endif // ADAFRUIT_ASCII96 GLCDFONTDECL(Adafruit5x7) = { 0x0, 0x0, // size of zero indicates fixed width font, 0x05, // width diff --git a/src/fonts/ZevvPeep8x16.h b/src/fonts/ZevvPeep8x16.h index ddddd2b..d68b7d0 100644 --- a/src/fonts/ZevvPeep8x16.h +++ b/src/fonts/ZevvPeep8x16.h @@ -1,7 +1,7 @@ // STARTFONT 2.1 // FONT -zevv-peep-Medium-R-Normal--16-140-75-75-C-80-ISO8859-1 -#ifndef font8x16_h -#define font8x16_h +#ifndef ZevvPeep8x16_h +#define ZevvPeep8x16_h GLCDFONTDECL(ZevvPeep8x16) = { 0x0, 0x0, // size of zero indicates fixed width font, @@ -106,4 +106,4 @@ GLCDFONTDECL(ZevvPeep8x16) = { 0X30,0X08,0X08,0X10,0X20,0X20,0X18,0X00,0X00,0X00,0X00,0X00,0X00,0X00, // '~' 0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0X7F,0X7F,0X7F,0X7F,0X7F,0X7F,0X7F // del }; -#endif // font8x16_h \ No newline at end of file +#endif // ZevvPeep8x16_h