init

wayland/bme280-barometer/init

Initialize bme280-device.
init
@/init
Initialize bme280-device.
DEV@/bme280-device
A bme280-device.
I2Cxod/i2c/i2c
I²C bus.
ADDRbyte
I²C address (default = 77h).
MODEbyte
Operating mode for the sensor. Options: sleep = 00h, forced mode = 01h, normal mode = 03h.
OSTbyte
Oversampling rate for temperature sensor. Options: no over-sampling = 00h, 1x over-sampling = 01h, 2x over-sampling = 02h, 4x over-sampling = 03h, 8x over-sampling = 04h, 16x over-sampling = 05h.
OSPbyte
Oversampling rate for pressure sensor. Options: no over-sampling = 00h, 1x over-sampling = 01h, 2x over-sampling = 02h, 4x over-sampling = 03h, 8x over-sampling = 04h, 16x over-sampling = 05h.
OSHbyte
Oversampling rate for humidity sensor. Options: no over-sampling = 00h, 1x over-sampling = 01h, 2x over-sampling = 02h, 4x over-sampling = 03h, 8x over-sampling = 04h, 16x over-sampling = 05h.
FILTbyte
Filtering level for sensor data. Options: no filtering = 00h, 2x filtering = 01h, 4x filtering = 02h, 8x filtering = 03h, 16x filtering = 04h.
STDBYbyte
Standby duration in milliseconds. Options: 0.5 ms = 00h, 10 ms = 06h, 20 ms = 07h, 62.5 ms = 01h, 125 ms = 02h, 250 ms = 03h, 500 ms = 04h, 1000 ms = 05h.
INITpulse
Initialize sensor.
init
DEV
I2C
ADDR
MODE
OST
OSP
OSH
FILT
STDBY
INIT
OK
OKpulse
Pulse on successful initialization.
To use the node in your project you should have the wayland/bme280-barometer 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

#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_INIT

node {
    void evaluate(Context ctx) {
        // The node responds only if there is an input pulse
        if (!isInputDirty<input_INIT>(ctx))
            return;

        auto sensor = getValue<input_DEV>(ctx);
        auto wire = getValue<input_I2C>(ctx);
        uint8_t i2c_addr = getValue<input_ADDR>(ctx);
        
        if (!sensor->begin(i2c_addr, wire)) {
            raiseError(ctx);
            return;
        }
        uint8_t mode = getValue<input_MODE>(ctx);
        uint8_t temp = getValue<input_OST>(ctx);
        uint8_t pressure = getValue<input_OSP>(ctx);
        uint8_t humidity = getValue<input_OSH>(ctx);
        uint8_t filter = getValue<input_FILT>(ctx);
        uint8_t standby = getValue<input_STDBY>(ctx);
        sensor -> setSampling(mode, temp, pressure, humidity, filter, standby);
        emitValue<output_OK>(ctx, 1);
    }
}