Skip to content

Commit 6aa3629

Browse files
authored
Add two displays support for sh1106 (#290)
1 parent b55edff commit 6aa3629

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/SH1106Wire.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class SH1106Wire : public OLEDDisplay {
4545
uint8_t _address;
4646
uint8_t _sda;
4747
uint8_t _scl;
48+
bool _doI2cAutoInit = false;
4849

4950
public:
5051
SH1106Wire(uint8_t _address, uint8_t _sda, uint8_t _scl, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64) {
@@ -64,6 +65,7 @@ class SH1106Wire : public OLEDDisplay {
6465
}
6566

6667
void display(void) {
68+
initI2cIfNeccesary();
6769
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
6870
uint8_t minBoundY = UINT8_MAX;
6971
uint8_t maxBoundY = 0;
@@ -143,6 +145,10 @@ class SH1106Wire : public OLEDDisplay {
143145
#endif
144146
}
145147

148+
void setI2cAutoInit(bool doI2cAutoInit) {
149+
_doI2cAutoInit = doI2cAutoInit;
150+
}
151+
146152
private:
147153
int getBufferOffset(void) {
148154
return 0;
@@ -154,6 +160,15 @@ class SH1106Wire : public OLEDDisplay {
154160
Wire.endTransmission();
155161
}
156162

163+
void initI2cIfNeccesary() {
164+
if (_doI2cAutoInit) {
165+
#ifdef ARDUINO_ARCH_AVR
166+
Wire.begin();
167+
#else
168+
Wire.begin(this->_sda, this->_scl);
169+
#endif
170+
}
171+
}
157172

158173
};
159174

0 commit comments

Comments
 (0)