jk-flipflop

hjlab/hachan-lab1/jk-flipflop

No description
jk-flipflop
@/jk-flipflop
Jboolean
Cpulse
Kboolean
jk-flipflop
J
C
K
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 J= getValue<input_J>(ctx);
        bool K= getValue<input_K>(ctx);
        
        if (C && !J && K) {
            newState= false;
        }   else if (C && J && !K) {
            newState= true;
        }   else if (C && J && K) {
            newState =! oldState;
        }   else if (!C || !J && !K) {
            newState= oldState;
        } 
        
         if (newState == oldState)
            return;
        
        bool Q_=!newState;
        emitValue<output_Q>(ctx, newState);
        emitValue<output_Q_>(ctx, Q_);
    }
}