@@ -173,9 +173,8 @@ int16_t DisplayHardware::parsePin(const char *pinStr) {
173173 Pointer to the SPI configuration structure for EPD.
174174 @return True if configuration was successful, False otherwise.
175175*/
176- bool DisplayHardware::beginEPD (
177- wippersnapper_display_v1_EPDConfig *config,
178- wippersnapper_display_v1_EpdSpiConfig *spi_config) {
176+ bool DisplayHardware::beginEPD (wippersnapper_display_v1_EPDConfig *config,
177+ wippersnapper_display_v1_SpiConfig *spi_config) {
179178 // Validate pointers
180179 if (config == nullptr || spi_config == nullptr ) {
181180 WS_DEBUG_PRINTLN (" [display] EPD config or SPI config is null!" );
@@ -273,9 +272,8 @@ void DisplayHardware::removeSuffix(const char *suffix) {
273272 Pointer to the SPI configuration structure for TFT.
274273 @return True if configuration was successful, False otherwise.
275274*/
276- bool DisplayHardware::beginTft (
277- wippersnapper_display_v1_TftConfig *config,
278- wippersnapper_display_v1_TftSpiConfig *spi_config) {
275+ bool DisplayHardware::beginTft (wippersnapper_display_v1_TftConfig *config,
276+ wippersnapper_display_v1_SpiConfig *spi_config) {
279277 // Validate pointers
280278 if (config == nullptr || spi_config == nullptr ) {
281279 WS_DEBUG_PRINTLN (" [display] EPD config or SPI config is null!" );
@@ -333,6 +331,65 @@ bool DisplayHardware::beginTft(
333331 return true ;
334332}
335333
334+ /* !
335+ @brief Attempts to configure and initialize an OLED display
336+ @param config
337+ Pointer to the OLED's configuration structure.
338+ @param i2c_config
339+ Pointer to the I2C configuration structure for OLED.
340+ @return True if configuration was successful, False otherwise.
341+ */
342+ bool DisplayHardware::beginOled (
343+ wippersnapper_display_v1_SSD1306Config *config,
344+ wippersnapper_display_v1_I2cConfig *i2c_config) {
345+ // Validate pointers
346+ if (config == nullptr || i2c_config == nullptr || !i2c_config->has_i2c ) {
347+ WS_DEBUG_PRINTLN (" [display] OLED or I2C config is null!" );
348+ return false ;
349+ }
350+
351+ // If we already have a display driver assigned to this hardware instance,
352+ // clean it up!
353+ if (_drvDisp) {
354+ delete _drvDisp;
355+ _drvDisp = nullptr ;
356+ }
357+
358+ if (strnlen (i2c_config->i2c .i2c_device_name ,
359+ sizeof (i2c_config->i2c .i2c_device_name )) <
360+ sizeof (i2c_config->i2c .i2c_device_name ) &&
361+ strcmp (i2c_config->i2c .i2c_device_name , " SSD1306" ) == 0 ) {
362+ _drvDisp = new dispDrvSsd1306 (WS._i2cPort0 ->getBus (),
363+ i2c_config->i2c .i2c_device_address );
364+ } else {
365+ WS_DEBUG_PRINTLN (" [display] Unsupported OLED driver!" );
366+ return false ;
367+ }
368+
369+ // Validate that the display driver was created successfully
370+ if (!_drvDisp) {
371+ WS_DEBUG_PRINTLN (" [display] Failed to create display driver!" );
372+ _drvDisp = nullptr ;
373+ return false ;
374+ }
375+
376+ // Configure display dimensions and text size
377+ _drvDisp->setWidth (config->width );
378+ _drvDisp->setHeight (config->height );
379+ // tODO: Remove the ssd-1306 -specic text size setters
380+ // _drvDisp->setTextSize(config->text_size);
381+
382+ // Initialize the display driver
383+ if (!_drvDisp->begin ()) {
384+ WS_DEBUG_PRINTLN (" [display] Failed to begin display driver!" );
385+ delete _drvDisp;
386+ _drvDisp = nullptr ;
387+ return false ;
388+ }
389+
390+ return true ;
391+ }
392+
336393/* !
337394 @brief Gets the name of the display hardware instance.
338395 @return The name of the display hardware instance.
0 commit comments