lis3dh-device

wayland/lis3dh-accelerometer/lis3dh-device

Create a lis3dh device.
lis3dh-device
@/lis3dh-device
Create a lis3dh device.
I2Cxod/i2c/i2c
I²C bus.
ADDRbyte
I²C address of lis3dh device.
lis3dh-device
I2C
ADDR
DEV
DEV@/lis3dh-device
A lis3dh device.
To use the node in your project you should have the wayland/lis3dh-accelerometer 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_Sensor"
#pragma XOD require "https://github.com/adafruit/Adafruit_LIS3DH"
#pragma XOD require "https://github.com/adafruit/Adafruit_BusIO"

//Include C++ libraries
{{#global}}
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LIS3DH.h>
{{/global}}

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

// Define our custom type as a pointer on the class instance.
using Type = Adafruit_LIS3DH*;

{{ GENERATED_CODE }}

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

    auto state = getState(ctx);
    auto address = getValue<input_ADDR>(ctx);
    auto wire = getValue<input_I2C>(ctx);

    // Create a new object in the memory area reserved previously.
    Type sensor = new (state->mem) Adafruit_LIS3DH(wire);

    if (!sensor->begin(address)) {
      raiseError(ctx);
      return;
    }

    emitValue<output_DEV>(ctx, sensor);
}