Unattach an ISR from a PinDetect object

01 Jun 2011

The function below attach a function to a PinDetect object.

void attach_asserted (void(*function)(void))

Is there any way to unattach an ISR from a PinDetect object.

Thank you in advance.

01 Jun 2011

PinDetect internally uses a FunctionPointer object to store the callback. FunctionPointer itself doesn't have an detach method so the short answer is no. But there's often more ways to do things. What is it you want to do? Just stop PinDetect making calls at all?

02 Jun 2011

I want to stop PinDetect making calls for a while, and then after an external event, turn it on again.

02 Jun 2011

Several methods.

  • Create an instance you then later delete and recreate. However, slow and silly.
  • Hack the library to do what you want. But since there's no detach function on a function pointer you'll be implementing teh following which you can just as well do in your own program
  • Use a flag to allow the callback to either a) return immediately or b) execute:-

bool allow_callback = false;

void my_callback(void)
{
    if (!allow_callback) return;
    // ... else run your code code
}

int main()
{
    // Setting allow_callback = true allows the callback to execute. You get the idea.
}
06 Jun 2011

Thank you Andy.

I am gonna try with one of the methods you suggested me.

Best wishes

Emanuel