toggle(pulse)

koadrobot/logics/toggle(pulse)

No description
toggle(pulse)
@/toggle(pulse)
SETpulse
Sets stored value to 1
TGLpulse
Toggles (inverts) stored value
RSTpulse
Sets stored value to 0
Tnumber
Value to be output if condition is true
Fnumber
Value to be output if condition is false
toggle(pulse)
SET
TGL
RST
T
F
RT
RF
RFnumber
Outputs value of `T` if `COND` is true, and `F` otherwise
RTnumber
Outputs value of `F` if `COND` is true, and `T` otherwise
To use the node in your project you should have the koadrobot/logics 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 dirtieness disable

struct State {
    bool isToggled=false;
};

{{ GENERATED_CODE }}

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

    if(isInputDirty<input_SET>(ctx))
    {
        emitValue<output_RT>(ctx, getValue<input_T>(ctx));
        emitValue<output_RF>(ctx, getValue<input_F>(ctx));
        state->isToggled = false;
    }
    else if(isInputDirty<input_RST>(ctx))
    {
        emitValue<output_RT>(ctx, getValue<input_F>(ctx));
        emitValue<output_RF>(ctx, getValue<input_T>(ctx));
        state->isToggled = true;
    }
    else if(isInputDirty<input_TGL>(ctx))
    {
        if(state->isToggled)
        {
            emitValue<output_RT>(ctx, getValue<input_T>(ctx));
            emitValue<output_RF>(ctx, getValue<input_F>(ctx));
            state->isToggled = false;
        }
        else
        {
            emitValue<output_RT>(ctx, getValue<input_F>(ctx));
            emitValue<output_RF>(ctx, getValue<input_T>(ctx));
            state->isToggled = true;
        }
    }
}

Tabular tests

SETRSTTGLTFRTRF
no-pulseno-pulseno-pulse10201010
pulseno-pulseno-pulse10201020
no-pulsepulseno-pulse10202010
no-pulseno-pulsepulse10201020
no-pulseno-pulsepulse10202010