dotnet / iot

This repo includes .NET Core implementations for various IoT boards, chips, displays and PCBs.
MIT License
2.12k stars 574 forks source link

FT232H Cannot register for pin value change events #2296

Closed IamRewt closed 3 months ago

IamRewt commented 3 months ago

Describe the bug

When using an FT232H board on windows, attempting to call GpioController.RegisterCallbackForPinValueChangedEvent() results in a 'NotImplementedException'.

The exact message is: "System.NotImplementedException: 'The method or operation is not implemented.'"

Steps to reproduce

 Ft232HDevice ft232h = new(FtCommon.GetDevices()[0]);
 var gpio = ft232h.CreateGpioController();
 var pin = 0;

 gpio.OpenPin(pin);
 gpio.SetPinMode(pin, PinMode.Input);
 gpio.RegisterCallbackForPinValueChangedEvent(pin, PinEventTypes.Rising, HandleRisingEvent); // Exception thrown here.

// the method being registered
  private void HandleRisingEvent(object sender, PinValueChangedEventArgs pinValueChangedEventArgs)
  {
      Console.WriteLine("Sensor changed from Low to High!");
  }

Expected behavior

When using a gpio controller on say a raspberry pi, registering the method in the same way works fine and events are caught.

For example, this code runs fine on a raspberry pi.

var gpio = new GpioController();
gpio.OpenPin(4);
gpio.SetPinMode(4, PinMode.Input);
gpio.RegisterCallbackForPinValueChangedEvent(pin, PinEventTypes.Rising, HandleRisingEvent);

Actual behavior

A Not Implemented exception is thrown.

Versions used .Net Version: 8.0.3 IOT Device Binding Version: 3.1.0. System Device GPIO Version: 3.1.0

Ellerbach commented 3 months ago

Hi, this is the actual correct behavior, this is not implemented. See https://github.com/dotnet/iot/blob/ab3f910a76568d8a0c234aee0227c65705729da8/src/devices/Ft232H/Ft232HGpio.cs#L220

If you want to implement it, you can with your own logic.

krwq commented 3 months ago

[Triage] we're in favor of PRs than bug reports for those kinds of issues - there is no straight forward way to support this natively and we'd need to emulate this behavior