49
49
// for the Qwiic OLED driver.
50
50
51
51
// include the underlying SDK implementation headers for the OLED devices
52
+ #include " qwiic_oled_1in3.h"
53
+ #include " qwiic_oled_custom.h"
52
54
#include " qwiic_oledmicro.h"
53
55
#include " qwiic_olednarrow.h"
54
56
#include " qwiic_oledtransp.h"
55
- #include " qwiic_oled_1in3.h"
56
- #include " qwiic_oled_custom.h"
57
57
58
58
#include < Arduino.h>
59
59
#include < Wire.h>
@@ -83,12 +83,13 @@ typedef QwBitmap QwiicBitmap;
83
83
84
84
// Define the template and fill in the interface methods in-line.
85
85
86
- template <typename SSD1306DeviceType>
87
- class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
88
- protected:
86
+ template <typename SSD1306DeviceType> class QwiicOLEDBaseClass : public Print // NOTE: implementing Arduino Print
87
+ {
88
+ protected:
89
89
// our device driver
90
90
SSD1306DeviceType m_device;
91
- private:
91
+
92
+ private:
92
93
QwI2C m_i2cBus; // our i2c object
93
94
94
95
// for the Aruduino print functionaliyt
@@ -97,7 +98,7 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
97
98
98
99
uint8_t m_color;
99
100
100
- public:
101
+ public:
101
102
// /////////////////////////////////////////////////////////////////////
102
103
// begin()
103
104
//
@@ -113,7 +114,7 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
113
114
// address optional. I2C Address. If not provided, the default address is used.
114
115
// retval true on success, false on startup failure
115
116
116
- bool begin (TwoWire& wirePort = Wire, uint8_t address = kNoAddressSet )
117
+ bool begin (TwoWire & wirePort = Wire, uint8_t address = kNoAddressSet )
117
118
{
118
119
119
120
// defaults for Arduino Print
@@ -122,17 +123,17 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
122
123
123
124
m_i2cBus.init (wirePort);
124
125
125
- m_device.setCommBus (m_i2cBus,
126
- (address == kNoAddressSet ? m_device.default_address : address));
126
+ m_device.setCommBus (m_i2cBus, (address == kNoAddressSet ? m_device.default_address : address));
127
127
128
128
// call init on the device
129
129
bool bStatus = m_device.init ();
130
130
131
131
// Want to start cursor at Y height of the current font, if we have a font.
132
132
//
133
133
// Get our font height ... a default font is set during init ...
134
- if (bStatus) {
135
- QwiicFont* pFont = m_device.font ();
134
+ if (bStatus)
135
+ {
136
+ QwiicFont *pFont = m_device.font ();
136
137
if (pFont)
137
138
m_cursorY = pFont->height ;
138
139
}
@@ -175,7 +176,7 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
175
176
//
176
177
// Parameter Description
177
178
// --------- -----------------------------
178
- // clearDisplay true - clear the internal buffers during reset
179
+ // clearDisplay true - clear the internal buffers during reset
179
180
// retval true on success, false on failure
180
181
181
182
bool reset (bool clearDisplay)
@@ -411,11 +412,11 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
411
412
// int myFontWidth = QW_FONT_31X48.width;
412
413
//
413
414
414
- void setFont (QwiicFont& theFont)
415
+ void setFont (QwiicFont & theFont)
415
416
{
416
417
m_device.setFont (theFont);
417
418
}
418
- void setFont (const QwiicFont* theFont)
419
+ void setFont (const QwiicFont * theFont)
419
420
{
420
421
m_device.setFont (theFont);
421
422
}
@@ -429,7 +430,7 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
429
430
// --------- -----------------------------
430
431
// retval A pointer to the current font. See setFont() for font object details.
431
432
432
- QwiicFont* getFont (void )
433
+ QwiicFont * getFont (void )
433
434
{
434
435
return m_device.font ();
435
436
}
@@ -441,7 +442,7 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
441
442
442
443
String getFontName (void )
443
444
{
444
- QwiicFont* pFont = m_device.font ();
445
+ QwiicFont * pFont = m_device.font ();
445
446
446
447
if (!pFont)
447
448
return String (" " );
@@ -458,12 +459,12 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
458
459
// text The string used to determine width
459
460
// retval The width of the provide string, as determined using the current font.
460
461
461
- unsigned int getStringWidth (String& text)
462
+ unsigned int getStringWidth (String & text)
462
463
{
463
464
return getStringWidth (text.c_str ());
464
465
}
465
466
466
- unsigned int getStringWidth (const char * text)
467
+ unsigned int getStringWidth (const char * text)
467
468
{
468
469
469
470
uint16_t height, width;
@@ -481,12 +482,12 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
481
482
// text The string used to determine height
482
483
// retval The height of the provide string, as determined using the current font.
483
484
484
- unsigned int getStringHeight (String& text)
485
+ unsigned int getStringHeight (String & text)
485
486
{
486
487
return getStringHeight (text.c_str ());
487
488
}
488
489
489
- unsigned int getStringHeight (const char * text)
490
+ unsigned int getStringHeight (const char * text)
490
491
{
491
492
492
493
uint16_t height, width;
@@ -662,8 +663,7 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
662
663
// bmp_width The width of the bitmap
663
664
// bmp_height The height of the bitmap
664
665
665
- void bitmap (uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
666
- uint8_t * pBitmap, uint8_t bmp_width, uint8_t bmp_height)
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
667
{
668
668
m_device.bitmap (x0, y0 , x1, y1 , pBitmap, bmp_width, bmp_height);
669
669
}
@@ -681,7 +681,7 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
681
681
// bmp_width The width of the bitmap
682
682
// bmp_height The height of the bitmap
683
683
684
- void bitmap (uint8_t x0, uint8_t y0, uint8_t * pBitmap, uint8_t bmp_width, uint8_t bmp_height)
684
+ void bitmap (uint8_t x0, uint8_t y0, uint8_t * pBitmap, uint8_t bmp_width, uint8_t bmp_height)
685
685
{
686
686
687
687
m_device.bitmap (x0, y0 , pBitmap, bmp_width, bmp_height);
@@ -697,7 +697,7 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
697
697
// y0 The Y coordinate to place the bitmap - upper left corner
698
698
// bitmap A bitmap object
699
699
700
- void bitmap (uint8_t x0, uint8_t y0, QwiicBitmap& bitmap)
700
+ void bitmap (uint8_t x0, uint8_t y0, QwiicBitmap & bitmap)
701
701
{
702
702
m_device.bitmap (x0, y0 , bitmap);
703
703
}
@@ -714,12 +714,12 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
714
714
// text The string to draw on the screen
715
715
// clr optional The color value to draw the text. This defaults to white (1).
716
716
717
- void text (uint8_t x0, uint8_t y0, const char * text, uint8_t clr = COLOR_WHITE)
717
+ void text (uint8_t x0, uint8_t y0, const char * text, uint8_t clr = COLOR_WHITE)
718
718
{
719
719
m_device.text (x0, y0 , text, clr);
720
720
}
721
721
722
- void text (uint8_t x0, uint8_t y0, String& text, uint8_t clr = COLOR_WHITE)
722
+ void text (uint8_t x0, uint8_t y0, String & text, uint8_t clr = COLOR_WHITE)
723
723
{
724
724
725
725
m_device.text (x0, y0 , text.c_str (), clr);
@@ -789,25 +789,27 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
789
789
790
790
virtual size_t write (uint8_t theChar)
791
791
{
792
- QwiicFont* pFont = m_device.font ();
792
+ QwiicFont * pFont = m_device.font ();
793
793
794
794
if (!pFont) // no Font?! No dice
795
795
return 0 ;
796
796
797
- switch (theChar) {
797
+ switch (theChar)
798
+ {
798
799
case ' \n ' : // Carriage return
799
800
m_cursorX = 0 ;
800
801
m_cursorY += pFont->height ;
801
802
case ' \r ' : // Line feed - do nothing
802
803
break ;
803
804
default :
804
805
805
- char buffer[2 ] = { theChar, ' \0 ' }; // text() needs a c string
806
+ char buffer[2 ] = {theChar, ' \0 ' }; // text() needs a c string
806
807
m_device.text (m_cursorX, m_cursorY, buffer, m_color);
807
808
808
809
m_cursorX += pFont->width + 1 ;
809
810
810
- if (m_cursorX > m_device.width () - pFont->width ) { // overflow
811
+ if (m_cursorX > m_device.width () - pFont->width )
812
+ { // overflow
811
813
m_cursorX = 0 ;
812
814
m_cursorY += pFont->height ;
813
815
}
@@ -823,30 +825,59 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
823
825
// /////////////////////////////////////////////////////////////////////
824
826
// For our actual implementations - just subclass from the above Arduino template
825
827
826
- class QwiicMicroOLED : public QwiicOLEDBaseClass <QwOLEDMicro> {
828
+ class QwiicMicroOLED : public QwiicOLEDBaseClass <QwOLEDMicro>
829
+ {
827
830
// nothing here - see above
828
831
};
829
832
830
- class QwiicNarrowOLED : public QwiicOLEDBaseClass <QwOLEDNarrow> {
833
+ class QwiicNarrowOLED : public QwiicOLEDBaseClass <QwOLEDNarrow>
834
+ {
831
835
// nothing here - see above
832
836
};
833
837
834
- class QwiicTransparentOLED : public QwiicOLEDBaseClass <QwOLEDTransparent> {
838
+ class QwiicTransparentOLED : public QwiicOLEDBaseClass <QwOLEDTransparent>
839
+ {
835
840
// nothing here - see above
836
841
};
837
842
838
- class Qwiic1in3OLED : public QwiicOLEDBaseClass <QwOLED1in3> {
843
+ class Qwiic1in3OLED : public QwiicOLEDBaseClass <QwOLED1in3>
844
+ {
839
845
// nothing here - see above
840
846
};
841
847
842
- class QwiicCustomOLED : public QwiicOLEDBaseClass <QwOLEDCustom> {
843
- public:
844
- void setXOffset (uint8_t xOffset){ m_device.setXOffset (xOffset); }
845
- void setYOffset (uint8_t yOffset){ m_device.setYOffset (yOffset); }
846
- void setDisplayWidth (uint8_t displayWidth){ m_device.setDisplayWidth (displayWidth); }
847
- void setDisplayHeight (uint8_t displayHeight){ m_device.setDisplayHeight (displayHeight); }
848
- void setPinConfig (uint8_t pinConfig){ m_device.setPinConfig (pinConfig); }
849
- void setPreCharge (uint8_t preCharge){ m_device.setPreCharge (preCharge); }
850
- void setVcomDeselect (uint8_t vcomDeselect){ m_device.setVcomDeselect (vcomDeselect); }
851
- void setContrast (uint8_t contrast){ m_device.setContrast (contrast); }
848
+ class 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
+ }
852
883
};
0 commit comments