Skip to content

Two displays support for sh1106 displays #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/SH1106Wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class SH1106Wire : public OLEDDisplay {
uint8_t _address;
uint8_t _sda;
uint8_t _scl;
bool _doI2cAutoInit = false;

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

void display(void) {
initI2cIfNeccesary();
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
uint8_t minBoundY = UINT8_MAX;
uint8_t maxBoundY = 0;
Expand Down Expand Up @@ -143,6 +145,10 @@ class SH1106Wire : public OLEDDisplay {
#endif
}

void setI2cAutoInit(bool doI2cAutoInit) {
_doI2cAutoInit = doI2cAutoInit;
}

private:
int getBufferOffset(void) {
return 0;
Expand All @@ -154,6 +160,15 @@ class SH1106Wire : public OLEDDisplay {
Wire.endTransmission();
}

void initI2cIfNeccesary() {
if (_doI2cAutoInit) {
#ifdef ARDUINO_ARCH_AVR
Wire.begin();
#else
Wire.begin(this->_sda, this->_scl);
#endif
}
}

};

Expand Down