7
7
* please support Adafruit and open-source hardware by purchasing
8
8
* products from Adafruit!
9
9
*
10
- * Copyright (c) Brent Rubell for Adafruit Industries 2025
10
+ * Copyright (c) Tyeth Gundry for Adafruit Industries 2025
11
11
*
12
12
* MIT license, all text here must be included in any redistribution.
13
13
*
17
17
#define WIPPERSNAPPER_I2C_DRIVER_OUT_SH1107_H
18
18
19
19
#include " WipperSnapper_I2C_Driver_Out.h"
20
- // #include <Adafruit_GrayOLED.h>
21
20
#include < Adafruit_GFX.h>
22
21
#include < Adafruit_SH110X.h>
23
22
#include < Arduino.h>
24
23
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
27
30
28
31
/* !
29
32
@brief Class that provides a driver interface for a SH1107
@@ -35,7 +38,7 @@ class WipperSnapper_I2C_Driver_Out_SH1107
35
38
public:
36
39
/* ******************************************************************************/
37
40
/* !
38
- @brief Constructor for a OLED display.
41
+ @brief Constructor for an SH1107 OLED display.
39
42
@param i2c
40
43
The I2C interface.
41
44
@param sensorAddress
@@ -46,8 +49,8 @@ class WipperSnapper_I2C_Driver_Out_SH1107
46
49
: WipperSnapper_I2C_Driver_Out(i2c, sensorAddress) {
47
50
_i2c = i2c;
48
51
_sensorAddress = sensorAddress;
49
- _width = DEFAULT_WIDTH ;
50
- _height = DEFAULT_HEIGHT ;
52
+ _width = WS_SH1107_DEFAULT_WIDTH ;
53
+ _height = WS_SH1107_DEFAULT_HEIGHT ;
51
54
}
52
55
53
56
/* !
@@ -68,8 +71,10 @@ class WipperSnapper_I2C_Driver_Out_SH1107
68
71
@returns True if initialized successfully, False otherwise.
69
72
*/
70
73
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
73
78
_display = new Adafruit_SH1107 (_height, _width, _i2c);
74
79
} else {
75
80
_display = new Adafruit_SH1107 (_width, _height, _i2c);
@@ -92,15 +97,9 @@ class WipperSnapper_I2C_Driver_Out_SH1107
92
97
_display->setTextSize (_text_sz);
93
98
_display->setTextColor (SH110X_WHITE);
94
99
_display->setCursor (0 , 0 );
95
- // Use full 256 char 'Code Page 437' font
96
- // _display->cp437(true);
97
100
// Clear the buffer
98
101
_display->clearDisplay ();
99
102
_display->display ();
100
- _display->print (char (' a' ));
101
- delay (500 );
102
- _display->write (char (' b' ));
103
- _display->display ();
104
103
return true ;
105
104
}
106
105
@@ -121,9 +120,7 @@ class WipperSnapper_I2C_Driver_Out_SH1107
121
120
_width = width;
122
121
_height = height;
123
122
_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
127
124
}
128
125
/* !
129
126
@brief Configures a SSD1306 OLED display. Must be called before driver
@@ -151,8 +148,6 @@ class WipperSnapper_I2C_Driver_Out_SH1107
151
148
void WriteMessageSH1107 (const char *message) {
152
149
if (_display == nullptr )
153
150
return ;
154
- WS_DEBUG_PRINT (" SH1107 Message:" );
155
- WS_DEBUG_PRINTLN (message);
156
151
// Start with a fresh display buffer
157
152
// and settings
158
153
int16_t y_idx = 0 ;
@@ -175,15 +170,11 @@ class WipperSnapper_I2C_Driver_Out_SH1107
175
170
message[i + 2 ] == ' \\ ' && message[i + 3 ] == ' n' ) {
176
171
// Skip to the next line
177
172
y_idx += line_height;
178
- WS_DEBUG_PRINT (" SH1107 Newline at: " );
179
- WS_DEBUG_PRINTLN (y_idx);
180
173
_display->setCursor (0 , y_idx);
181
174
i += 3 ;
182
175
} else if (message[i + 1 ] == ' n' ) {
183
176
// Skip to the next line
184
177
y_idx += line_height;
185
- WS_DEBUG_PRINT (" SH1107 Newline at: " );
186
- WS_DEBUG_PRINTLN (y_idx);
187
178
_display->setCursor (0 , y_idx);
188
179
i++;
189
180
}
0 commit comments