mcp9808-device

wayland/mcp9808-thermometer/mcp9808-device

Create mcp9808 device.
mcp9808-device
@/mcp9808-device
Create mcp9808 device.
ADDRESSbyte
I²C address of the MCP9808 device. Default is 18h. The I²C address of the device can be changed using the address select pins (see https://learn.adafruit.com/adafruit-mcp9808-precision-i2c-temperature-sensor-guide/arduino-code).
RESOLUTIONbyte
Set resolution of measurements. Four modes are available (resolution and sample time in parentheses): 00h ( 0.5°C , 30 ms); 01h (0.25°C, 65 ms); 02h (0.125°C, 130 ms); 03h (0.0625°C, 250 ms).
mcp9808-device
ADDRESS
RESOLUTION
DEV
DEV@/mcp9808-device
A mcp9808 device.
To use the node in your project you should have the wayland/mcp9808-thermometer 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_MCP9808_Library"

//Include C++ libraries
{{#global}}
#include <Adafruit_MCP9808.h>
{{/global}}

// Reserve memory to store an instance of the Adafruit_MCP9808 class,
// and create the instance later:
struct State {
    uint8_t mem[sizeof(Adafruit_MCP9808)];
};

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


{{ GENERATED_CODE }}

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

    auto state = getState(ctx);
    uint8_t address = getValue<input_ADDRESS>(ctx);
    uint8_t resolution = getValue<input_RESOLUTION>(ctx);

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

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

    sensor->setResolution(resolution);

    emitValue<output_DEV>(ctx, sensor);

}