Skip to content

Commit d5cada2

Browse files
authored
Merge pull request #183 from Rotzbua/improve_constructor
improve constructor
2 parents 102bb14 + 478e8a5 commit d5cada2

File tree

14 files changed

+35
-98
lines changed

14 files changed

+35
-98
lines changed

OLEDDisplay.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,18 @@ size_t OLEDDisplay::write(const char* str) {
714714
}
715715

716716
// Private functions
717+
void OLEDDisplay::setGeometry(OLEDDISPLAY_GEOMETRY g) {
718+
this->geometry = g;
719+
if (g == GEOMETRY_128_64) {
720+
this->displayWidth = 128;
721+
this->displayHeight = 64;
722+
} else if (g == GEOMETRY_128_32) {
723+
this->displayWidth = 128;
724+
this->displayHeight = 32;
725+
}
726+
this->displayBufferSize = displayWidth*displayHeight/8;
727+
}
728+
717729
void OLEDDisplay::sendInitCommands(void) {
718730
sendCommand(DISPLAYOFF);
719731
sendCommand(SETDISPLAYCLOCKDIV);
@@ -854,4 +866,4 @@ char* OLEDDisplay::utf8ascii(String str) {
854866

855867
void OLEDDisplay::setFontTableLookupFunction(FontTableLookupFunction function) {
856868
this->fontTableLookupFunction = function;
857-
}
869+
}

OLEDDisplay.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ class OLEDDisplay : public Print {
265265
uint16_t displayWidth = 128;
266266
uint16_t displayHeight = 64;
267267
uint16_t displayBufferSize = 1024;
268+
269+
// Set the correct height, width and buffer for the geometry
270+
void setGeometry(OLEDDISPLAY_GEOMETRY g);
268271

269272
OLEDDISPLAY_TEXT_ALIGNMENT textAlignment = TEXT_ALIGN_LEFT;
270273
OLEDDISPLAY_COLOR color = WHITE;

SH1106Brzo.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,8 @@ class SH1106Brzo : public OLEDDisplay {
4444
uint8_t _scl;
4545

4646
public:
47-
SH1106Brzo(uint8_t _address, uint8_t _sda, uint8_t _scl) : SH1106Brzo(GEOMETRY_128_64, _address, _sda, _scl) {
48-
49-
}
50-
51-
SH1106Brzo(OLEDDISPLAY_GEOMETRY g, uint8_t _address, uint8_t _sda, uint8_t _scl) {
52-
this->geometry = g;
53-
if (g == GEOMETRY_128_64) {
54-
this->displayWidth = 128;
55-
this->displayHeight = 64;
56-
this->displayBufferSize = 1024;
57-
} else if (g == GEOMETRY_128_32) {
58-
this->displayWidth = 128;
59-
this->displayHeight = 32;
60-
this->displayBufferSize = 512;
61-
}
47+
SH1106Brzo(uint8_t _address, uint8_t _sda, uint8_t _scl, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) {
48+
setGeometry(g);
6249

6350
this->_address = _address;
6451
this->_sda = _sda;

SH1106Spi.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,8 @@ class SH1106Spi : public OLEDDisplay {
3737
uint8_t _dc;
3838

3939
public:
40-
SH1106Spi(uint8_t _rst, uint8_t _dc) : SH1106Spi(GEOMETRY_128_64, _rst, _dc) {
41-
42-
}
43-
44-
SH1106Spi(OLEDDISPLAY_GEOMETRY g, uint8_t _rst, uint8_t _dc) {
45-
this->geometry = g;
46-
if (g == GEOMETRY_128_64) {
47-
this->displayWidth = 128;
48-
this->displayHeight = 64;
49-
this->displayBufferSize = 1024;
50-
} else if (g == GEOMETRY_128_32) {
51-
this->displayWidth = 128;
52-
this->displayHeight = 32;
53-
this->displayBufferSize = 512;
54-
}
40+
SH1106Spi(uint8_t _rst, uint8_t _dc, uint8_t _cs, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) {
41+
setGeometry(g);
5542

5643
this->_rst = _rst;
5744
this->_dc = _dc;

SH1106Wire.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,8 @@ class SH1106Wire : public OLEDDisplay {
4444
uint8_t _scl;
4545

4646
public:
47-
SH1106Wire(uint8_t _address, uint8_t _sda, uint8_t _scl) : SH1106Wire(GEOMETRY_128_64, _address, _sda, _scl) {
48-
49-
}
50-
51-
SH1106Wire(OLEDDISPLAY_GEOMETRY g, uint8_t _address, uint8_t _sda, uint8_t _scl) {
52-
this->geometry = g;
53-
if (g == GEOMETRY_128_64) {
54-
this->displayWidth = 128;
55-
this->displayHeight = 64;
56-
this->displayBufferSize = 1024;
57-
} else if (g == GEOMETRY_128_32) {
58-
this->displayWidth = 128;
59-
this->displayHeight = 32;
60-
this->displayBufferSize = 512;
61-
}
47+
SH1106Wire(uint8_t _address, uint8_t _sda, uint8_t _scl, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) {
48+
setGeometry(g);
6249

6350
this->_address = _address;
6451
this->_sda = _sda;

SSD1306Brzo.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,8 @@ class SSD1306Brzo : public OLEDDisplay {
4444
uint8_t _scl;
4545

4646
public:
47-
SSD1306Brzo(uint8_t _address, uint8_t _sda, uint8_t _scl) : SSD1306Brzo(GEOMETRY_128_64, _address, _sda, _scl) {
48-
49-
}
50-
51-
SSD1306Brzo(OLEDDISPLAY_GEOMETRY g, uint8_t _address, uint8_t _sda, uint8_t _scl) {
52-
this->geometry = g;
53-
if (g == GEOMETRY_128_64) {
54-
this->displayWidth = 128;
55-
this->displayHeight = 64;
56-
this->displayBufferSize = 1024;
57-
} else if (g == GEOMETRY_128_32) {
58-
this->displayWidth = 128;
59-
this->displayHeight = 32;
60-
this->displayBufferSize = 512;
61-
}
47+
SSD1306Brzo(uint8_t _address, uint8_t _sda, uint8_t _scl, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) {
48+
setGeometry(g);
6249

6350
this->_address = _address;
6451
this->_sda = _sda;

SSD1306Spi.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,8 @@ class SSD1306Spi : public OLEDDisplay {
4444
uint8_t _cs;
4545

4646
public:
47-
SSD1306Spi(uint8_t _rst, uint8_t _dc, uint8_t _cs) : SSD1306Spi(GEOMETRY_128_64, _rst, _dc, _cs) {
48-
49-
}
50-
51-
SSD1306Spi(OLEDDISPLAY_GEOMETRY g, uint8_t _rst, uint8_t _dc, uint8_t _cs) {
52-
this->geometry = g;
53-
if (g == GEOMETRY_128_64) {
54-
this->displayWidth = 128;
55-
this->displayHeight = 64;
56-
this->displayBufferSize = 1024;
57-
} else if (g == GEOMETRY_128_32) {
58-
this->displayWidth = 128;
59-
this->displayHeight = 32;
60-
this->displayBufferSize = 512;
61-
}
47+
SSD1306Spi(uint8_t _rst, uint8_t _dc, uint8_t _cs, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) {
48+
setGeometry(g);
6249

6350
this->_rst = _rst;
6451
this->_dc = _dc;

SSD1306Wire.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,8 @@ class SSD1306Wire : public OLEDDisplay {
3939
bool _doI2cAutoInit = false;
4040

4141
public:
42-
SSD1306Wire(uint8_t _address, uint8_t _sda, uint8_t _scl) : SSD1306Wire(GEOMETRY_128_64, _address, _sda, _scl) {
43-
44-
}
45-
46-
SSD1306Wire(OLEDDISPLAY_GEOMETRY g, uint8_t _address, uint8_t _sda, uint8_t _scl) {
47-
this->geometry = g;
48-
if (g == GEOMETRY_128_64) {
49-
this->displayWidth = 128;
50-
this->displayHeight = 64;
51-
this->displayBufferSize = 1024;
52-
} else if (g == GEOMETRY_128_32) {
53-
this->displayWidth = 128;
54-
this->displayHeight = 32;
55-
this->displayBufferSize = 512;
56-
}
42+
SSD1306Wire(uint8_t _address, uint8_t _sda, uint8_t _scl, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) {
43+
setGeometry(g);
5744

5845
this->_address = _address;
5946
this->_sda = _sda;

examples/SSD1306ClockDemo/SSD1306ClockDemo.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
// SH1106Brzo display(0x3c, D3, D5);
6767

6868
// Initialize the OLED display using Wire library
69-
SSD1306 display(GEOMETRY_128_64, 0x3c, D3, D5);
69+
SSD1306 display(0x3c, D3, D5);
7070
// SH1106 display(0x3c, D3, D5);
7171

7272
OLEDDisplayUi ui ( &display );

examples/SSD1306DrawingDemo/SSD1306DrawingDemo.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
// SH1106Brzo display(0x3c, D3, D5);
5959

6060
// Initialize the OLED display using Wire library
61-
SSD1306 display(GEOMETRY_128_64, 0x3c, D3, D5);
61+
SSD1306 display(0x3c, D3, D5);
6262
// SH1106 display(0x3c, D3, D5);
6363

6464
// Adapted from Adafruit_SSD1306

0 commit comments

Comments
 (0)