ThingPulse / esp8266-oled-ssd1306

Driver for the SSD1306 and SH1106 based 128x64, 128x32, 64x48 pixel OLED display running on ESP8266/ESP32
https://thingpulse.com
Other
1.99k stars 637 forks source link

Dynamic data in an Overlay #271

Closed PR77 closed 4 years ago

PR77 commented 4 years ago

Hi there,

I have the following code snippet for an overlay;

void uiOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {
    String overlayText = String();

    display->setTextAlignment(TEXT_ALIGN_RIGHT);
    display->setFont(ArialMT_Plain_10);

    overlayText = "vBatt: ";
    overlayText += ((analogRead(A0) / 1023.0) * 4.55);
    overlayText += "V, UiFrm: ";
    overlayText += state->currentFrame;

    display->drawString(128, 0, overlayText);
}

With multiple frames all works very well, however I would like to make an element of the overlay dynamic based on a value passed in state->userData. Is it possible for the main loop to "know" when the overlay is being rendered and assign an object to state->userData? Perhaps something like;

    if (ui.getUiState()->currentFrame == OVERLAY) {
        ui.getUiState()->userData = (void *)&newMessageFlag;
    }

EDIT: I want to avoid global variables basically by using the userData pointer in addition to the overlays.

Thanks!

PR77 commented 4 years ago

Ended up having to use a global. Pending time, might see what it might take to add this to the library. Additionally, I would also like to have a userData pointer specific to each Frame and not just a single for the UI object.

Issue closed.