Skip to main content

Class PushButtonBase

Contains common push button logic

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

Derived:
Meadow.Foundation.Sensors.Buttons.PollingPushButton

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
Declaration
protected bool ShouldDisposeInput { get; set; }

ButtonPressStart

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

View Source
Declaration
protected DateTime ButtonPressStart { get; set; }

DigitalIn

The digital input port used by the button

View Source
Declaration
protected IDigitalInputPort DigitalIn { get; }

LongClickedThreshold

The minimum duration for a long press. Defaults to

View Source
Declaration
public TimeSpan LongClickedThreshold { get; set; }

State

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

View Source
Declaration
public bool State { get; }

Fields

DefaultLongClickThreshold

Default threshold for LongClicked events

View Source
Declaration
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
Declaration
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
Declaration
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
Declaration
protected virtual void RaiseClicked()

RaisePressStarted()

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

View Source
Declaration
protected virtual void RaisePressStarted()

RaisePressEnded()

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

View Source
Declaration
protected virtual void RaisePressEnded()

RaiseLongClicked()

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

View Source
Declaration
protected virtual void RaiseLongClicked()

Read()

Convenience method to get the current sensor reading

View Source
Declaration
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
Declaration
public virtual void Dispose()

Events

PressStarted

Raised when a press starts

View Source
Declaration
public event EventHandler? PressStarted
Event Type

System.EventHandler

PressEnded

Raised when a press ends

View Source
Declaration
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
Declaration
public event EventHandler Clicked
Event Type

System.EventHandler

LongClicked

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

View Source
Declaration
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