diff --git a/SSD1306Ascii.cpp b/SSD1306Ascii.cpp index e125eff..bc13270 100644 --- a/SSD1306Ascii.cpp +++ b/SSD1306Ascii.cpp @@ -73,6 +73,8 @@ void SSD1306Ascii::setCursor(uint8_t col, uint8_t row) { //------------------------------------------------------------------------------ void SSD1306Ascii::setFont(const uint8_t* font) { m_font = font; + fontFirstChar = readFontByte(m_font + FONT_FIRST_CHAR); + fontCharCount = readFontByte(m_font + FONT_CHAR_COUNT); } //------------------------------------------------------------------------------ void SSD1306Ascii::setRow(uint8_t row) { @@ -101,10 +103,6 @@ size_t SSD1306Ascii::write(uint8_t ch) { return 0; } const uint8_t* base = m_font + FONT_WIDTH_TABLE; - const uint8_t letterSpacing = 1; - uint8_t fontFirstChar = readFontByte(m_font + FONT_FIRST_CHAR); - uint8_t fontCharCount = readFontByte(m_font + FONT_CHAR_COUNT); - uint8_t fontWidth = readFontByte(m_font + FONT_WIDTH); if (ch < fontFirstChar || ch >= (fontFirstChar + fontCharCount)) return 0; ch -= fontFirstChar; diff --git a/SSD1306Ascii.h b/SSD1306Ascii.h index 16a3556..84dc390 100644 --- a/SSD1306Ascii.h +++ b/SSD1306Ascii.h @@ -195,6 +195,13 @@ class SSD1306Ascii : public Print { uint8_t m_displayHeight; // Display height. uint8_t m_colOffset; // Column offset RAM to SEG. const uint8_t* m_font = nullptr; // Current font. + + // Only fixed size 5x7 fonts in a 6x8 cell are supported. + const int fontWidth = 5; + const int fontHeight = 7; + const uint8_t letterSpacing = 1; + uint8_t fontFirstChar; + uint8_t fontCharCount; };