wiringpi-dotnet
wiringpi-dotnet copied to clipboard
Implement Interrupt deregistration
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.
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");
}
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.
Hi @sensslen, we are looking for maintainers, you can apply at https://adoptoposs.org/p/67b02bee-a00e-446a-a321-c1a6449014bc
Hi @geoperez ,
I do have no interest in this currently. Sorry!