read-byte

xod/i2c/read-byte

Reads the next byte received from an I²C device after `request` succeeded. Possible errors: - Can't read byte
read-byte
@/read-byte
Reads the next byte received from an I²C device after `request` succeeded. Possible errors: - Can't read byte
I2C@/i2c
I²C interface object
READpulse
Triggers the read. Use another `read-byte` or `request` as a source signal.
read-byte
BYTE
DONE
I2C
READ
DONEpulse
Pulses when read completes successfully. When multiple bytes should be read, send it to the next `read-byte` node in a chain.
BYTEbyte
The byte read

C++ implementation

#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_READ
#pragma XOD error_raise enable

node {
    void evaluate(Context ctx) {
        if (!isInputDirty<input_READ>(ctx))
            return;

        auto wire = getValue<input_I2C>(ctx);
        if (!wire->available()) {
            raiseError(ctx);
            return;
        }

        auto res = wire->read();
        if (res == -1) {
            raiseError(ctx); // Can't read byte
            return;
         }

        emitValue<output_BYTE>(ctx, (uint8_t)res);
        emitValue<output_DONE>(ctx, 1);
    }
}