timer-copy

hio/nwt-gus-hi/timer-copy

A simple timer/stopwatch
timer-copy
@/timer-copy
A simple timer/stopwatch
ENboolean
Enabled or not. If set to `false` pulses on `UPD` do not change the output value. Effectively that means the timer is paused. Set to `true` again to continue time counting.
RSTpulse
Resets the current time value to zero.
UPDpulse
Triggers the time value update.
timer-copy
OUT
EN
RST
UPD
OUTnumber
The current time value in seconds.
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

node {
    TimeMs lastUpdateTime;

    void evaluate(Context ctx) {
        bool enabled = getValue<input_EN>(ctx);
        bool update = isInputDirty<input_UPD>(ctx);
        bool reset = isInputDirty<input_RST>(ctx);

        TimeMs t = transactionTime();
        if (reset)
            emitValue<output_OUT>(ctx, 0);
        else if (enabled && update) {
            Number dtSeconds = (t - lastUpdateTime) / 1000.0;
            Number oldSeconds = getValue<output_OUT>(ctx);
            emitValue<output_OUT>(ctx, oldSeconds + dtSeconds);
        }

        lastUpdateTime = t;
    }
}