schmitt-trigger

cesars/utils/schmitt-trigger

No description
schmitt-trigger
@/schmitt-trigger
Xnumber
input value
LOWnumber
threshold low
HIGHnumber
threshold high
schmitt-trigger
Xout
ACT
Xout'
ACT'
X
LOW
HIGH
ACT'boolean
Schmitt Trigger invert output
Xout'number
ACTboolean
Schmitt Trigger invert output
Xoutnumber
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

#pragma XOD dirtieness disable

node {

    void evaluate(Context ctx) {
        auto x = getValue<input_X>(ctx);
        auto min = getValue<input_LOW>(ctx);
        auto max = getValue<input_HIGH>(ctx);
        bool oldState = getValue<output_ACT>(ctx);
        bool newState = oldState;

        if (x <= min) {
            newState = false;
        } else if (x >= max) {
            newState = true;
        }
        emitValue<output_ACT>(ctx, newState);
        if (getValue<output_ACT>(ctx) == true){
            emitValue<output_Xout>(ctx, getValue<input_X>(ctx));
            emitValue<output_XoutU0027>(ctx, 0);
            emitValue<output_ACTU0027>(ctx, false);
        }else{
            emitValue<output_ACTU0027>(ctx, true);
            emitValue<output_Xout>(ctx, 0);
            emitValue<output_XoutU0027>(ctx, getValue<input_X>(ctx));
        }
    }
}