After unregister all callbacks, the new registered callbacks events are not fired in Raspberry Pi 4
See original GitHub issueDescribe the bug
In GpioController, when you register some callbacks with RegisterCallbackForPinValueChangedEvent() function, the events are fired as expected. Then, If you unregister all the callbacks registered before with UnregisterCallbackForPinValueChangedEvent() function, your events are not fired now. (This is the expected behaviour). Now, if you registered new callbacks in GpioController with RegisterCallbackForPinValueChangedEvent() function, the new events are not fired. No matter how many times you unregister and register callbacks, the events will never be fired again.
Steps to reproduce
- Create new GpioController
- Open one pin as input / InputPullUp / InputPullDown
- Register some callbacks with RegisterCallbackForPinValueChangedEvent() function.
- Unregister all of them with UnregisterCallbackForPinValueChangedEvent() function.
- Register again some callbacks.
class Program
{
static void Main(string[] args)
{
int pin = 12;
PinMode pinMode = PinMode.InputPullUp;
using GpioController controller = new();
for(int i = 0; i < 3; i++)
{
Console.WriteLine($"Iteration: {i+1}");
OpenAndRegisterPin(controller, pin, pinMode);
Console.WriteLine($"Try pin:{pin} events in 30 seconds.");
Task.Delay(30000).Wait();
CloseAndUnregisterPin(controller, pin);
}
}
protected static void OpenAndRegisterPin(GpioController controller, int pin, PinMode pinMode)
{
Console.WriteLine($"Opening Pin: {pin}");
controller.OpenPin(pin, pinMode);
Console.WriteLine($"Registering pin events.");
controller.RegisterCallbackForPinValueChangedEvent(pin, PinEventTypes.Falling, OnFalling);
controller.RegisterCallbackForPinValueChangedEvent(pin, PinEventTypes.Rising, OnRising);
}
protected static void CloseAndUnregisterPin(GpioController controller, int pin)
{
Console.WriteLine($"Unregistering pin events.");
controller.UnregisterCallbackForPinValueChangedEvent(pin, OnFalling);
controller.UnregisterCallbackForPinValueChangedEvent(pin, OnRising);
Console.WriteLine($"Closing Pin: {pin}");
controller.ClosePin(pin);
}
protected static void OnFalling(object sender, PinValueChangedEventArgs ev)
{
Console.WriteLine($"OnFalling Pin:{ev.PinNumber}");
}
protected static void OnRising(object sender, PinValueChangedEventArgs ev)
{
Console.WriteLine($"OnRising Pin:{ev.PinNumber}");
}
}
Expected behavior
In all iterations, the console must show OnFallling and/or OnRising messages with the Pin:12. For example:
Iteration: 1
Opening Pin: 12
Registering pin events.
Try pin:12 events in 30 seconds.
OnFalling Pin:12
OnRising Pin:12
Unregistering pin events.
Closing Pin: 12
Iteration: 2
Opening Pin: 12
Registering pin events.
Try pin:12 events in 30 seconds.
OnFalling Pin:12
OnRising Pin:12
Unregistering pin events.
Closing Pin: 12
Iteration: 3
Opening Pin: 12
Registering pin events.
Try pin:12 events in 30 seconds.
OnFalling Pin:12
OnRising Pin:12
Unregistering pin events.
Closing Pin: 12
Actual behavior
Only in the iteration 1 (i == 0) the event messages are showed. In the next iterations, this doesn’t happened. For example:
Iteration: 1
Opening Pin: 12
Registering pin events.
Try pin:12 events in 30 seconds.
OnFalling Pin:12
OnRising Pin:12
Unregistering pin events.
Closing Pin: 12
Iteration: 2
Opening Pin: 12
Registering pin events.
Try pin:12 events in 30 seconds.
Unregistering pin events.
Closing Pin: 12
Iteration: 3
Opening Pin: 12
Registering pin events.
Try pin:12 events in 30 seconds.
Unregistering pin events.
Closing Pin: 12
Versions used
Checked In Raspberry Pi 4 Model B with Raspberry Pi OS
dotnet --info
on the machine being used to build
SDK de .NET (que refleje cualquier global.json):
Version: 5.0.400
Commit: d61950f9bf
dotnet --info
on the machine where app is being run (not applicable for self-contained apps)
SDK de .NET (que refleje cualquier global.json):
Version: 5.0.400
Commit: d61950f9bf
Also checked with:
SDK de .NET Core (reflejando cualquier global.json):
Version: 3.1.411
Commit: d100cdf718
- Version of
System.Device.Gpio
package
1.5.0
Also checked with:
1.3.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (16 by maintainers)
Top GitHub Comments
Well done, great work. I am personally ok with that. Just have a bit of patience so that others may find some time to review the PR.
Don’t worry, @raffaeler. My apologies, I didn’t see that Readme before.
Thank you so much! I finally can run the tests.
Now I’m trying to create the test and check it out.
Should I put it in SysFsDriverTests.cs file for only the SysFsDriver driver or in GpioControllerTestBase.cs file for all the drivers?