octoliner-device

amperka/octoliner/octoliner-device

Constructs an octoliner-device value for the Amperka Octoliner. Possible errors: — Invalid I2C address
octoliner-device
@/octoliner-device
Constructs an octoliner-device value for the Amperka Octoliner. Possible errors: — Invalid I2C address
I2Cxod/i2c/i2c
ADDRbyte
I²C address. 2Ah by default.
octoliner-device
I2C
ADDR
DEV
DEV@/octoliner-device
To use the node in your project you should have the amperka/octoliner 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/amperka/I2CioExpander"
#pragma XOD error_raise enable

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

struct State {
    uint8_t mem[sizeof(GpioExpander)];
};

using Type = GpioExpander*;

// clang-format off
{{ GENERATED_CODE }}
// clang-format on

void evaluate(Context ctx) {
    if (!isSettingUp()) return;
    auto state = getState(ctx);

    uint8_t addr = getValue<input_ADDR>(ctx);

    if (addr > 127) {
        raiseError(ctx); // Invalid I2C address
        return;
    }

    TwoWire* i2c = getValue<input_I2C>(ctx);

    Type octoliner = new (state->mem) GpioExpander(addr);

    octoliner->begin(i2c);
    octoliner->pwmFreq(8000);

    emitValue<output_DEV>(ctx, octoliner);
}