diff --git a/Adafruit_SSD1306.cpp b/Adafruit_SSD1306.cpp index 46218d7d..3136098b 100644 --- a/Adafruit_SSD1306.cpp +++ b/Adafruit_SSD1306.cpp @@ -1099,3 +1099,28 @@ void Adafruit_SSD1306::dim(boolean dim) { TRANSACTION_END } + +/**************************************************************************/ +/*! + @brief Scroll display up one line, reseting cursor y to print at bottom +*/ +/**************************************************************************/ +void Adafruit_SSD1306::scrollUp(void) { + /* + * - supporting oled 128x32 pixel display so know width + * -- a row of pixels 128 columns x 8 down is 8 * 16, left to right + */ + + // copy 2nd to last line from buffer to top of scroll buffer; (char pixel width with 8 as base size of 1) * (total pixel width / 8 as that is how this display is addressed) * (lines) + int intLineSize = ((textsize * SSD1306_PIXEL_CHUNK) * (WIDTH / SSD1306_PIXEL_CHUNK)); + memcpy(buffer, buffer + intLineSize, SSD1306_BUFF_SIZE - intLineSize); + + // clear buffer last line; (char pixel width with 8 as base size of 1) * (total pixel width / 8 as that is how this display is addressed) * (font size for height * lines) + int intOffsetLastLine = intLineSize * 3; + memset(buffer + intOffsetLastLine, 0, SSD1306_BUFF_SIZE - intOffsetLastLine); + + setCursor(cursor_x, (textsize * SSD1306_PIXEL_CHUNK) * 3); + +} + + diff --git a/Adafruit_SSD1306.h b/Adafruit_SSD1306.h index 2933cb0b..18b0a853 100644 --- a/Adafruit_SSD1306.h +++ b/Adafruit_SSD1306.h @@ -102,13 +102,15 @@ #if defined SSD1306_128_32 #define SSD1306_LCDWIDTH 128 ///< DEPRECATED: width w/SSD1306_128_32 defined #define SSD1306_LCDHEIGHT 32 ///< DEPRECATED: height w/SSD1306_128_32 defined + #define SSD1306_PIXEL_CHUNK 8 ///< for scrollUP(); 8 bit "pages"; see datasheet + #define SSD1306_BUFF_SIZE (128 * ((32 + 7) / 8)) ///< for scrollUP() #endif #if defined SSD1306_96_16 #define SSD1306_LCDWIDTH 96 ///< DEPRECATED: width w/SSD1306_96_16 defined #define SSD1306_LCDHEIGHT 16 ///< DEPRECATED: height w/SSD1306_96_16 defined #endif -/*! +/*! @brief Class that stores state and functions for interacting with SSD1306 OLED displays. */ @@ -149,6 +151,10 @@ class Adafruit_SSD1306 : public Adafruit_GFX { boolean getPixel(int16_t x, int16_t y); uint8_t *getBuffer(void); + // adding function to scroll display up a line; for use with println + void scrollUp(void); // scroll display up one line of text + + private: inline void SPIwrite(uint8_t d) __attribute__((always_inline)); void drawFastHLineInternal(int16_t x, int16_t y, int16_t w,