init

gabbapeople/4d-ulcd/init

Initializes a 4D uLCD device with custom settings
init
@/init
Initializes a 4D uLCD device with custom settings
UARTxod/uart/uart
An UART interface to which 4D ULCD display is wired
RSTport
Board port number the RST pin of the display is connected to. By default and for the 4D-Arduino-Adaptor-Shield-II RST pin is D4.
UPDpulse
Updates all objects states
INITpulse
Triggets a new connection to a display
init
UART
RST
UPD
INIT
DEV
DONE
DONEpulse
Fires on a successful connection
DEV@/4d-ulcd
a 4D ULCD device
To use the node in your project you should have the gabbapeople/4d-ulcd 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 require "https://github.com/4dsystems/ViSi-Genie-Arduino-Library"

// clang-format off
{{#global}}
#include <genieArduino.h>
{{/global}}
// clang-format on

struct State {
    uint8_t mem[sizeof(Genie)];
    Genie* genie;
    uint8_t cmd;
    uint8_t object;
    uint8_t index;
    uint16_t eventData;
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    State* state = getState(ctx);
    auto uart = getValue<input_UART>(ctx);

    if (isInputDirty<input_INIT>(ctx)){
        state->genie = new (state->mem) Genie;
        state->genie->Begin(*(uart->toStream()));

        const uint8_t port = getValue<input_RST>(ctx);
        ::pinMode(port, OUTPUT);
        ::digitalWrite(port, 1);
        delay(100);
        ::digitalWrite(port, 0);
        delay(3500);
        emitValue<output_DONE>(ctx, 1);

    }


    if (isInputDirty<input_UPD>(ctx)){
        state->genie->DoEvents();
        genieFrame Event;
        state->genie->DequeueEvent(&Event);
        state->cmd = Event.reportObject.cmd;
        state->object = Event.reportObject.object;
        state->index = Event.reportObject.index;
        state->eventData = state->genie->GetEventData(&Event);
    }


    ValueType<output_DEV>::T obj;
    obj = { state->genie, state->cmd, state->object, state->index, state->eventData};
    emitValue<output_DEV>(ctx, obj);

}