1717#define WIPPERSNAPPER_I2C_DRIVER_OUT_SH1107_H
1818
1919#include " WipperSnapper_I2C_Driver_Out.h"
20- #include < Adafruit_SH110x.h>
20+ // #include <Adafruit_GrayOLED.h>
21+ #include < Adafruit_GFX.h>
22+ #include < Adafruit_SH110X.h>
2123#include < Arduino.h>
2224
2325#define DEFAULT_WIDTH 128 // /< Default width for a sh1107 128x64 display
@@ -33,7 +35,7 @@ class WipperSnapper_I2C_Driver_Out_SH1107
3335public:
3436 /* ******************************************************************************/
3537 /* !
36- @brief Constructor for a SH1107 OLED display.
38+ @brief Constructor for a OLED display.
3739 @param i2c
3840 The I2C interface.
3941 @param sensorAddress
@@ -55,7 +57,7 @@ class WipperSnapper_I2C_Driver_Out_SH1107
5557 if (_display != nullptr ) {
5658 _display->clearDisplay ();
5759 _display->display ();
58- _display->sh1107_command (SH1107_DISPLAYOFF );
60+ _display->oled_command (SH110X_DISPLAYOFF );
5961 delete _display;
6062 _display = nullptr ;
6163 }
@@ -66,18 +68,35 @@ class WipperSnapper_I2C_Driver_Out_SH1107
6668 @returns True if initialized successfully, False otherwise.
6769 */
6870 bool begin () {
69- // Attempt to create and allocate a SH1107 obj.
70- _display = new Adafruit_SH1107 (_width, _height , _i2c);
71+ // Attempt to create and allocate a SH1107 obj, backwards w/h
72+ _display = new Adafruit_SH1107 (_height, _width , _i2c);
7173 if (!_display->begin (_sensorAddress, true ))
7274 return false ;
75+
76+ // Show image buffer on the display hardware.
77+ // Since the buffer is intialized with an Adafruit splashscreen
78+ // internally, this will display the splashscreen.
79+ _display->display ();
80+ delay (1700 );
81+
82+ // Clear the buffer.
83+ _display->clearDisplay ();
84+ _display->display ();
85+ _display->setRotation (1 );
86+
7387 // Configure the text size and color
7488 _display->setTextSize (_text_sz);
75- _display->setTextColor (SH1107_WHITE);
89+ _display->setTextColor (SH110X_WHITE);
90+ _display->setCursor (0 , 0 );
7691 // Use full 256 char 'Code Page 437' font
77- _display->cp437 (true );
92+ // _display->cp437(true);
7893 // Clear the buffer
7994 _display->clearDisplay ();
8095 _display->display ();
96+ _display->print (char (' a' ));
97+ delay (500 );
98+ _display->write (char (' b' ));
99+ _display->display ();
81100 return true ;
82101 }
83102
@@ -95,7 +114,25 @@ class WipperSnapper_I2C_Driver_Out_SH1107
95114 _width = width;
96115 _height = height;
97116 _text_sz = text_size;
117+ WS_DEBUG_PRINT (" SH1107 text size: " );
118+ WS_DEBUG_PRINTLN (text_size);
98119 }
120+ /* !
121+ @brief Configures a SSD1306 OLED display. Must be called before driver
122+ begin() - This is a fake function to match the SSD1306 interface.
123+ @param width
124+ The width of the display in pixels.
125+ @param height
126+ The height of the display in pixels.
127+ @param text_size
128+ The magnification factor for the text size.
129+ */
130+ void ConfigureSSD1306 (uint8_t width, uint8_t height,
131+ uint8_t text_size) {
132+ // This is a SH1107, not a SSD1306, so we don't need to do anything here.
133+ ConfigureSH1107 (width, height, text_size);
134+ }
135+
99136
100137 /* !
101138 @brief Writes a message to the SH1107 display.
@@ -105,13 +142,14 @@ class WipperSnapper_I2C_Driver_Out_SH1107
105142 void WriteMessageSH1107 (const char *message) {
106143 if (_display == nullptr )
107144 return ;
108-
145+ WS_DEBUG_PRINT (" SH1107 Message:" );
146+ WS_DEBUG_PRINTLN (message);
109147 // Start with a fresh display buffer
110148 // and settings
111149 int16_t y_idx = 0 ;
112150 _display->clearDisplay ();
113151 _display->setTextSize (_text_sz);
114- _display->setTextColor (SH1107_WHITE );
152+ _display->setTextColor (SH110X_WHITE );
115153 _display->setCursor (0 , y_idx);
116154 _display->display ();
117155
@@ -128,11 +166,15 @@ class WipperSnapper_I2C_Driver_Out_SH1107
128166 message[i + 2 ] == ' \\ ' && message[i + 3 ] == ' n' ) {
129167 // Skip to the next line
130168 y_idx += line_height;
169+ WS_DEBUG_PRINT (" SH1107 Newline at: " );
170+ WS_DEBUG_PRINTLN (y_idx);
131171 _display->setCursor (0 , y_idx);
132172 i += 3 ;
133173 } else if (message[i + 1 ] == ' n' ) {
134174 // Skip to the next line
135175 y_idx += line_height;
176+ WS_DEBUG_PRINT (" SH1107 Newline at: " );
177+ WS_DEBUG_PRINTLN (y_idx);
136178 _display->setCursor (0 , y_idx);
137179 i++;
138180 }
@@ -147,6 +189,17 @@ class WipperSnapper_I2C_Driver_Out_SH1107
147189 }
148190 }
149191
192+
193+ /* !
194+ @brief Writes a message to the fake "SSD1306" SH1107 display.
195+ @param msg_write
196+ Pointer to a wippersnapper_i2c_v1_SSD1306Write message.
197+ */
198+ void WriteMessageSSD1306 (const char *message) {
199+ // This is a SH1107, not a SSD1306, so we just call the SH1107 write
200+ WriteMessageSH1107 (message);
201+ }
202+
150203protected:
151204 Adafruit_SH1107 *_display =
152205 nullptr ; // /< Pointer to the Adafruit_SH1107 object
@@ -155,4 +208,4 @@ class WipperSnapper_I2C_Driver_Out_SH1107
155208 uint8_t _text_sz; // /< Text size of the display
156209};
157210
158- #endif // WIPPERSNAPPER_I2C_DRIVER_OUT_SH1107_H
211+ #endif // WIPPERSNAPPER_I2C_DRIVER_OUT_SH1107_H
0 commit comments