-
Notifications
You must be signed in to change notification settings - Fork 585
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
Button with external resistor bug as for #2012 #2013
Conversation
…tors and continue detecting correctly the gpio transitions in the events
…tors and continue detecting correctly the gpio transitions in the events
…to button_resistor
After a rebase, this PR got all the doc changes that has already been merged in main. Don't know why. |
…now true. This PR introduces a source breaking-change as discussed and approved in the Triage.
Since this PR introduce a source and binary breaking change (the old two ctors were replaced with different parameters), I tried to run the command Anyway the command failed with the following output:
Apart the compatibility suppression xml file not being generated, the rest of the PR is good and ready for review/approval. |
@pgrawehr I had to change the ctor call in Arduino.Monitor.cs. |
@joperezr I see helix failing with this error. Is there anything I can do?
|
Those are the hardware tests. Given their nature and what they test, they tend to be flaky sometimes. Usually we just re-run to make sure it was just a fluke. In this case we can be pretty sure about it since your PR isn't really touching S.D.G and the other Linux Debug build (which also runs the tests) passed. |
Thanks, but recently I got merge permissions, but not the azp ones :-) |
The button is pulled down with an external resistor in the example. See src\devices\Arduino\ArduinoSample_Monitor.png for the schematic of the example. |
@pgrawehr |
@pgrawehr do you have any idea why the |
Yea, that particular test is flaky. I'll check a bunch of the latest builds and disable it if it's really always the same. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PullUp/PullDown are not supported everywhere. So you can't create them just like this. You have to test and then keep the chosen mode to compare later on.
_debounceTime = debounceTime; | ||
HasExternalResistor = hasExternalResistor; | ||
|
||
_eventPinMode = isPullUp ? PinMode.InputPullUp : PinMode.InputPullDown; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is dangerous! Because some board do not support PullUp/PullDown. It's the reason why originally you have to pass the pull type.
If you want to do something like this, you need first to check if the pin mode is supported, if not, then choose one that is a default one.
See here for the good way to do it: https://github.com/dotnet/iot/blob/main/src/devices/Dhtxx/DhtBase.cs#L192
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ellerbach I am aware that not every pin can be internally pulled up or down.
I didn't change the logic of the original author, I just added support for the external pullup/down resistor.
I was not aware of IsPinModeSupported
in GpioController
. Good to know, Now I can throw an exception if it's not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I revised two cases:
- if the button can be configured as input (certain gpio can only be output)
- if the button can be configured with the configuration deriving from
isPullUp
andHasExternalResistor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine. If the mode is not supported, it will throw, which is expected, because it's an user error.
@@ -75,7 +101,7 @@ private void PinStateChanged(object sender, PinValueChangedEventArgs pinValueCha | |||
switch (pinValueChangedEventArgs.ChangeType) | |||
{ | |||
case PinEventTypes.Falling: | |||
if (_pinMode == PinMode.InputPullUp) | |||
if (_eventPinMode == PinMode.InputPullUp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, you can't really do it like this is pull up is not supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _eventPinMode
is always good because it is used to keep track if it is either pulled-up internally or externally.
The validation only goes when I open the pin. But if the resistor is external, the raising/falling logic is basically the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make this more clear: _eventPinMode
is not used in OpenPin
.
I just 'reused" the enumeration to keep track whether the button transition is high to low or vice-versa.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the tweaks, looks good to me now.
Could you please you merge it? |
This PR implements solution 1 and 3 proposed in #2012
I ask the reviewers whether they prefer:
In case of option 3, please tell me whether you prefer to:
Microsoft Reviewers: Open in CodeFlow