Skip to content

Commit cf4cce5

Browse files
committed
Add ability to reset display without clearing CGRAM or turning display off.
1 parent 045c9dc commit cf4cce5

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun Qwiic OLED Graphics Library
2-
version=1.0.3
2+
version=1.0.4
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for SparkFun SSD1306 based OLED display products.

src/SparkFun_Qwiic_OLED.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,11 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
169169
//
170170
// Parameter Description
171171
// --------- -----------------------------
172-
// retval true on success, false on failure
172+
// clearDisplay true - clear the internal buffers during reset
173+
// retval true on success, false on failure
173174

174-
bool reset(void){
175-
return _device.reset();
175+
bool reset(bool clearDisplay){
176+
return _device.reset(clearDisplay);
176177
}
177178

178179
///////////////////////////////////////////////////////////////////////

src/qwiic_grssd1306.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ bool QwGrSSD1306::init(void)
264264
//
265265
// Returns true on success, false on failure
266266

267-
bool QwGrSSD1306::reset(void){
267+
bool QwGrSSD1306::reset(bool clearDisplay){
268268

269269
// If we are not in an init state, just call init
270270
if(!_isInit)
@@ -275,11 +275,11 @@ bool QwGrSSD1306::reset(void){
275275
return false;
276276

277277
// setup oled
278-
setup_oled_device();
278+
setup_oled_device(clearDisplay);
279279

280280
// Init internal/drawing buffers and device screen buffer
281-
282-
init_buffers();
281+
if(clearDisplay)
282+
init_buffers();
283283

284284
return true;
285285
}
@@ -320,11 +320,12 @@ void QwGrSSD1306::set_contrast(uint8_t contrast){
320320
// Method sends the init/setup commands to the OLED device, placing
321321
// it in a state for use by this driver/library.
322322

323-
void QwGrSSD1306::setup_oled_device(void){
323+
void QwGrSSD1306::setup_oled_device(bool clearDisplay){
324324

325325
// Start the device setup - sending commands to device. See command defs in header, and
326326
// device datasheet
327-
send_dev_command(kCmdDisplayOff);
327+
if(clearDisplay)
328+
send_dev_command(kCmdDisplayOff);
328329

329330
send_dev_command(kCmdSetDisplayClockDiv, 0x80);
330331
send_dev_command(kCmdSetMultiplex, _viewport.height - 1);
@@ -346,8 +347,8 @@ void QwGrSSD1306::setup_oled_device(void){
346347
send_dev_command(kCmdSetVComDeselect, _initVCOMDeselect);
347348
send_dev_command(kCmdDeactivateScroll);
348349

349-
send_dev_command(kCmdDisplayOn);
350-
350+
if(clearDisplay)
351+
send_dev_command(kCmdDisplayOn);
351352
}
352353
////////////////////////////////////////////////////////////////////////////////////
353354
// set_comm_bus()

src/qwiic_grssd1306.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class QwGrSSD1306 : public QwGrBufferDevice {
167167
// Device setup
168168
virtual bool init(void);
169169
bool is_initialized(void) { return _isInit; };
170-
bool reset(void);
170+
bool reset(bool clearDisplay = true);
171171

172172
// method to set the communication bus this object should use
173173
void set_comm_bus(QwI2C &theBus, uint8_t id_bus);
@@ -234,7 +234,7 @@ class QwGrSSD1306 : public QwGrBufferDevice {
234234
void init_buffers(void); // clear graphics and screen buffer
235235
void clear_screen_buffer(void);
236236
void resend_graphics(void);
237-
void setup_oled_device(void);
237+
void setup_oled_device(bool clearDisplay = true);
238238

239239
// device communication methods
240240
void send_dev_command(uint8_t command);

0 commit comments

Comments
 (0)