d-flipflop

hjlab/hachan-lab1/d-flipflop

No description
d-flipflop
@/d-flipflop
Dboolean
Cpulse
d-flipflop
D
C
Q
Q_
Q_boolean
Qboolean
To use the node in your project you should have the hjlab/hachan-lab1 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) {
        bool oldState = getValue<output_Q>(ctx);
        bool newState = oldState;
        bool C= isInputDirty<input_C>(ctx);
        bool D= getValue<input_D>(ctx);
       
        if (C && D) {
            newState= true;
        } else if (C && !D) {
            newState= false;
        } else if (!C && !D) {
            newState=oldState;
        }
        
        if (newState == oldState)
            return;

        bool Q_ = !newState;
        emitValue<output_Q>(ctx, newState);
        emitValue<output_Q_>(ctx, Q_);
    }
}