arduinointerrupt-handling

How to exit waitPress() fuction of the Keypad library?


I have a library on Arduino that declares a function like this :

void Keypad::waitPress()
// Wait for any key to be pressed.
 { while (scan() == 0);
 }

Which, for one conditional is fine, but I also have an ISR (interrupt system routine) in my main code which will likely be triggered during the waitPress() call :

static void isr_zero(void) {
    if (isr_change_flag == 0)
    {
      isr_dest = 0;
      isr_change_flag = 1;
    }
  }

Since Keypad::waitPress is a loop, it won't care if the ISR is triggered and will continue looping indefinitely until a key is pressed, which is an undesireable behaviour as I need that ISR to act there

Is there a way to break that while loop if the ISR is triggered?

I thank about calling the processing function from the ISR, but I know that that's not good practice to hook a long running function within an ISR, although that would technically work


Solution

  • Reading through the .h file, I found that the class actually exported a that got me a view of the component output

    I was able to implement it and my code now works

    while (KEYPAD1() != true) {
      if (isr_change_flag == 1)
          {
            break;
          }
        }