delay-boolean

nazarijtipusak080/work-with-bit/delay-boolean

No description
delay-boolean
@/delay-boolean
Tnumber
Time to delay in seconds
SETpulse
Resets current countdown, starts new countdown
RSTpulse
Resets current countdown, i.e. cancels the delay
delay-boolean
T
SET
RST
DONE
ACT
ACTboolean
Outputs true when delay is in progress
DONEboolean
To use the node in your project you should have the nazarijtipusak080/work-with-bit 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

node {
    void evaluate(Context ctx) {
        if (isInputDirty<input_RST>(ctx)) {
            clearTimeout(ctx);
            emitValue<output_ACT>(ctx, false);
             emitValue<output_DONE>(ctx, false);
        } else if (isInputDirty<input_SET>(ctx)) {
            TimeMs dt = getValue<input_T>(ctx) * 1000;
            setTimeout(ctx, dt);
            emitValue<output_ACT>(ctx, true);
        } else if (isTimedOut(ctx)) {
            emitValue<output_DONE>(ctx, true);
            emitValue<output_ACT>(ctx, false);
        }
    }
}

Tabular tests

__time(ms)TSETRSTDONEACT
00.5no-pulseno-pulseno-pulsefalse
10000.5pulseno-pulseno-pulsetrue
15000.5no-pulseno-pulseno-pulsetrue
15010.5no-pulseno-pulsepulsefalse
20000.5pulsepulseno-pulsefalse
25000.5pulseno-pulseno-pulsetrue
26002no-pulseno-pulseno-pulsetrue
27002no-pulsepulseno-pulsefalse
30012no-pulseno-pulseno-pulsefalse