for-count

cesars/utils/for-count

No description
for-count
@/for-count
STARTnumber
Start Value to count.
STOPnumber
Stop Value to count.
STEPnumber
Value to add on each increment. (Stop > Start) Use a negative value (e.g. -1) to make decrements. (Stop < Start)
PULSEpulse
Triggers a single step.
RSTpulse
Resets the counting value to start.
for-count
START
STOP
STEP
PULSE
RST
OUT
DONE
DONEpulse
OUTnumber
The counting value. set OUT for start of counting.
To use the node in your project you should have the cesars/utils 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) {

        Number start = getValue<input_START>(ctx);
        Number stop = getValue<input_STOP>(ctx);
        Number step = getValue<input_STEP>(ctx);
        Number count = getValue<output_OUT>(ctx);

        if (isInputDirty<input_RST>(ctx)) {
            emitValue<output_OUT>(ctx, start);
        }
        else if (isInputDirty<input_PULSE>(ctx)){
            if(start>=count){
                count=start;
            }
            count += step;
            if (step*count >= step*stop) {
                    count=stop;
                    emitValue<output_DONE>(ctx, true);
            }
            emitValue<output_OUT>(ctx, count);
        }
    }
}