diff --git a/OLEDDisplay.cpp b/OLEDDisplay.cpp index 9caf84fd244f7105b5372773a836703dfc2a7d34..cc48374662ebb7093903858eda58767402fab541 100644 --- a/OLEDDisplay.cpp +++ b/OLEDDisplay.cpp @@ -714,6 +714,18 @@ size_t OLEDDisplay::write(const char* str) { } // Private functions +void OLEDDisplay::setGeometry(OLEDDISPLAY_GEOMETRY g) { + this->geometry = g; + if (g == GEOMETRY_128_64) { + this->displayWidth = 128; + this->displayHeight = 64; + } else if (g == GEOMETRY_128_32) { + this->displayWidth = 128; + this->displayHeight = 32; + } + this->displayBufferSize = displayWidth*displayHeight/8; +} + void OLEDDisplay::sendInitCommands(void) { sendCommand(DISPLAYOFF); sendCommand(SETDISPLAYCLOCKDIV); @@ -854,4 +866,4 @@ char* OLEDDisplay::utf8ascii(String str) { void OLEDDisplay::setFontTableLookupFunction(FontTableLookupFunction function) { this->fontTableLookupFunction = function; -} \ No newline at end of file +} diff --git a/OLEDDisplay.h b/OLEDDisplay.h index 93263236cb0d9897f960706366fc8170e91bf8ed..3fd56dc21bf2caf2aa319c3d39c090c1b6befcd6 100644 --- a/OLEDDisplay.h +++ b/OLEDDisplay.h @@ -265,6 +265,9 @@ class OLEDDisplay : public Print { uint16_t displayWidth = 128; uint16_t displayHeight = 64; uint16_t displayBufferSize = 1024; + + // Set the correct height, width and buffer for the geometry + void setGeometry(OLEDDISPLAY_GEOMETRY g); OLEDDISPLAY_TEXT_ALIGNMENT textAlignment = TEXT_ALIGN_LEFT; OLEDDISPLAY_COLOR color = WHITE; diff --git a/SH1106Brzo.h b/SH1106Brzo.h index 85d7372754056abf628d93933fd36dae4b213873..a65906356a48b5e0743c887a10380dd11e6697ef 100644 --- a/SH1106Brzo.h +++ b/SH1106Brzo.h @@ -44,21 +44,8 @@ class SH1106Brzo : public OLEDDisplay { uint8_t _scl; public: - SH1106Brzo(uint8_t _address, uint8_t _sda, uint8_t _scl) : SH1106Brzo(GEOMETRY_128_64, _address, _sda, _scl) { - - } - - SH1106Brzo(OLEDDISPLAY_GEOMETRY g, uint8_t _address, uint8_t _sda, uint8_t _scl) { - this->geometry = g; - if (g == GEOMETRY_128_64) { - this->displayWidth = 128; - this->displayHeight = 64; - this->displayBufferSize = 1024; - } else if (g == GEOMETRY_128_32) { - this->displayWidth = 128; - this->displayHeight = 32; - this->displayBufferSize = 512; - } + SH1106Brzo(uint8_t _address, uint8_t _sda, uint8_t _scl, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) { + setGeometry(g); this->_address = _address; this->_sda = _sda; diff --git a/SH1106Spi.h b/SH1106Spi.h index 45d9ccf7b7f76f4fc74cccda06bacda5a99c1ff6..99ded8d7374a3c771820bc41aebae0987e697a95 100644 --- a/SH1106Spi.h +++ b/SH1106Spi.h @@ -37,21 +37,8 @@ class SH1106Spi : public OLEDDisplay { uint8_t _dc; public: - SH1106Spi(uint8_t _rst, uint8_t _dc) : SH1106Spi(GEOMETRY_128_64, _rst, _dc) { - - } - - SH1106Spi(OLEDDISPLAY_GEOMETRY g, uint8_t _rst, uint8_t _dc) { - this->geometry = g; - if (g == GEOMETRY_128_64) { - this->displayWidth = 128; - this->displayHeight = 64; - this->displayBufferSize = 1024; - } else if (g == GEOMETRY_128_32) { - this->displayWidth = 128; - this->displayHeight = 32; - this->displayBufferSize = 512; - } + SH1106Spi(uint8_t _rst, uint8_t _dc, uint8_t _cs, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) { + setGeometry(g); this->_rst = _rst; this->_dc = _dc; diff --git a/SH1106Wire.h b/SH1106Wire.h index 6bb95e75e44b2317de70c20bdcd8eba31d4c9ff4..e1687397297bc994875e7aeb22700fe4da6aa02f 100644 --- a/SH1106Wire.h +++ b/SH1106Wire.h @@ -44,21 +44,8 @@ class SH1106Wire : public OLEDDisplay { uint8_t _scl; public: - SH1106Wire(uint8_t _address, uint8_t _sda, uint8_t _scl) : SH1106Wire(GEOMETRY_128_64, _address, _sda, _scl) { - - } - - SH1106Wire(OLEDDISPLAY_GEOMETRY g, uint8_t _address, uint8_t _sda, uint8_t _scl) { - this->geometry = g; - if (g == GEOMETRY_128_64) { - this->displayWidth = 128; - this->displayHeight = 64; - this->displayBufferSize = 1024; - } else if (g == GEOMETRY_128_32) { - this->displayWidth = 128; - this->displayHeight = 32; - this->displayBufferSize = 512; - } + SH1106Wire(uint8_t _address, uint8_t _sda, uint8_t _scl, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) { + setGeometry(g); this->_address = _address; this->_sda = _sda; diff --git a/SSD1306Brzo.h b/SSD1306Brzo.h index edd3f53cb76ce3c9a54f01c039f368a6a0682ee5..3753a02a493c20d30ef48eb25ef51b1fc0e774b4 100644 --- a/SSD1306Brzo.h +++ b/SSD1306Brzo.h @@ -44,21 +44,8 @@ class SSD1306Brzo : public OLEDDisplay { uint8_t _scl; public: - SSD1306Brzo(uint8_t _address, uint8_t _sda, uint8_t _scl) : SSD1306Brzo(GEOMETRY_128_64, _address, _sda, _scl) { - - } - - SSD1306Brzo(OLEDDISPLAY_GEOMETRY g, uint8_t _address, uint8_t _sda, uint8_t _scl) { - this->geometry = g; - if (g == GEOMETRY_128_64) { - this->displayWidth = 128; - this->displayHeight = 64; - this->displayBufferSize = 1024; - } else if (g == GEOMETRY_128_32) { - this->displayWidth = 128; - this->displayHeight = 32; - this->displayBufferSize = 512; - } + SSD1306Brzo(uint8_t _address, uint8_t _sda, uint8_t _scl, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) { + setGeometry(g); this->_address = _address; this->_sda = _sda; diff --git a/SSD1306Spi.h b/SSD1306Spi.h index 0984298a8428e4587f8b1dee297e4ddf91862a68..faf2344f7e4c93ed89dd2ed4cf5c5d2deaf12017 100644 --- a/SSD1306Spi.h +++ b/SSD1306Spi.h @@ -44,21 +44,8 @@ class SSD1306Spi : public OLEDDisplay { uint8_t _cs; public: - SSD1306Spi(uint8_t _rst, uint8_t _dc, uint8_t _cs) : SSD1306Spi(GEOMETRY_128_64, _rst, _dc, _cs) { - - } - - SSD1306Spi(OLEDDISPLAY_GEOMETRY g, uint8_t _rst, uint8_t _dc, uint8_t _cs) { - this->geometry = g; - if (g == GEOMETRY_128_64) { - this->displayWidth = 128; - this->displayHeight = 64; - this->displayBufferSize = 1024; - } else if (g == GEOMETRY_128_32) { - this->displayWidth = 128; - this->displayHeight = 32; - this->displayBufferSize = 512; - } + SSD1306Spi(uint8_t _rst, uint8_t _dc, uint8_t _cs, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) { + setGeometry(g); this->_rst = _rst; this->_dc = _dc; diff --git a/SSD1306Wire.h b/SSD1306Wire.h index 312bdea838e6efd41c0174ba3b06bfe46b69dde0..40831394d20007ef21ba0c7708e7863badee21be 100644 --- a/SSD1306Wire.h +++ b/SSD1306Wire.h @@ -39,21 +39,8 @@ class SSD1306Wire : public OLEDDisplay { bool _doI2cAutoInit = false; public: - SSD1306Wire(uint8_t _address, uint8_t _sda, uint8_t _scl) : SSD1306Wire(GEOMETRY_128_64, _address, _sda, _scl) { - - } - - SSD1306Wire(OLEDDISPLAY_GEOMETRY g, uint8_t _address, uint8_t _sda, uint8_t _scl) { - this->geometry = g; - if (g == GEOMETRY_128_64) { - this->displayWidth = 128; - this->displayHeight = 64; - this->displayBufferSize = 1024; - } else if (g == GEOMETRY_128_32) { - this->displayWidth = 128; - this->displayHeight = 32; - this->displayBufferSize = 512; - } + SSD1306Wire(uint8_t _address, uint8_t _sda, uint8_t _scl, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) { + setGeometry(g); this->_address = _address; this->_sda = _sda;