wiringpi-dotnet icon indicating copy to clipboard operation
wiringpi-dotnet copied to clipboard

Implement Interrupt deregistration

Open sensslen opened this issue 4 years ago • 4 comments

This Pull Request implements the requested interface change from https://github.com/unosquare/raspberryio/pull/212.

It also tries to improve operational safety, as (if I do understand the code correctly) ther can only ever be one interrupt registered. This is handled by this pull request also by throwing an exception if another interrupt has alredy been registered.

With the possibility to also remove registered callbacks it is now also possible to react to such an event.

sensslen avatar Jun 19 '20 10:06 sensslen

Hi @sensslen

At first glance this seems to be a good approach, nevertheless, since WiringPi does not support unsubscribing from interrupts, actually the Raspberry will continue running the thread for the interrupt doing nothing.

If you change CallRegisteredInterruptCallback function to log something besides calling InterruptCallback, you will see that even after RemoveInterruptCallback is called the log will continue being executing.

private void CallRegisteredInterruptCallback() 
{
   InterruptCallback?.Invoke();
   Console.WriteLine("Interrupt was called");
}

k3z0 avatar Jun 19 '20 14:06 k3z0

I am well aware of the fact that wiringpi does not support deregitration of interrupts. Nevertheless I find it much better to have the callback of a static class being called even if no interrupt is currently active than any class that might also be already disposed at the time of the intterupt.

As you will never be able to control the consumer of said intterupt, I would suggest to handle the shortcomings of the base library in the code we control.

It might be a good idea to always register for interrupts on both edges and only forward the ones registered for. As in my application I don't require such functionality I left this out but this might be a better solution.

sensslen avatar Jun 22 '20 05:06 sensslen

Hi @sensslen, we are looking for maintainers, you can apply at https://adoptoposs.org/p/67b02bee-a00e-446a-a321-c1a6449014bc

geoperez avatar Feb 15 '21 14:02 geoperez

Hi @geoperez ,

I do have no interest in this currently. Sorry!

sensslen avatar Feb 17 '21 14:02 sensslen