Skip to content

Commit 1f0da2d

Browse files
author
Kirk
committed
added reset command and ability to control display power -- both need testing
1 parent c4161ce commit 1f0da2d

File tree

3 files changed

+106
-25
lines changed

3 files changed

+106
-25
lines changed

src/SparkFun_Qwiic_OLED.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
162162
return _device.get_height();
163163
}
164164

165+
///////////////////////////////////////////////////////////////////////
166+
// reset()
167+
//
168+
// When called, the system and OLED are reset back to an initial state
169+
//
170+
171+
void reset(void){
172+
_device.reset();
173+
}
174+
165175
///////////////////////////////////////////////////////////////////////
166176
// display()
167177
//
@@ -322,6 +332,21 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
322332
_device.scroll(SCROLL_VERT_LEFT, start, stop, interval);
323333
}
324334

335+
///////////////////////////////////////////////////////////////////////
336+
// displayPower()
337+
//
338+
// Used to turn the OLED display on an off.
339+
//
340+
// Default value is on.
341+
//
342+
// Parameter Description
343+
// --------- -----------------------------
344+
// enable Turn the display on or off - default is on
345+
346+
void displayPower(bool enable=true){
347+
348+
_device.display_power(enable);
349+
}
325350
///////////////////////////////////////////////////////////////////////
326351
// setFont()
327352
//

src/qwiic_grssd1306.cpp

Lines changed: 77 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -241,31 +241,8 @@ bool QwGrSSD1306::init(void)
241241
if(!this->QwGrBufferDevice::init())
242242
return false; // something isn't right
243243

244-
// Start the device setup - sending commands to device. See command defs in header, and
245-
// device datasheet
246-
send_dev_command(kCmdDisplayOff);
247-
248-
send_dev_command(kCmdSetDisplayClockDiv, 0x80);
249-
send_dev_command(kCmdSetMultiplex, _viewport.height - 1);
250-
send_dev_command(kCmdSetDisplayOffset, 0x0);
251-
252-
send_dev_command(kCmdSetStartLine | 0x0);
253-
send_dev_command(kCmdChargePump, 0x14);
254-
send_dev_command(kCmdMemoryMode, 0b10); // Page Addressing mode - see data sheet
255-
256-
send_dev_command(kCmdNormalDisplay);
257-
send_dev_command(kCmdDisplayAllOnResume);
258-
send_dev_command(kCmdSegRemap | 0x1);
259-
260-
send_dev_command(kCmdComScanDec);
261-
send_dev_command(kCmdSetComPins, _initHWComPins);
262-
send_dev_command(kCmdSetContrast, _initContrast);
263-
264-
send_dev_command(kCmdSetPreCharge, _initPreCharge);
265-
send_dev_command(kCmdSetVComDeselect, _initVCOMDeselect);
266-
send_dev_command(kCmdDeactivateScroll);
267-
268-
send_dev_command(kCmdDisplayOn);
244+
// setup the oled device
245+
setup_oled_device();
269246

270247
// Finish up setting up this object
271248

@@ -279,6 +256,33 @@ bool QwGrSSD1306::init(void)
279256

280257
return true;
281258
}
259+
260+
////////////////////////////////////////////////////////////////////////////////////
261+
// reset()
262+
//
263+
// Return the OLED system to its initial state
264+
//
265+
// Returns true on success, false on failure
266+
267+
bool QwGrSSD1306::reset(void){
268+
269+
// If we are not in an init state, just call init
270+
if(!_isInit)
271+
return init();
272+
273+
// is the device connected?
274+
if(!_i2cBus->ping(_i2c_address))
275+
return false;
276+
277+
// setup oled
278+
setup_oled_device();
279+
280+
// Init internal/drawing buffers and device screen buffer
281+
282+
init_buffers();
283+
284+
return true;
285+
}
282286
////////////////////////////////////////////////////////////////////////////////////
283287
// Configuration API
284288
//
@@ -310,6 +314,41 @@ void QwGrSSD1306::set_contrast(uint8_t contrast){
310314
send_dev_command(kCmdSetContrast, contrast);
311315
}
312316

317+
////////////////////////////////////////////////////////////////////////////////////
318+
// setup_oled_device()
319+
//
320+
// Method sends the init/setup commands to the OLED device, placing
321+
// it in a state for use by this driver/library.
322+
323+
void QwGrSSD1306::setup_oled_device(void){
324+
325+
// Start the device setup - sending commands to device. See command defs in header, and
326+
// device datasheet
327+
send_dev_command(kCmdDisplayOff);
328+
329+
send_dev_command(kCmdSetDisplayClockDiv, 0x80);
330+
send_dev_command(kCmdSetMultiplex, _viewport.height - 1);
331+
send_dev_command(kCmdSetDisplayOffset, 0x0);
332+
333+
send_dev_command(kCmdSetStartLine | 0x0);
334+
send_dev_command(kCmdChargePump, 0x14);
335+
send_dev_command(kCmdMemoryMode, 0b10); // Page Addressing mode - see data sheet
336+
337+
send_dev_command(kCmdNormalDisplay);
338+
send_dev_command(kCmdDisplayAllOnResume);
339+
send_dev_command(kCmdSegRemap | 0x1);
340+
341+
send_dev_command(kCmdComScanDec);
342+
send_dev_command(kCmdSetComPins, _initHWComPins);
343+
send_dev_command(kCmdSetContrast, _initContrast);
344+
345+
send_dev_command(kCmdSetPreCharge, _initPreCharge);
346+
send_dev_command(kCmdSetVComDeselect, _initVCOMDeselect);
347+
send_dev_command(kCmdDeactivateScroll);
348+
349+
send_dev_command(kCmdDisplayOn);
350+
351+
}
313352
////////////////////////////////////////////////////////////////////////////////////
314353
// set_comm_bus()
315354
//
@@ -508,6 +547,19 @@ void QwGrSSD1306::scroll(uint16_t scroll_type, uint8_t start, uint8_t stop, uint
508547
send_dev_command(kCmdActivateScroll);
509548
}
510549

550+
////////////////////////////////////////////////////////////////////////////////////
551+
// display_power()
552+
//
553+
// Used to set the power of the screen.
554+
555+
void QwGrSSD1306::display_power(bool enable){
556+
557+
558+
if(!_isInit)
559+
return;
560+
561+
send_dev_command( (enable ? kCmdDisplayOn : kCmdDisplayOff));
562+
}
511563
////////////////////////////////////////////////////////////////////////////////////
512564
// Drawing Methods
513565
////////////////////////////////////////////////////////////////////////////////////

src/qwiic_grssd1306.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +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);
170171

171172
// method to set the communication bus this object should use
172173
void set_comm_bus(QwI2C &theBus, uint8_t id_bus);
@@ -196,6 +197,8 @@ class QwGrSSD1306 : public QwGrBufferDevice {
196197
void scroll_stop(void);
197198
void scroll(uint16_t scroll_type, uint8_t start, uint8_t stop, uint8_t interval = SCROLL_INTERVAL_2_FRAMES);
198199

200+
void display_power(bool enable=true);
201+
199202
protected:
200203
// Subclasses of this class define the specifics of the device, including size.
201204
// Subclass needs to define the graphics buffer array - stack based - and pass in
@@ -231,6 +234,7 @@ class QwGrSSD1306 : public QwGrBufferDevice {
231234
void init_buffers(void); // clear graphics and screen buffer
232235
void clear_screen_buffer(void);
233236
void resend_graphics(void);
237+
void setup_oled_device(void);
234238

235239
// device communication methods
236240
void send_dev_command(uint8_t command);

0 commit comments

Comments
 (0)