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);
}
}