v-delta-zahlen

hio/nwt-gus-hi/v-delta-zahlen

Calculates difference between current and past input values.
v-delta-zahlen
@/v-delta-zahlen
Calculates difference between current and past input values.
INnumber
Input value
UPDpulse
Update: trigger a calculation and store the current `IN` value as the new “past” value.
RSTpulse
Resets the stored past value to the current input value. Efficiently sets `OUT` to 0.
v-delta-zahlen
OUT
IN
UPD
RST
OUTnumber
The last difference value.
To use the node in your project you should have the hio/nwt-gus-hi 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_RST input_UPD
#pragma XOD dirtieness disable output_OUT

node {
    Number refValue = 0;

    void evaluate(Context ctx) {
        auto inValue = getValue<input_IN>(ctx);

        if (isInputDirty<input_RST>(ctx)) {
            refValue = inValue;
            emitValue<output_OUT>(ctx, 0);
            return;
        }

        if (!isInputDirty<input_UPD>(ctx)) {
          return;
        }

        auto outValue = inValue - refValue;
        emitValue<output_OUT>(ctx, outValue);
        refValue = inValue;
    }
}

Tabular tests

INUPDRSTOUT
0no-pulseno-pulse0
10pulseno-pulse10
30no-pulseno-pulse10
20no-pulsepulse0
30pulseno-pulse10
50pulseno-pulse20
10pulseno-pulse-40
10pulsepulse0
5pulseno-pulse-5