sht2x-device

wayland/sht2x-rh-temp/sht2x-device

Create an SHT2x device.
sht2x-device
@/sht2x-device
Create an SHT2x device.
I2Cxod/i2c/i2c
I²C bus
sht2x-device
DEV
I2C
DEV@/sht2x-device
An SHT2x device.
To use the node in your project you should have the wayland/sht2x-rh-temp 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

// Tell XOD where it can download the libraries:
#pragma XOD require "https://github.com/RobTillaart/SHT2x"

//Include C++ libraries
#include <Wire.h>
#include <SHT2x.h>

node {

    meta {
        // Define our custom type as a pointer on the class instance.
        using Type = SHT2x*;
    }

    uint8_t mem[sizeof(SHT2x)];
    // Create an object of class SHT2x
    SHT2x sensor = SHT2x();

    void evaluate(Context ctx) {
        // It should be evaluated only once on the first (setup) transaction
        if (!isSettingUp())
            return;

        auto wire = getValue<input_I2C>(ctx);

        Type sensor = new (mem) SHT2x(wire);
        emitValue<output_DEV>(ctx, sensor);

        // Try to initialize sensor
        if (!sensor->begin()) {
            raiseError(ctx);
            return;
        }
        emitValue<output_DEV>(ctx, sensor);
    }
}