Skip to content

Class daisy::Switch

ClassList > daisy > Switch

More...

  • #include <switch.h>

Public Types

Type Name
enum Polarity
enum Type

Public Functions

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

Detailed Description

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

Author:

Stephen Hensley

Date:

December 2019

Public Types Documentation

enum Polarity

enum daisy::Switch::Polarity {
    POLARITY_NORMAL,
    POLARITY_INVERTED
};

Specifies whether the pressed is HIGH or LOW.


enum Type

enum daisy::Switch::Type {
    TYPE_TOGGLE,
    TYPE_MOMENTARY
};

Specifies the expected behavior of the switch


Public Functions Documentation

function 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.


function FallingEdge

inline bool daisy::Switch::FallingEdge () const

Returns:

true if the button was just released


function Init [½]

void daisy::Switch::Init (
    Pin pin,
    float update_rate,
    Type t,
    Polarity pol,
    GPIO::Pull pu=GPIO::Pull::PULLUP
) 

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

Parameters:

  • pin port/pin object to tell the switch which hardware pin to use.
  • update_rate Does nothing. Backwards compatibility until next breaking update.
  • t switch type Default: TYPE_MOMENTARY
  • pol switch polarity Default: POLARITY_INVERTED
  • pu switch pull up/down Default: PULL_UP

function Init [2/2]

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

Simplified Init.

Parameters:

  • pin port/pin object to tell the switch which hardware pin to use.
  • update_rate Left for backwards compatibility until next breaking change.

function Pressed

inline bool daisy::Switch::Pressed () const

Returns:

true if the button is held down (or if the toggle is on)


function RawState

inline bool daisy::Switch::RawState () 

Returns:

true if the button is held down, without debouncing


function RisingEdge

inline bool daisy::Switch::RisingEdge () const

Returns:

true if a button was just pressed.


function SetUpdateRate

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

Left for backwards compatability until next breaking change

Parameters:

  • update_rate Doesn't do anything

function Switch

inline daisy::Switch::Switch () 

function TimeHeldMs

inline float daisy::Switch::TimeHeldMs () const

Returns:

the time in milliseconds that the button has been held (or toggle has been on)


function ~Switch

inline daisy::Switch::~Switch () 


The documentation for this class was generated from the following file external-docs/libDaisy/src/hid/switch.h