ticker(second)

koadrobot/progress/ticker(second)

No description
ticker(second)
@/ticker(second)
ENboolean
Enabled or not. If set to `false` pulses on `UPD` do not change the output value. Effictively that means the timer is paused. Set to `true` again to continue time counting.
Tsecnumber
Tick interval in second.
UPDpulse
Triggers the time value update.
ticker(second)
EN
Tsec
UPD
TICK
TICKpulse
Pulses on each time interval end
To use the node in your project you should have the koadrobot/progress 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

struct State 
{
  TimeMs nextTrig;
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) 
{
    State* state = getState(ctx);

    TimeMs tNow = transactionTime();
    TimeMs dt = (uint32_t)getValue<input_Tsec>(ctx) * 1000;
    TimeMs tNext = tNow + dt;

    auto isEnabled = getValue<input_EN>(ctx);
    auto isRstDirty = isInputDirty<input_RST>(ctx);

    if (isTimedOut(ctx) && isEnabled && !isRstDirty) 
    {
        emitValue<output_TICK>(ctx, 1);
        state->nextTrig = tNext;
        setTimeout(ctx, dt);
    }

    if (isRstDirty || isInputDirty<input_EN>(ctx)) 
    {
        // Handle enable/disable/reset
        if (dt <= 0 || !isEnabled) 
        {
            // Disable timeout loop on zero IVAL or explicit false on EN
            state->nextTrig = 0;
            clearTimeout(ctx);
        } 
        else if (state->nextTrig < tNow || state->nextTrig > tNext) 
        {
            // Start timeout from scratch
            state->nextTrig = tNext;
            setTimeout(ctx, dt);
        }
    }
}