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

PushButton only works with constructor where Device is passed #18

Closed
padesso opened this issue Oct 25, 2019 · 3 comments
Closed

PushButton only works with constructor where Device is passed #18

padesso opened this issue Oct 25, 2019 · 3 comments
Assignees
Milestone

Comments

@padesso
Copy link

padesso commented Oct 25, 2019

Summary
When creating a Meadow.Foundation.Sensors.Buttons.PushButton, the event handlers only fire when the constructor used is where the IIODevice is passed as a parameter.

How To Reproduce
Instantiate a PushButton as follows:
PushButton buttonPort = new PushButton(Device.CreateDigitalInputPort(Device.Pins.D04));

Add event handlers:
buttonPort.PressStarted += ButtonPort_PressStarted;
buttonPort.PressEnded += ButtonPort_PressEnded;

Workaround
To get the event handlers to fire, the alternate constructor override may be used:
PushButton buttonPort = new PushButton(Device, Device.Pins.D04, 100);

Add event handlers:
buttonPort.PressStarted += ButtonPort_PressStarted;
buttonPort.PressEnded += ButtonPort_PressEnded;

@adrianstevens
Copy link

@jorgedevs - this should be an easy fix, let's take a look this week

@bryancostanich
Copy link
Contributor

@ctacke did this get fixed in b3.6 with the other pushbutton fixes?

@ctacke ctacke assigned ctacke and unassigned jorgedevs and adrianstevens Dec 23, 2019
@ctacke
Copy link
Contributor

ctacke commented Dec 29, 2019

The issue here is that the IPort used by the PushButton must have interrupts enabled. If you pass in just an IPin, the PushButton creates the Port for you with interrupts (rising and falling) enabled. I've updated the MF code to throw a meaningful exception if you try wiring up a PushButton event without the appropriate interrupt enabled on the underlying port. This will be in Beta3.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants