GxEPD2 - Selecting Display Type at Runtime?

Hello. I'm new, so please forgive a rookie question...

I'm using an ePaper display from Adafruit: Adafruit 1.54 Monochrome eInk / ePaper Display with SRAM [200x200 with SSD1681] : ID 4196 : $24.95 : Adafruit Industries, Unique & fun DIY electronics and kits

This display has gone through a revision and now is incompatible with a previous release of an identical-looking device.

I've been using the nifty GxEPD2 library on the previous version for its nice partial update support and have gotten it to work with the newer board as well with a compile-time selection of the type of device.

However, given I have a mix of devices, I'd like to be able to switch which driver I use at boot time so I can support both the old and new devices with one firmware load.

What's the right way to go about this? I've tried declaring one of each type and then tried to make a suitable pointer to select which one I want to work with, but alas, no joy so far...

Any suggestions would be greatly appreciated!

Thanks!

-John

'''
// ADAFRUIT 1.54" ePaper Display. SSD1608

GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display1(GxEPD2_154(/CS=5/ EPD_CS, /DC=/ EPD_DC, /RST=/ EPD_RESET, /BUSY=/ EPD_BUSY)); // GDEH0154D67

// ADAFRUIT 1.54" ePaper Display. SSD1681

GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display2(GxEPD2_154_D67(/CS=5/ EPD_CS, /DC=/ EPD_DC, /RST=/ EPD_RESET, /BUSY=/ EPD_BUSY)); // GDEW0154M09 200x200

SomeKindOfDeclaration??? * display;

//***************************************************************************

void initDisplay()
{

display = &display1;

display->init(0);
display->setRotation(3);
display->setTextSize(2);
display->setTextColor(GxEPD_BLACK);
display->fillScreen(GxEPD_WHITE);
return;
}

'''

@jmprice50, Hi, welcome to the forum!

Yes, this can be done easily, by selecting:

// base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
// enable GxEPD2_GFX base class
#define ENABLE_GxEPD2_GFX 1

You can then declare:

GxEPD2_GFX* display;

And set:

display = &display1;

or:

display = &display2;

Note that using code windows, code tags, for code makes it nicer to read, even for short code pieces.

Jean-Marc

Other uses of this are shown in GxEPD2_GFX_Example and GxEPD2_MultiDisplayExample.

Thank you very much for the pointer. :slight_smile:

I'll give it a try today.

Got it working. (I don't know how I missed the example...)
Thanks so much for the help!
Regards, John.