NetBurner 3.5.6
PDF Version
SparkFun_Qwiic_OLED.h
1// SparkFun_Qwiic_OLED.h
2//
3// This is a library written for SparkFun Qwiic OLED boards that use the SSD1306.
4//
5// SparkFun sells these at its website: www.sparkfun.com
6//
7// Do you like this library? Help support SparkFun. Buy a board!
8//
9// Micro OLED https://www.sparkfun.com/products/14532
10// Transparent OLED https://www.sparkfun.com/products/15173
11// "Narrow" OLED https://www.sparkfun.com/products/17153
12//
13//
14// Written by Kirk Benell @ SparkFun Electronics, March 2022
15//
16// This library configures and draws graphics to OLED boards that use the
17// SSD1306 display hardware. The library only supports I2C.
18//
19// Repository:
20// https://github.com/sparkfun/SparkFun_Qwiic_OLED_Arduino_Library
21//
22// Documentation:
23// https://sparkfun.github.io/SparkFun_Qwiic_OLED_Arduino_Library/
24//
25//
26// SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).
27//
28// SPDX-License-Identifier: MIT
29//
30// The MIT License (MIT)
31//
32// Copyright (c) 2022 SparkFun Electronics
33// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
34// associated documentation files (the "Software"), to deal in the Software without restriction,
35// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
36// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to
37// do so, subject to the following conditions:
38// The above copyright notice and this permission notice shall be included in all copies or substantial
39// portions of the Software.
40// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
41// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
42// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
43// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
44// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45
46#pragma once
47
48// Arduino wrapper for the OLED library. Provides an Arduino experience and platform support
49// for the Qwiic OLED driver.
50
51// include the underlying SDK implementation headers for the OLED devices
52#include "qwiic_oled_1in3.h"
53#include "qwiic_oled_custom.h"
54#include "qwiic_oledmicro.h"
55#include "qwiic_olednarrow.h"
56#include "qwiic_oledtransp.h"
57
58#include <Arduino.h>
59#include <Wire.h>
60
61// Friendly typenames
62typedef QwFont QwiicFont;
63typedef QwBitmap QwiicBitmap;
64
65#define COLOR_WHITE 1
66#define COLOR_BLACK 0
67
68// The Plan:
69//
70// For each supported device the following is needed
71//
72// - A commmon Arduino interface/implementation. One impl, one area to maintain
73// - Classes that are specialized for each device
74// - No abstract methods that a subclass must implement
75//
76// The solution
77// A templated base class that device specific sub-classes derive from.
78//
79
80// flag - internal - to determine if an address is passed into begin or not
81
82#define kNoAddressSet 0
83
84// Define the template and fill in the interface methods in-line.
85
86template <typename SSD1306DeviceType> class QwiicOLEDBaseClass : public Print // NOTE: implementing Arduino Print
87{
88 protected:
89 // our device driver
90 SSD1306DeviceType m_device;
91
92 private:
93 QwI2C m_i2cBus; // our i2c object
94
95 // for the Aruduino print functionaliyt
96 uint8_t m_cursorX;
97 uint8_t m_cursorY;
98
99 uint8_t m_color;
100
101 public:
103 // begin()
104 //
105 // This method is called to initialize the OLED library and connection to
106 // the OLED device. This method must be called before calling any graphics methods.
107 //
108 // This method follows the standard startup pattern in SparkFun Arduino
109 // libraries.
110 //
111 // Parameter Description
112 // --------- ----------------------------
113 // wirePort optional. The Wire port. If not provided, the default port is used
114 // address optional. I2C Address. If not provided, the default address is used.
115 // retval true on success, false on startup failure
116
117 bool begin(TwoWire &wirePort = Wire, uint8_t address = kNoAddressSet)
118 {
119
120 // defaults for Arduino Print
121 setCursor(0, 0);
122 setColor(COLOR_WHITE);
123
124 m_i2cBus.init(wirePort);
125
126 m_device.setCommBus(m_i2cBus, (address == kNoAddressSet ? m_device.default_address : address));
127
128 // call init on the device
129 bool bStatus = m_device.init();
130
131 // Want to start cursor at Y height of the current font, if we have a font.
132 //
133 // Get our font height ... a default font is set during init ...
134 if (bStatus)
135 {
136 QwiicFont *pFont = m_device.font();
137 if (pFont)
138 m_cursorY = pFont->height;
139 }
140
141 return bStatus;
142 }
143
145 // getWidth()
146 //
147 // This method returns the width, in pixels, of the connected OLED device
148 //
149 // Parameter Description
150 // --------- -----------------------------
151 // retval The width in pixels of the connected OLED device
152
153 uint8_t getWidth(void)
154 {
155 return m_device.width();
156 }
157
159 // getHeight()
160 //
161 // This method returns the height, in pixels, of the connected OLED device
162 //
163 // Parameter Description
164 // --------- -----------------------------
165 // retval The height in pixels of the connected OLED device
166
167 uint8_t getHeight(void)
168 {
169 return m_device.height();
170 }
171
173 // reset()
174 //
175 // When called, the system and OLED are reset back to an initial state
176 //
177 // Parameter Description
178 // --------- -----------------------------
179 // clearDisplay true - clear the internal buffers during reset
180 // retval true on success, false on failure
181
182 bool reset(bool clearDisplay)
183 {
184 return m_device.reset(clearDisplay);
185 }
186
188 // display()
189 //
190 // When called, any pending display updates are sent to the connected OLED
191 // device. This includes drawn graphics and erase commands.
192 //
193 // To display any graphics, this method must be called.
194
195 void display(void)
196 {
197 m_device.display();
198 }
199
201 // erase()
202 //
203 // Erases all graphics on the device, placing the display in a blank state.
204 // The erase update isn't sent to the device until the next display() call
205 // on the device.
206
207 void erase(void)
208 {
209 m_device.erase();
210 }
211
213 // invert()
214 //
215 // This method inverts the current graphics on the display. This results
216 // of this command happen immediatly.
217 //
218 // Parameter Description
219 // --------- -----------------------------
220 // bInvert true - the screen is inverted. false - the screen is set to normal
221
222 void invert(bool bInvert)
223 {
224 m_device.invert(bInvert);
225 }
226
228 // flipVertical()
229 //
230 // When called, the screen contents are flipped vertically if the flip parameter
231 // is true, or restored to normal display if the flip parameter is false.
232 //
233 // Parameter Description
234 // --------- -----------------------------
235 // bFlip true - the screen is flipped vertically. false - the screen is set to normal
236
237 void flipVertical(bool bFlip)
238 {
239 m_device.flipVert(bFlip);
240 }
241
243 // flipHorizontal()
244 //
245 // When called, the screen contents are flipped horizontally if the flip parameter
246 // is true, or restored to normal display if the flip parameter is false.
247 //
248 // Parameter Description
249 // --------- -----------------------------
250 // bFlip true - the screen is flipped horizontally. false - the screen is set to normal
251
252 void flipHorizontal(bool bFlip)
253 {
254 m_device.flipHorz(bFlip);
255 }
256
258 // scrollStop()
259 //
260 // If the device is in a scrolling mode, calling this method stops the scroll,
261 // and restores the device to normal display operation. This action is performed immediately.
262
263 void scrollStop(void)
264 {
265 m_device.stopScroll();
266 }
267
269 // scrollRight()
270 //
271 // This method is called to start the device scrolling the displayed graphics to the right.
272 // This action is performed immediately.
273 //
274 // The screen will scroll until the scrollStop() method is called.
275 //
276 // Parameter Description
277 // --------- -----------------------------
278 // start The start page address of the scroll - valid values are 0 thru 7
279 // stop The stop/end page address of the scroll - valid values are 0 thru 7
280 // interval The time interval between scroll step - values listed below
281 //
282 // Defined values for the interval parameter:
283 //
284 // Defined Symbol Time Interval Between Steps
285 // ---------------------------- ---------------------------
286 // SCROLL_INTERVAL_2_FRAMES 2
287 // SCROLL_INTERVAL_3_FRAMES 3
288 // SCROLL_INTERVAL_4_FRAMES 4
289 // SCROLL_INTERVAL_5_FRAMES 5
290 // SCROLL_INTERVAL_25_FRAMES 25
291 // SCROLL_INTERVAL_64_FRAMES 64
292 // SCROLL_INTERVAL_128_FRAMES 128
293 // SCROLL_INTERVAL_256_FRAMES 256
294
295 void scrollRight(uint8_t start, uint8_t stop, uint8_t interval)
296 {
297 m_device.scroll(SCROLL_RIGHT, start, stop, interval);
298 }
299
301 // scrollVertRight()
302 //
303 // This method is called to start the device scrolling the displayed graphics verticall and to the right.
304 // This action is performed immediately.
305 //
306 // The screen will scroll until the scrollStop() method is called.
307 //
308 // Parameter Description
309 // --------- -----------------------------
310 // start The start page address of the scroll - valid values are 0 thru 7
311 // stop The stop/end page address of the scroll - valid values are 0 thru 7
312 // interval The time interval between scroll step - values listed in scrollRight()
313
314 void scrollVertRight(uint8_t start, uint8_t stop, uint8_t interval)
315 {
316 m_device.scroll(SCROLL_VERT_RIGHT, start, stop, interval);
317 }
318
320 // scrollLeft()
321 //
322 // This method is called start to the device scrolling the displayed graphics to the left.
323 // This action is performed immediately.
324 //
325 // The screen will scroll until the scrollStop() method is called.
326 //
327 // Parameter Description
328 // --------- -----------------------------
329 // start The start page address of the scroll - valid values are 0 thru 7
330 // stop The stop/end page address of the scroll - valid values are 0 thru 7
331 // interval The time interval between scroll step - values listed in scrollRight()
332
333 void scrollLeft(uint8_t start, uint8_t stop, uint8_t interval)
334 {
335 m_device.scroll(SCROLL_LEFT, start, stop, interval);
336 }
337
339 // scrollVertLeft()
340 //
341 // This method is called to start the device scrolling the displayed graphics verticall and to the left.
342 // This action is performed immediately.
343 //
344 // The screen will scroll until the scrollStop() method is called.
345 //
346 // Parameter Description
347 // --------- -----------------------------
348 // start The start page address of the scroll - valid values are 0 thru 7
349 // stop The stop/end page address of the scroll - valid values are 0 thru 7
350 // interval The time interval between scroll step - values listed in scrollRight()
351
352 void scrollVertLeft(uint8_t start, uint8_t stop, uint8_t interval)
353 {
354 m_device.scroll(SCROLL_VERT_LEFT, start, stop, interval);
355 }
356
358 // displayPower()
359 //
360 // Used to turn the OLED display on an off.
361 //
362 // Default value is on.
363 //
364 // Parameter Description
365 // --------- -----------------------------
366 // enable Turn the display on or off - default is on
367
368 void displayPower(bool enable = true)
369 {
370
371 m_device.displayPower(enable);
372 }
374 // setFont()
375 //
376 // This method is called to set the current font in the library. The current font is used
377 // when calling the text() method on this device.
378 //
379 // The default font for the device is 5x7.
380 //
381 // Parameter Description
382 // --------- -----------------------------
383 // theFont The font to set as current in the device. A Font object or pointer is accepted
384 //
385 // For the library, fonts are added to your program by including them via include files which
386 // are part of this library.
387 //
388 // The following fonts are included:
389 //
390 // Font Include File Font Variable Description
391 // ----------- --------------------- ---------------- ---------------------
392 // 5x7 <res/qw_fnt_5x7.h> QW_FONT_5X7 A full, 5 x 7 font
393 // 31x48 <res/qw_fnt_31x48.h> QW_FONT_31X48 A full, 31 x 48 font
394 // Seven Segment <res/qw_fnt_7segment.h> QW_FONT_7SEGMENT Numbers only
395 // 8x16 <res/qw_fnt_8x16.h> QW_FONT_8X16 A full, 8 x 16 font
396 // Large Numbers <res/qw_fnt_largenum.h> QW_FONT_LARGENUM Numbers only
397 //
398 // For each font, the font variables are objects with the following attributes:
399 //
400 // Attribute Value
401 // ---------- -------------------------------------
402 // width The font width in pixels
403 // height The font height in pixels
404 // start The font start character offset
405 // n_chars The number of characters
406 // map_width The width of the font map
407 //
408 // Example use of a font object attribute:
409 //
410 // #include <res/qw_fnt_31x48.h>
411 //
412 // int myFontWidth = QW_FONT_31X48.width;
413 //
414
415 void setFont(QwiicFont &theFont)
416 {
417 m_device.setFont(theFont);
418 }
419 void setFont(const QwiicFont *theFont)
420 {
421 m_device.setFont(theFont);
422 }
423
425 // getFont()
426 //
427 // This method returns the current font for the device.
428 //
429 // Parameter Description
430 // --------- -----------------------------
431 // retval A pointer to the current font. See setFont() for font object details.
432
433 QwiicFont *getFont(void)
434 {
435 return m_device.font();
436 }
437
439 // getFontName()
440 //
441 // This method returns the name of the current font for the device.
442
443 String getFontName(void)
444 {
445 QwiicFont *pFont = m_device.font();
446
447 if (!pFont)
448 return String("");
449
450 return String(pFont->name);
451 }
453 // getStringWidth()
454 //
455 // Returns the width of the provide string using the current font.
456 //
457 // Parameter Description
458 // --------- -----------------------------
459 // text The string used to determine width
460 // retval The width of the provide string, as determined using the current font.
461
462 unsigned int getStringWidth(String &text)
463 {
464 return getStringWidth(text.c_str());
465 }
466
467 unsigned int getStringWidth(const char *text)
468 {
469
470 uint16_t height, width;
471
472 return (m_device.getStringSize(text, width, height) ? width : 0);
473 }
474
476 // getStringHeight()
477 //
478 // Returns the height of the provide string using the current font.
479 //
480 // Parameter Description
481 // --------- -----------------------------
482 // text The string used to determine height
483 // retval The height of the provide string, as determined using the current font.
484
485 unsigned int getStringHeight(String &text)
486 {
487 return getStringHeight(text.c_str());
488 }
489
490 unsigned int getStringHeight(const char *text)
491 {
492
493 uint16_t height, width;
494
495 return (m_device.getStringSize(text, width, height) ? height : 0);
496 }
498 // setDrawMode()
499 //
500 // This method sets the current draw mode for the library. The draw mode
501 // determines how pixels are set on the screen during drawing operations.
502 //
503 // Parameter Description
504 // --------- -----------------------------
505 // rop The raster operation (ROP) to set the graphics system to.
506 //
507 // Raster operations device how source (pixels to draw) are represented on the
508 // destination device. The available Raster Operation (ROP) codes are:
509 //
510 // ROP Code Description
511 // --------- -------------------------------------
512 // grROPCopy default Drawn pixel values are copied to the device screen
513 // grROPNotCopy A not operation is applied to the source value before copying to screen
514 // grROPNot A not operation is applied to the destination (screen) value
515 // grROPXOR A XOR operation is performed between the source and destination values
516 // grROPBlack A value of 0, or black is drawn to the destination
517 // grROPWhite A value of 1, or black is drawn to the destination
518
519 void setDrawMode(grRasterOp_t rop)
520 {
521 m_device.setRasterOp(rop);
522 }
523
525 // setDrawMode()
526 //
527 // This method returns the current draw mode for the library. The draw mode
528 // determines how pixels are set on the screen during drawing operations.
529 //
530 // Parameter Description
531 // --------- -----------------------------
532 // retval The current aster operation (ROP) of the graphics system.
533
534 grRasterOp_t getDrawMode(void)
535 {
536 return m_device.rasterOp();
537 }
538
540 // Drawing methods
542 //
543 // pixel()
544 //
545 // Set the value of a pixel on the screen.
546 //
547 // Parameter Description
548 // --------- -----------------------------
549 // x The X coordinate of the pixel to set
550 // y The Y coordinate of the pixel to set
551 // clr optional The color value to set the pixel. This defaults to white (1).
552
553 void pixel(uint8_t x, uint8_t y, uint8_t clr = COLOR_WHITE)
554 {
555 m_device.pixel(x, y, clr);
556 }
557
559 // line()
560 //
561 // Draw a line on the screen.
562 //
563 // Note: If a line is horizontal (y0 = y1) or vertical (x0 = x1), optimized
564 // draw algorithms are used by the library.
565 //
566 // Parameter Description
567 // --------- -----------------------------
568 // x0 The start X coordinate of the line
569 // y0 The start Y coordinate of the line
570 // x1 The end X coordinate of the line
571 // y1 The end Y coordinate of the line
572 // clr optional The color value to draw the line. This defaults to white (1).
573
574 void line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr = COLOR_WHITE)
575 {
576 m_device.line(x0, y0, x1, y1, clr);
577 }
578
580 // rectangle()
581 //
582 // Draw a rectangle on the screen.
583 //
584 // Parameter Description
585 // --------- -----------------------------
586 // x0 The start X coordinate of the rectangle - upper left corner
587 // y0 The start Y coordinate of the rectangle - upper left corner
588 // width The width of the rectangle
589 // height The height of the rectangle
590 // clr optional The color value to draw the rectangle. This defaults to white (1).
591
592 void rectangle(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, uint8_t clr = COLOR_WHITE)
593 {
594 m_device.rectangle(x0, y0, width, height, clr);
595 }
596
598 // rectangleFill()
599 //
600 // Draw a filled rectangle on the screen.
601 //
602 // Parameter Description
603 // --------- -----------------------------
604 // x0 The start X coordinate of the rectangle - upper left corner
605 // y0 The start Y coordinate of the rectangle - upper left corner
606 // width The width of the rectangle
607 // height The height of the rectangle
608 // clr optional The color value to draw the filled rectangle. This defaults to white (1).
609
610 void rectangleFill(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, uint8_t clr = COLOR_WHITE)
611 {
612 m_device.rectangleFill(x0, y0, width, height, clr);
613 }
614
616 // circle()
617 //
618 // Draw a circle on the screen.
619 //
620 // Parameter Description
621 // --------- -----------------------------
622 // x0 The X coordinate of the circle center
623 // y0 The Y coordinate of the circle center
624 // radius The radius of the circle
625 // clr optional The color value to draw the circle. This defaults to white (1).
626
627 void circle(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t clr = COLOR_WHITE)
628 {
629 m_device.circle(x0, y0, radius, clr);
630 }
631
633 // circleFill()
634 //
635 // Draw a circle on the screen.
636 //
637 // Parameter Description
638 // --------- -----------------------------
639 // x0 The X coordinate of the circle center
640 // y0 The Y coordinate of the circle center
641 // radius The radius of the circle
642 // clr optional The color value to draw the circle. This defaults to white (1).
643
644 void circleFill(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t clr = COLOR_WHITE)
645 {
646 m_device.circleFill(x0, y0, radius, clr);
647 }
648
650 // bitmap()
651 //
652 // Draws a bitmap on the screen.
653 //
654 // Parameter Description
655 // --------- -----------------------------
656 // x0 The X coordinate to place the bitmap - upper left corner
657 // y0 The Y coordinate to place the bitmap - upper left corner
658 // x1 The end X coordinate of area to draw - lower right corner
659 // Range will not exceed bitmap width
660 // y1 The end Y coordinate of area to draw - lower right corner
661 // Range will not exceed bitmap height
662 // pBitmap A pointer to the bitmap array
663 // bmp_width The width of the bitmap
664 // bmp_height The height of the bitmap
665
666 void bitmap(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t *pBitmap, uint8_t bmp_width, uint8_t bmp_height)
667 {
668 m_device.bitmap(x0, y0, x1, y1, pBitmap, bmp_width, bmp_height);
669 }
670
672 // bitmap()
673 //
674 // Draws a bitmap on the screen.
675 //
676 // Parameter Description
677 // --------- -----------------------------
678 // x0 The X coordinate to place the bitmap - upper left corner
679 // y0 The Y coordinate to place the bitmap - upper left corner
680 // pBitmap A pointer to the bitmap array
681 // bmp_width The width of the bitmap
682 // bmp_height The height of the bitmap
683
684 void bitmap(uint8_t x0, uint8_t y0, uint8_t *pBitmap, uint8_t bmp_width, uint8_t bmp_height)
685 {
686
687 m_device.bitmap(x0, y0, pBitmap, bmp_width, bmp_height);
688 }
690 // bitmap()
691 //
692 // Draws a bitmap object on the screen.
693 //
694 // Parameter Description
695 // --------- -----------------------------
696 // x0 The X coordinate to place the bitmap - upper left corner
697 // y0 The Y coordinate to place the bitmap - upper left corner
698 // bitmap A bitmap object
699
700 void bitmap(uint8_t x0, uint8_t y0, QwiicBitmap &bitmap)
701 {
702 m_device.bitmap(x0, y0, bitmap);
703 }
704
706 // text()
707 //
708 // Draws a string using the current font on the screen.
709 //
710 // Parameter Description
711 // --------- -----------------------------
712 // x0 The X coordinate to start drawing the text
713 // y0 The Y coordinate to start drawing the text
714 // text The string to draw on the screen
715 // clr optional The color value to draw the text. This defaults to white (1).
716
717 void text(uint8_t x0, uint8_t y0, const char *text, uint8_t clr = COLOR_WHITE)
718 {
719 m_device.text(x0, y0, text, clr);
720 }
721
722 void text(uint8_t x0, uint8_t y0, String &text, uint8_t clr = COLOR_WHITE)
723 {
724
725 m_device.text(x0, y0, text.c_str(), clr);
726 }
727
729 // Methods to support Arduino Print capability
731 //
732 // setCursor()
733 //
734 // This method is called set the "cursor" position in the device. The library
735 // supports the Arduino Print interface, enabling the use of a print() and
736 // println() methods. The set cursor position defines where to start text
737 // output for this functionality.
738 //
739 // Parameter Description
740 // --------- -----------------------------
741 // x The X coordinate of the cursor
742 // y The Y coordinate of the cursor
743
744 void setCursor(uint8_t x, uint8_t y)
745 {
746
747 if (x < 0 || x >= m_device.width() || y < 0 || y >= m_device.height())
748 return;
749
750 m_cursorX = x;
751 m_cursorY = y;
752 }
753
755 // setColor()
756 //
757 // This method is called to set the current color of the system. This is
758 // used by the Arduino Print interface functionality
759 //
760 // Parameter Description
761 // --------- -----------------------------
762 // clr The color to set. 0 = black, > 0 = white
763
764 void setColor(uint8_t clr)
765 {
766 m_color = (clr > 0 ? COLOR_WHITE : COLOR_BLACK);
767 }
768
770 // getColor()
771 //
772 // This method is called to get the current color of the system. This is
773 // used by the Arduino Print interface functionality
774 //
775 // Parameter Description
776 // --------- -----------------------------
777 // retval The current color. 0 = black, > 0 = white
778
779 uint8_t getColor(void)
780 {
781 return m_color;
782 }
783
785 // write()
786 //
787 // For the Arduino Print interface
788 //
789
790 virtual size_t write(uint8_t theChar)
791 {
792 QwiicFont *pFont = m_device.font();
793
794 if (!pFont) // no Font?! No dice
795 return 0;
796
797 switch (theChar)
798 {
799 case '\n': // Carriage return
800 m_cursorX = 0;
801 m_cursorY += pFont->height;
802 case '\r': // Line feed - do nothing
803 break;
804 default:
805
806 char buffer[2] = {theChar, '\0'}; // text() needs a c string
807 m_device.text(m_cursorX, m_cursorY, buffer, m_color);
808
809 m_cursorX += pFont->width + 1;
810
811 if (m_cursorX > m_device.width() - pFont->width)
812 { // overflow
813 m_cursorX = 0;
814 m_cursorY += pFont->height;
815 }
816 break;
817 }
818 if (m_cursorY >= m_device.height()) // check for overflow
819 m_cursorY = 0;
820
821 return 1;
822 }
823};
824
826// For our actual implementations - just subclass from the above Arduino template
827
828class QwiicMicroOLED : public QwiicOLEDBaseClass<QwOLEDMicro>
829{
830 // nothing here - see above
831};
832
833class QwiicNarrowOLED : public QwiicOLEDBaseClass<QwOLEDNarrow>
834{
835 // nothing here - see above
836};
837
838class QwiicTransparentOLED : public QwiicOLEDBaseClass<QwOLEDTransparent>
839{
840 // nothing here - see above
841};
842
843class Qwiic1in3OLED : public QwiicOLEDBaseClass<QwOLED1in3>
844{
845 // nothing here - see above
846};
847
848class QwiicCustomOLED : public QwiicOLEDBaseClass<QwOLEDCustom>
849{
850 public:
851 void setXOffset(uint8_t xOffset)
852 {
853 m_device.setXOffset(xOffset);
854 }
855 void setYOffset(uint8_t yOffset)
856 {
857 m_device.setYOffset(yOffset);
858 }
859 void setDisplayWidth(uint8_t displayWidth)
860 {
861 m_device.setDisplayWidth(displayWidth);
862 }
863 void setDisplayHeight(uint8_t displayHeight)
864 {
865 m_device.setDisplayHeight(displayHeight);
866 }
867 void setPinConfig(uint8_t pinConfig)
868 {
869 m_device.setPinConfig(pinConfig);
870 }
871 void setPreCharge(uint8_t preCharge)
872 {
873 m_device.setPreCharge(preCharge);
874 }
875 void setVcomDeselect(uint8_t vcomDeselect)
876 {
877 m_device.setVcomDeselect(vcomDeselect);
878 }
879 void setContrast(uint8_t contrast)
880 {
881 m_device.setContrast(contrast);
882 }
883};
const char * c_str() const
Method to pass a NBString as a constant char *.
Wire interface class.
Definition Wire.h:43