draw-text

wayland/ssd1306-oled-i2c/draw-text

Writes string to display buffer. To show content of display buffer on screen use node send-buffer-to-display.
draw-text
@/draw-text
Writes string to display buffer. To show content of display buffer on screen use node send-buffer-to-display.
DEV@/ssd1306-oled-i2c-device
An SSD1306 OLED device.
Xnumber
Cursor position x coordinate.
Ynumber
Cursor position y coordinate.
TEXTstring
Text string. Special characters can be specified using octal index. For example the degree symbol "°" (decimal code 248) can be specified using "\370".
SIZEbyte
Font size.
COLOURnumber
Colour of circle. Options: 0 = black; 1 = white; 2 = invert.
WRAPboolean
If TRUE text is wrapped.
UPDpulse
Update. Trigger write to display buffer.
draw-text
DEV
X
Y
TEXT
SIZE
COLOUR
WRAP
UPD
DONE
DONEpulse
Pulses on completion.
To use the node in your project you should have the wayland/ssd1306-oled-i2c library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

struct State {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    // The node responds only if there is an input pulse
    if (!isInputDirty<input_UPD>(ctx))
        return;

    // Get a pointer to the `Adafruit_SSD1306` class instance
    auto display = getValue<input_DEV>(ctx);
    auto cursor_x = getValue<input_X>(ctx);
    auto cursor_y = getValue<input_Y>(ctx);
    auto xString = getValue<input_TEXT>(ctx);
    auto font_size = getValue<input_SIZE>(ctx);
    auto colour = getValue<input_COLOUR>(ctx);
    auto wrap = getValue<input_WRAP>(ctx);

    // `length` returns the number of characters and you need an extra one to keep the
    // terminal NUL-character used in C string representation. Initialize to 0’s to
    // ensure the last char is indeed NUL
    // The following line worked on Arduino, but would not compile for esp8266:
    // char cString[length(xString) + 1] = { 0 };
    // Bug fixed by the following four lines provided by Martin Brader:
    int N=length(xString) + 1;
    char cString[N];
    for(int i=0;i<N;i++)
    cString[i]=0;
    // move the data from XString to the plain C string
    dump(xString, cString);

    // Use full 256 char 'Code Page 437' font
    display->cp437(true);
    display->setTextWrap(wrap);
    display->setCursor(cursor_x, cursor_y);
    display->setTextSize(font_size);
    display->setTextColor(colour);
    display->println(cString);

    emitValue<output_DONE>(ctx, 1);
}