Skip to main content

Class PushButtonBase

Contains common push button logic

Assembly: Meadow.Foundation.dll
View Source
public abstract class PushButtonBase : IButton, ISensor<bool>, ISensor, IDisposable

Derived:
Meadow.Foundation.Sensors.Buttons.PollingPushButton, Meadow.Foundation.Sensors.Buttons.PushButton

Implements:
Meadow.Peripherals.Sensors.Buttons.IButton, Meadow.Peripherals.Sensors.ISensor<System.Boolean>, Meadow.Peripherals.Sensors.ISensor, System.IDisposable

Properties

ShouldDisposeInput

Track if we created the input port in the PushButton instance (true) or was it passed in via the ctor (false)

View Source
protected bool ShouldDisposeInput { get; set; }

ButtonPressStart

The date/time when the last button press occurred and the button hasn't been released

View Source
protected DateTime ButtonPressStart { get; set; }

DigitalIn

The digital input port used by the button

View Source
protected IDigitalInputPort DigitalIn { get; }

LongClickedThreshold

The minimum duration for a long press. Defaults to

View Source
public TimeSpan LongClickedThreshold { get; set; }

State

Returns the sanitized state of the button If pressed, return true, otherwise false

View Source
public bool State { get; }

Fields

DefaultLongClickThreshold

Default threshold for LongClicked events

View Source
public static readonly TimeSpan DefaultLongClickThreshold

Methods

GetNormalizedState(bool)

Returns the sanitized state of the button Inverts the state when using a pull-up resistor

View Source
protected bool GetNormalizedState(bool state)
Returns

System.Boolean

Parameters
TypeName
System.Booleanstate

UpdateEvents(bool)

Raises the proper button events based on current and previous states

View Source
protected void UpdateEvents(bool state)
Parameters
TypeName
System.Booleanstate

RaiseClicked()

Raised when the button circuit is re-opened after it has been closed (at the end of a �press�).

View Source
protected virtual void RaiseClicked()

RaisePressStarted()

Raised when a press starts (the button is pushed down; circuit is closed).

View Source
protected virtual void RaisePressStarted()

RaisePressEnded()

Raised when a press ends (the button is released; circuit is opened).

View Source
protected virtual void RaisePressEnded()

RaiseLongClicked()

Raised when the button circuit is pressed for at least 500ms.

View Source
protected virtual void RaiseLongClicked()

Read()

Convenience method to get the current sensor reading

View Source
public Task<bool> Read()
Returns

System.Threading.Tasks.Task<System.Boolean>

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

View Source
public virtual void Dispose()

Events

PressStarted

Raised when a press starts

View Source
public event EventHandler PressStarted
Event Type

System.EventHandler

PressEnded

Raised when a press ends

View Source
public event EventHandler PressEnded
Event Type

System.EventHandler

Clicked

Raised when the button is released after being pressed (for shorter than LongClickedThreshold, if set)

View Source
public event EventHandler Clicked
Event Type

System.EventHandler

LongClicked

Raised when the button is released after being pressed for longer than LongClickedThreshold

View Source
public event EventHandler LongClicked
Event Type

System.EventHandler

Implements

  • Meadow.Peripherals.Sensors.Buttons.IButton
  • Meadow.Peripherals.Sensors.ISensor<System.Boolean>
  • Meadow.Peripherals.Sensors.ISensor
  • System.IDisposable