print-at

wayland/text-lcd-i2c/print-at

Prints a text on the LCD screen in the allocated area, specified by `ROW` index, position at the row and length. The text trims to the allocated area length. If the text is shorter — the rest of the allocated area will be cleared (replaced with whitespaces).
print-at
@/print-at
Prints a text on the LCD screen in the allocated area, specified by `ROW` index, position at the row and length. The text trims to the allocated area length. If the text is shorter — the rest of the allocated area will be cleared (replaced with whitespaces).
DEV@/text-lcd-i2c-device
A text-lcd-i2c-device.
ROWnumber
The row index on the display. Starts from 0.
POSnumber
Position in the row. Starts from 0.
LENnumber
The length of the allocated area on the LCD screen.
VALstring
Text to print on the row
DOpulse
Update the allocated area content
print-at
DEV
ROW
POS
LEN
VAL
DO
DEV'
DONE
DONEpulse
Fires when the allocated area is updated
DEV'@/text-lcd-i2c-device
A text-lcd-i2c-device.
To use the node in your project you should have the wayland/text-lcd-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

#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_DO

node {
    static void printAt(LiquidCrystal_I2C_MTW* lcd, uint8_t rowIndex, uint8_t posIndex, uint8_t len, XString str) {
        lcd->setCursor(posIndex, rowIndex);
        uint8_t whitespace = len;
        for (auto it = str.iterate(); it && whitespace > 0; ++it, --whitespace)
            lcd->write(*it);

        // Clear the rest of the area
        while (whitespace--)
            lcd->write(' ');
    }

    void evaluate(Context ctx) {
        auto t = getValue<input_DEV>(ctx);

        if (isInputDirty<input_DO>(ctx)) {
            XString str = getValue<input_VAL>(ctx);
            uint8_t row = (uint8_t) getValue<input_ROW>(ctx);
            uint8_t pos = (uint8_t) getValue<input_POS>(ctx);

            Number _len = getValue<input_LEN>(ctx);
            uint8_t restLen = t.cols - pos;
            uint8_t len = (_len > restLen) ? restLen : (uint8_t) _len;

            if (row < 0 || row >= t.rows || pos < 0 || pos >= t.cols) {
                raiseError<output_DONE>(ctx);
                return;
            }

            printAt(t.lcd, row, pos, len, str);
            emitValue<output_DONE>(ctx, 1);
        }

        emitValue<output_DEVU0027>(ctx, t);
    }
};