Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GrovePi binding timing issue when read sensors #2359

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

2427dkusiro
Copy link

@2427dkusiro 2427dkusiro commented Oct 23, 2024

Fixes #2337

Summary

Fix timing issue in the GrovePi Binding logic for sensor reading.

Detail

As mentioned in the issue I raised, there is a bug in the current GrovePi Binding that prevents it from correctly reading sensor values on the Raspberry Pi 4. To fix this bug, I have modified the code to wait and retry when an invalid response is received from the device. Additionally, I've standardized the implementation of the DigitalRead method with other sensor readings so that it can also benefit from this bug fix.

Validation

I have confirmed that the changes in this PR work as intended by testing with sample code from the GrovePi directory. I connected a button, potentiometer, relay, ultrasonic distance sensor, and temperature & humidity sensor to both Raspberry Pi 3 and 4.

IMG_20241023_163606

Microsoft Reviewers: Open in CodeFlow

@2427dkusiro 2427dkusiro changed the title Fix GrovePi binding timing issue in Fix GrovePi binding timing issue when read sensors Oct 23, 2024
@dotnet-policy-service dotnet-policy-service bot added the area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio label Oct 23, 2024
@2427dkusiro
Copy link
Author

@dotnet-policy-service agree


throw new IOException($"{nameof(DigitalRead)}: Failed to read byte with command {GrovePiCommand.DigitalRead}", innerEx);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you removing the throw here and replace with the -1 logic? Throwing is a good way to say that things did not work properly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ellerbach
I initially considered making this change because the existing AnalogRead method was designed to return -1 instead of throwing an exception. However, I have adjusted the behavior at commit 93c6303 accordingly.

@Ellerbach
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GrovePi device binding fails to read sensor values
2 participants