segm8-device

amperka/segm8/segm8-device

Device node for a single SegM8 display module or several modules linked in a daisy chain connected via hardware or software SPI interface. If the DO and CLK pin values are D255 the hardware SPI is used. Other DO and CLK pin values are used for the software SPI.
segm8-device
@/segm8-device
Device node for a single SegM8 display module or several modules linked in a daisy chain connected via hardware or software SPI interface. If the DO and CLK pin values are D255 the hardware SPI is used. Other DO and CLK pin values are used for the software SPI.
Nnumber
The number of modules in the daisy-chain. The default is 1.
CSport
The "chip select" board port of the SPI interface the display is connected to. You can use any Arduino pin. For example: 'D8'.
DOport
The "data output" board port of the SPI interface the display is connected to. It can be named MOSI. You can use any pin of the Arduino. For example: 'D3'. Leave this parameter at 'D255' when using hardware SPI.
CLKport
The "serial clock" board port of the SPI interface the display is connected to. You can use any pin of the Arduino. For example: 'D4'. Leave this parameter at 'D255' when using hardware SPI.
segm8-device
N
CS
DO
CLK
DEV
DEV@/segm8-device
The SegM8 device.
To use the node in your project you should have the amperka/segm8 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 require "https://github.com/amperka/SegM8"

{{#global}}
#include "segm8.h"
{{/global}}

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

using Type = SegM8*;

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    State* state = getState(ctx);
    if(isSettingUp()) {
        auto cnt = getValue<input_N>(ctx);
        auto cs = getValue<input_CS>(ctx);
        auto d0 = getValue<input_DO>(ctx);
        auto clk = getValue<input_CLK>(ctx);
        Type chain;
        if(d0 == 255 || clk == 255) {
            chain = new (state->mem) SegM8(cs, cnt);
        } else {
            chain = new (state->mem) SegM8(cs, d0, clk, cnt);
        }
        chain->begin();
        emitValue<output_DEV>(ctx, chain);
    }
}