ssd1306-oled-i2c-device

wayland/ssd1306-oled-i2c/ssd1306-oled-i2c-device

Create SSD1306 OLED device.
ssd1306-oled-i2c-device
@/ssd1306-oled-i2c-device
Create SSD1306 OLED device.
I2Cxod/i2c/i2c
I²C bus.
ADDRESSbyte
I²C address of the SSD1306 OLED device.
WIDTHnumber
Display width in pixels (default 128).
HEIGHTnumber
Display height in pixels (default 64).
RESET_PINnumber
Reset pin (using Arduino pin numbering), or -1 if not used (some displays might be wired to share the microcontroller's reset pin).
ssd1306-oled-i2c-device
I2C
ADDRESS
WIDTH
HEIGHT
RESET_PIN
DEV
DEV@/ssd1306-oled-i2c-device
An SSD1306 OLED device.
To use the node in your project you should have the wayland/ssd1306-oled-i2c 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 error_raise enable

// Tell XOD where it could download the library:
#pragma XOD require "https://github.com/adafruit/Adafruit_SSD1306"
#pragma XOD require "https://github.com/adafruit/Adafruit-GFX-Library"
#pragma XOD require "https://github.com/adafruit/Adafruit_BusIO"

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

// Adafruit_SSD1306 class wants to know I2C bus in the moment of instantiation
// but we don't know them at this moment.
// Therefore, we reserve memory to store an instance of the class,
// and create the instance later:
struct State {
    uint8_t mem[sizeof(Adafruit_SSD1306)];
};

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

{{ 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 wire = getValue<input_I2C>(ctx);
    auto width = getValue<input_WIDTH>(ctx);
    auto height = getValue<input_HEIGHT>(ctx);
    auto reset_pin = getValue<input_RESET_PIN>(ctx);

    // Create a new object in the memory area reserved previously.
    Type display = new (state->mem) Adafruit_SSD1306(width, height, wire, reset_pin);

    // Attempt to initialize display module; if attempt fails raise error
    auto address = getValue<input_ADDRESS>(ctx);
    if (!display->begin(SSD1306_SWITCHCAPVCC, address)) {
      raiseError(ctx);
      return;
    }

    emitValue<output_DEV>(ctx, display);
}