Skip to content

Commit 6ab5a6f

Browse files
committed
Separate out rotation for future usage and add notes
1 parent 8c8c5c2 commit 6ab5a6f

File tree

4 files changed

+37
-21
lines changed

4 files changed

+37
-21
lines changed

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,9 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
892892
(uint8_t)msgDeviceInitReq->i2c_output_add.config.ssd1306_config.width,
893893
(uint8_t)msgDeviceInitReq->i2c_output_add.config.ssd1306_config.height,
894894
(uint8_t)
895-
msgDeviceInitReq->i2c_output_add.config.ssd1306_config.text_size);
895+
msgDeviceInitReq->i2c_output_add.config.ssd1306_config.text_size,
896+
90); // fixed as currently the only screen is 128x64 featherwing which
897+
// needs a rotation of 1 / 90degrees, and constructor w/h swap.
896898
if (!_sh1107->begin()) {
897899
WS_DEBUG_PRINTLN("ERROR: Failed to initialize sh1107!");
898900
_busStatusResponse =
@@ -925,7 +927,8 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
925927
(uint8_t)msgDeviceInitReq->i2c_output_add.config.ssd1306_config.width,
926928
(uint8_t)msgDeviceInitReq->i2c_output_add.config.ssd1306_config.height,
927929
(uint8_t)
928-
msgDeviceInitReq->i2c_output_add.config.ssd1306_config.text_size);
930+
msgDeviceInitReq->i2c_output_add.config.ssd1306_config.text_size,
931+
0); // TODO: add rotation to protobuf and IO UI for adapted max len
929932
if (!_ssd1306->begin()) {
930933
WS_DEBUG_PRINTLN("ERROR: Failed to initialize ssd1306!");
931934
_busStatusResponse =

src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ class WipperSnapper_I2C_Driver_Out : public WipperSnapper_I2C_Driver {
6262
The height of the display in pixels.
6363
@param text_size
6464
The display's text size.
65+
@param rotation
66+
The rotation of the display in degrees, default is 0 (no rotation).
6567
*/
6668
virtual void ConfigureSSD1306(uint8_t width, uint8_t height,
67-
uint8_t text_size) {
69+
uint8_t text_size, uint8_t rotation = 0) {
6870
// noop
6971
}
7072

src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_Sh1107.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,9 @@ class WipperSnapper_I2C_Driver_Out_SH1107
6868
@returns True if initialized successfully, False otherwise.
6969
*/
7070
bool begin() {
71-
uint8_t rotation = 0; // Default rotation
72-
// Attempt to create and allocate a SH1107 obj
73-
if (_width == 128 && _height == 64) { // featherwing
71+
if (_width == 128 && _height == 64 && _rotation == 1) {
72+
// featherwing needs to be rotated 90 degrees and swap w/h
7473
_display = new Adafruit_SH1107(_height, _width, _i2c);
75-
rotation = 1; // Set rotation to 1 for 128x64 OLED featherwing
7674
} else {
7775
_display = new Adafruit_SH1107(_width, _height, _i2c);
7876
}
@@ -88,7 +86,7 @@ class WipperSnapper_I2C_Driver_Out_SH1107
8886
// Clear the buffer.
8987
_display->clearDisplay();
9088
_display->display();
91-
_display->setRotation(rotation);
89+
_display->setRotation(_rotation); // 0-3, not degrees for SH1107
9290

9391
// Configure the text size and color
9492
_display->setTextSize(_text_sz);
@@ -115,11 +113,15 @@ class WipperSnapper_I2C_Driver_Out_SH1107
115113
The height of the display in pixels.
116114
@param text_size
117115
The magnification factor for the text size.
116+
@param rotation
117+
The rotation of the display in degrees, default is 0 (no rotation).
118118
*/
119-
void ConfigureSH1107(uint8_t width, uint8_t height, uint8_t text_size) {
119+
void ConfigureSH1107(uint8_t width, uint8_t height, uint8_t text_size,
120+
uint8_t rotation) {
120121
_width = width;
121122
_height = height;
122123
_text_sz = text_size;
124+
_rotation = rotation % 90;
123125
WS_DEBUG_PRINT("SH1107 text size: ");
124126
WS_DEBUG_PRINTLN(text_size);
125127
}
@@ -204,11 +206,12 @@ class WipperSnapper_I2C_Driver_Out_SH1107
204206
}
205207

206208
protected:
207-
Adafruit_SH1107 *_display =
208-
nullptr; ///< Pointer to the Adafruit_SH1107 object
209-
uint8_t _width; ///< Width of the display in pixels
210-
uint8_t _height; ///< Height of the display in pixels
211-
uint8_t _text_sz; ///< Text size of the display
209+
Adafruit_SH1107 *_display =
210+
nullptr; ///< Pointer to the Adafruit_SH1107 object
211+
uint8_t _width; ///< Width of the display in pixels
212+
uint8_t _height; ///< Height of the display in pixels
213+
uint8_t _rotation; ///< Rotation of the display (0-3)
214+
uint8_t _text_sz; ///< Text size of the display
212215
};
213216

214217
#endif // WIPPERSNAPPER_I2C_DRIVER_OUT_SH1107_H

src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_Ssd1306.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ class WipperSnapper_I2C_Driver_Out_Ssd1306
5353
*/
5454
~WipperSnapper_I2C_Driver_Out_Ssd1306() {
5555
if (_display != nullptr) {
56+
WS_DEBUG_PRINTLN("SSD1306 Destructor called, clearing display buffer.");
5657
_display->clearDisplay();
5758
_display->display();
59+
WS_DEBUG_PRINTLN("SSD1306 display cleared, turning off display.");
5860
_display->ssd1306_command(SSD1306_DISPLAYOFF);
5961
delete _display;
6062
_display = nullptr;
@@ -70,7 +72,8 @@ class WipperSnapper_I2C_Driver_Out_Ssd1306
7072
_display = new Adafruit_SSD1306(_width, _height, _i2c);
7173
if (!_display->begin(SSD1306_SWITCHCAPVCC, _sensorAddress, false, false))
7274
return false;
73-
// Configure the text size and color
75+
// Configure the rotation, text size and color
76+
_display->setRotation(_rotation);
7477
_display->setTextSize(_text_sz);
7578
_display->setTextColor(SSD1306_WHITE);
7679
// Use full 256 char 'Code Page 437' font
@@ -90,11 +93,15 @@ class WipperSnapper_I2C_Driver_Out_Ssd1306
9093
The height of the display in pixels.
9194
@param text_size
9295
The magnification factor for the text size.
96+
@param rotation
97+
The rotation of the display in degrees, default is 0 (no rotation).
9398
*/
94-
void ConfigureSSD1306(uint8_t width, uint8_t height, uint8_t text_size) {
99+
void ConfigureSSD1306(uint8_t width, uint8_t height, uint8_t text_size,
100+
uint8_t rotation = 0) {
95101
_width = width;
96102
_height = height;
97103
_text_sz = text_size;
104+
_rotation = rotation;
98105
WS_DEBUG_PRINT("SSD1306 text size: ");
99106
WS_DEBUG_PRINTLN(text_size);
100107
}
@@ -153,11 +160,12 @@ class WipperSnapper_I2C_Driver_Out_Ssd1306
153160
}
154161

155162
protected:
156-
Adafruit_SSD1306 *_display =
157-
nullptr; ///< Pointer to the Adafruit_SSD1306 object
158-
uint8_t _width; ///< Width of the display in pixels
159-
uint8_t _height; ///< Height of the display in pixels
160-
uint8_t _text_sz; ///< Text size of the display
163+
Adafruit_SSD1306 *_display =
164+
nullptr; ///< Pointer to the Adafruit_SSD1306 object
165+
uint8_t _width; ///< Width of the display in pixels
166+
uint8_t _height; ///< Height of the display in pixels
167+
uint8_t _rotation; ///< Rotation of the display in degrees
168+
uint8_t _text_sz; ///< Text size of the display
161169
};
162170

163171
#endif // WIPPERSNAPPER_I2C_DRIVER_OUT_SSD1306_H

0 commit comments

Comments
 (0)