Interrupt in complex programs


#1

I had do dinosalvioni/hwlibrary/rf433receive node baseo on bradzilla84/433mhz-rcswitch
it works fine in “stand alone program” but when i put it in more big complex software (as example bitrex/xod-menu-system) it start but dont work (interrupt dont receive siglal or similar effect)
I suspect it is something related to interrupt management
How XOD operate with interrupts?
there’s a node for use easy interrupts signal? (as example interrupt number -> interrupt pulse that start and run “over the main program”)

Any comment and workaround is welcome.

The best thing would be a tutorial on the interrupt’s use

I Use Arduino Mega

Thanks a lot


#2

There’s no interrupt management built in XOD C++ runtime (yet). A quick solution one could try is the following (very rough draft, unchecked):

volatile uint8_t interruptCount = 0;

void myISR() {
  // Record we have had an interrupt
  ++interruptCount;
}

void evaluate(Context ctx) {
    if (isSettingUp()) {
        // Register handler once
        auto pin = getValue<input_PORT>(ctx);
        attachInterrupt(digitalPinToInterrupt(pin), myISR, RISING);
    }

    if (interruptCount) {
        // Process a single interrupt
        --interruptCount;
        emitValue<output_OUT>(ctx, 1);
    }

    // Come back on next transaction
    setTimeout(ctx, 0);
}