libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
daisy::Switch Class Reference

Detailed Description

Generic Class for handling momentary/latching switches
Inspired/influenced by Mutable Instruments (pichenettes) Switch classes

Author
Stephen Hensley
Date
December 2019

#include <switch.h>

Public Types

enum  Type { TYPE_TOGGLE , TYPE_MOMENTARY }
 
enum  Polarity { POLARITY_NORMAL , POLARITY_INVERTED }
 
enum  Pull { PULL_UP , PULL_DOWN , PULL_NONE }
 

Public Member Functions

 Switch ()
 
 ~Switch ()
 
void Init (dsy_gpio_pin pin, float update_rate, Type t, Polarity pol, Pull pu)
 
void Init (dsy_gpio_pin pin, float update_rate=0.f)
 
void Debounce ()
 
bool RisingEdge () const
 
bool FallingEdge () const
 
bool Pressed () const
 
bool RawState ()
 
float TimeHeldMs () const
 
void SetUpdateRate (float update_rate)
 

Member Enumeration Documentation

◆ Polarity

Specifies whether the pressed is HIGH or LOW.

Enumerator
POLARITY_NORMAL 

&

POLARITY_INVERTED 

&

◆ Pull

Specifies whether to use built-in Pull Up/Down resistors to hold button at a given state when not engaged.

Enumerator
PULL_UP 

&

PULL_DOWN 

&

PULL_NONE 

&

◆ Type

Specifies the expected behavior of the switch

Enumerator
TYPE_TOGGLE 

&

TYPE_MOMENTARY 

&

Constructor & Destructor Documentation

◆ Switch()

daisy::Switch::Switch ( )
inline

◆ ~Switch()

daisy::Switch::~Switch ( )
inline

Member Function Documentation

◆ Debounce()

void daisy::Switch::Debounce ( )

Called at update_rate to debounce and handle timing for the switch. In order for events not to be missed, its important that the Edge/Pressed checks be made at the same rate as the debounce function is being called.

◆ FallingEdge()

bool daisy::Switch::FallingEdge ( ) const
inline
Returns
true if the button was just released

◆ Init() [1/2]

void daisy::Switch::Init ( dsy_gpio_pin  pin,
float  update_rate,
Type  t,
Polarity  pol,
Pull  pu 
)

Initializes the switch object with a given port/pin combo.

Parameters
pinport/pin object to tell the switch which hardware pin to use.
update_rateDoes nothing. Backwards compatibility until next breaking update.
tswitch type – Default: TYPE_MOMENTARY
polswitch polarity – Default: POLARITY_INVERTED
puswitch pull up/down – Default: PULL_UP

◆ Init() [2/2]

void daisy::Switch::Init ( dsy_gpio_pin  pin,
float  update_rate = 0.f 
)

Simplified Init.

Parameters
pinport/pin object to tell the switch which hardware pin to use.
update_rateLeft for backwards compatibility until next breaking change.

◆ Pressed()

bool daisy::Switch::Pressed ( ) const
inline
Returns
true if the button is held down (or if the toggle is on)

◆ RawState()

bool daisy::Switch::RawState ( )
inline
Returns
true if the button is held down, without debouncing

◆ RisingEdge()

bool daisy::Switch::RisingEdge ( ) const
inline
Returns
true if a button was just pressed.

◆ SetUpdateRate()

void daisy::Switch::SetUpdateRate ( float  update_rate)
inline

Left for backwards compatability until next breaking change

Parameters
update_rateDoesn't do anything

◆ TimeHeldMs()

float daisy::Switch::TimeHeldMs ( ) const
inline
Returns
the time in milliseconds that the button has been held (or toggle has been on)

The documentation for this class was generated from the following file: