77 * please support Adafruit and open-source hardware by purchasing
88 * products from Adafruit!
99 *
10- * Copyright (c) Brent Rubell for Adafruit Industries 2025
10+ * Copyright (c) Tyeth Gundry for Adafruit Industries 2025
1111 *
1212 * MIT license, all text here must be included in any redistribution.
1313 *
1717#define WIPPERSNAPPER_I2C_DRIVER_OUT_SH1107_H
1818
1919#include " WipperSnapper_I2C_Driver_Out.h"
20- // #include <Adafruit_GrayOLED.h>
2120#include < Adafruit_GFX.h>
2221#include < Adafruit_SH110X.h>
2322#include < Arduino.h>
2423
25- #define DEFAULT_WIDTH 128 // /< Default width for a sh1107 128x64 display
26- #define DEFAULT_HEIGHT 64 // /< Default height for a sh1107 128x64 display
24+ #define WS_SH1107_DEFAULT_WIDTH 128 // /< Default width for a sh1107 128x64 display
25+ #define WS_SH1107_DEFAULT_HEIGHT 64 // /< Default height for a sh1107 128x64 display
26+
27+ #define OLED_128X64_WING_WIDTH 128 // /< Width of the 128x64 OLED FeatherWing
28+ #define OLED_128X64_WING_HEIGHT 64 // /< Height of the 128x64 OLED FeatherWing
29+ #define OLED_128X64_WING_ROTATION_90 1 // /< Rotation of OLED FeatherWing 0-3
2730
2831/* !
2932 @brief Class that provides a driver interface for a SH1107
@@ -35,7 +38,7 @@ class WipperSnapper_I2C_Driver_Out_SH1107
3538public:
3639 /* ******************************************************************************/
3740 /* !
38- @brief Constructor for a OLED display.
41+ @brief Constructor for an SH1107 OLED display.
3942 @param i2c
4043 The I2C interface.
4144 @param sensorAddress
@@ -46,8 +49,8 @@ class WipperSnapper_I2C_Driver_Out_SH1107
4649 : WipperSnapper_I2C_Driver_Out(i2c, sensorAddress) {
4750 _i2c = i2c;
4851 _sensorAddress = sensorAddress;
49- _width = DEFAULT_WIDTH ;
50- _height = DEFAULT_HEIGHT ;
52+ _width = WS_SH1107_DEFAULT_WIDTH ;
53+ _height = WS_SH1107_DEFAULT_HEIGHT ;
5154 }
5255
5356 /* !
@@ -68,8 +71,10 @@ class WipperSnapper_I2C_Driver_Out_SH1107
6871 @returns True if initialized successfully, False otherwise.
6972 */
7073 bool begin () {
71- if (_width == 128 && _height == 64 && _rotation == 1 ) {
72- // featherwing needs to be rotated 90 degrees and swap w/h
74+ if (_width == OLED_128X64_WING_WIDTH &&
75+ _height == OLED_128X64_WING_HEIGHT &&
76+ _rotation == OLED_128X64_WING_ROTATION_90) {
77+ // featherwing needs to be rotated 90 degrees and swap w/h ctor args
7378 _display = new Adafruit_SH1107 (_height, _width, _i2c);
7479 } else {
7580 _display = new Adafruit_SH1107 (_width, _height, _i2c);
@@ -92,15 +97,9 @@ class WipperSnapper_I2C_Driver_Out_SH1107
9297 _display->setTextSize (_text_sz);
9398 _display->setTextColor (SH110X_WHITE);
9499 _display->setCursor (0 , 0 );
95- // Use full 256 char 'Code Page 437' font
96- // _display->cp437(true);
97100 // Clear the buffer
98101 _display->clearDisplay ();
99102 _display->display ();
100- _display->print (char (' a' ));
101- delay (500 );
102- _display->write (char (' b' ));
103- _display->display ();
104103 return true ;
105104 }
106105
@@ -121,9 +120,7 @@ class WipperSnapper_I2C_Driver_Out_SH1107
121120 _width = width;
122121 _height = height;
123122 _text_sz = text_size;
124- _rotation = rotation % 90 ;
125- WS_DEBUG_PRINT (" SH1107 text size: " );
126- WS_DEBUG_PRINTLN (text_size);
123+ _rotation = rotation % 90 ; // SH1107 requires rotation to be 0-3, not degrees
127124 }
128125 /* !
129126 @brief Configures a SSD1306 OLED display. Must be called before driver
@@ -151,8 +148,6 @@ class WipperSnapper_I2C_Driver_Out_SH1107
151148 void WriteMessageSH1107 (const char *message) {
152149 if (_display == nullptr )
153150 return ;
154- WS_DEBUG_PRINT (" SH1107 Message:" );
155- WS_DEBUG_PRINTLN (message);
156151 // Start with a fresh display buffer
157152 // and settings
158153 int16_t y_idx = 0 ;
@@ -175,15 +170,11 @@ class WipperSnapper_I2C_Driver_Out_SH1107
175170 message[i + 2 ] == ' \\ ' && message[i + 3 ] == ' n' ) {
176171 // Skip to the next line
177172 y_idx += line_height;
178- WS_DEBUG_PRINT (" SH1107 Newline at: " );
179- WS_DEBUG_PRINTLN (y_idx);
180173 _display->setCursor (0 , y_idx);
181174 i += 3 ;
182175 } else if (message[i + 1 ] == ' n' ) {
183176 // Skip to the next line
184177 y_idx += line_height;
185- WS_DEBUG_PRINT (" SH1107 Newline at: " );
186- WS_DEBUG_PRINTLN (y_idx);
187178 _display->setCursor (0 , y_idx);
188179 i++;
189180 }
0 commit comments