To use the node in your project you should have the wayland/si1145-light-sensor 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 could download the library:
#pragma XOD require "https://github.com/adafruit/Adafruit_SI1145_Library"
//Include C++ libraries
{{#global}}
#include <Wire.h>
#include <Adafruit_SI1145.h>
{{/global}}
struct State {
uint8_t mem[sizeof(Adafruit_SI1145)];
};
// Define our custom type as a pointer on the class instance.
using Type = Adafruit_SI1145*;
{{ GENERATED_CODE }}
void evaluate(Context ctx) {
// It should be evaluated only once on the first (setup) transaction
if (isSettingUp()) {
auto state = getState(ctx);
// Create a new object in the memory area reserved previously.
Type sensor = new (state->mem) Adafruit_SI1145();
if (!sensor->begin()) {
raiseError(ctx);
return;
}
}
// Measure light intensity only if there is an input pulse.
if (isInputDirty<input_UPD>(ctx)) {
auto state = getState(ctx);
auto sensor = reinterpret_cast<Adafruit_SI1145*>(state->mem);
emitValue<output_VIS>(ctx, sensor->readVisible());
emitValue<output_IR>(ctx, sensor->readIR());
float UVindex = sensor->readUV();
// the index is multiplied by 100 so to get the
// integer index, divide by 100!
UVindex /= 100.0;
emitValue<output_UV>(ctx, UVindex);
emitValue<output_DONE>(ctx, 1);
}
}