display

wkov/colony/display

No description
display
@/display
ADDRbyte
I²C address of expander chip.
BLboolean
Backlight enable/disable.
P1number
Text position for the first line.
V1string
Text value for the first line.
P2number
Text position for the second line.
V2string
Text value for the second line.
UPDpulse
Trigger to update display state.
display
DONE
ADDR
BL
P1
V1
P2
V2
UPD
DONEpulse
Pulse when updating is done.
To use the node in your project you should have the wkov/colony 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_UPD

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

nodespace {

    const unsigned char RUS1[] = {
        0x41,0xa0,0x42,0xa1,0xe0,0x45,0xa3,0xa4,0xa5,0xa6,0x4b,0xa7,0x4d,0x48,0x4f,0xa8,
        0x50,0x43,0x54,0xa9,0xaa,0x58,0xe1,0xab,0xac,0xe2,0xad,0xae,0x62,0xaf,0xb0,0xb1,
        0x61,0xb2,0xb3,0xb4,0xe3,0x65,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0x6f,0xbe
    };

    const unsigned char RUS2[] = {
        0x70,0x63,0xbf,0x79,0xe4,0x78,0xe5,0xc0,0xc1,0xe6,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7
    };

    unsigned char convert(unsigned char prev, unsigned char next) {
        if (prev == 0xd0)
            return next == 0x81 ? 0xa2 : RUS1[next - 0x90];
        if (prev == 0xd1)
            return next == 0x91 ? 0xb5 : RUS2[next - 0x80];
        return next;
    }

    void print(LiquidCrystal_I2C* lcd, int8_t row, int8_t len, int8_t pos, XString str) {
        lcd->setCursor(0, row);

        auto it = str.iterate();

        unsigned char prev;
        unsigned char next;

        while (len > 0) {
            prev = next;
            next = 0x20;

            if (pos > 0) {
                pos--;
            } else if (it) {
                next = *it;
                it++;

                if (next == 0xd0 || next == 0xd1) {
                    continue;
                } else if (pos < 0) {
                    pos++;
                    continue;
                }

                next = convert(prev, next);
            }

            lcd->write(next);
            len--;
        }
    }
}

node {

    LiquidCrystal_I2C* melt;

    void evaluate(Context ctx) {
        if (!melt) {
            melt = new LiquidCrystal_I2C(getValue<input_ADDR>(ctx), 16, 2);
            melt->begin();
        }

        melt->setBacklight(getValue<input_BL>(ctx));

        print(melt, 0, 16, getValue<input_P1>(ctx), getValue<input_V1>(ctx));
        print(melt, 1, 16, getValue<input_P2>(ctx), getValue<input_V2>(ctx));

        emitValue<output_DONE>(ctx, 1);
    }
}