arduino-audio-tools
Loading...
Searching...
No Matches
AudioActions Class Reference

A simple class to assign functions to gpio pins e.g. to implement a simple navigation control or volume control with buttons. More...

#include <AudioActions.h>

Classes

struct  Action
 Action definition per pin. More...

Public Types

enum  ActiveLogic : uint8_t { ActiveLow , ActiveHigh , ActiveChange , ActiveTouch }
 Defines the logic for the action execution. More...

Public Member Functions

 AudioActions (bool useInterrupt=false)
 Default constructor.
virtual ~AudioActions ()
 deletes all actions
void add (Action &action)
 Adds an Action.
void add (digital_pin_t pin, void(*actionOn)(bool pinStatus, digital_pin_t pin, void *ref), ActiveLogic activeLogic=ActiveLow, void *ref=nullptr)
 Adds an action.
void add (digital_pin_t pin, void(*actionOn)(bool pinStatus, digital_pin_t pin, void *ref), void(*actionOff)(bool pinStatus, digital_pin_t pin, void *ref), ActiveLogic activeLogicPar=ActiveLow, void *ref=nullptr)
 Adds an action.
void clear ()
Action * findActionById (int id)
 Determines the action for the pin/id.
Action * findActionByPin (digital_pin_t pin)
int findActionIdx (int id)
 Determines the action for the pin/id.
void processActions ()
 Execute all actions if the corresponding pin is low. To minimize the runtime: With each call we process a different pin. When interrupts are enabled, all actions are processed when a pin change is detected.
void processAllActions ()
 Execute all actions.
void setDebounceDelay (int value)
 Defines the debounce delay.
void setEnabled (digital_pin_t pin, bool enabled)
 enable/disable pin actions
void setPinMode (bool active)
 setup pin mode when true
void setReadCallback (bool(*read_cb_par)(digital_pin_t, void *), void *ref=nullptr)
 Sets a callback function to read the pin state.
void setTouchLimit (int value)
 Defines the touch limit (Default 20).
void setUsePinInterrupt (bool active)
 Use interrupts instead of processActions() call in loop.

Protected Member Functions

void insertAction (Action *p)
void setupInterrupt (digital_pin_t pin)
void setupISR (digital_pin_t button)
 Setup GPIO interrupt for a given pin.
void setupPin (digital_pin_t pin, ActiveLogic logic)

Static Protected Member Functions

static void audioActionsISRZephyr (const struct device *dev, struct gpio_callback *cb, uint32_t pins)
static AudioActions *& selfAudioActions ()

Protected Attributes

Vector< Action * > actions {0}
int debounceDelayValue = 500
volatile bool interrupt_pending = false
bool(* read_cb )(digital_pin_t, void *) = nullptr
void * read_cb_ref = nullptr
int touchLimit = 20
bool use_pin_interrupt = false
bool use_pin_mode = true

Static Protected Attributes

static struct gpio_callback button_cb_data

Detailed Description

A simple class to assign functions to gpio pins e.g. to implement a simple navigation control or volume control with buttons.

Member Enumeration Documentation

◆ ActiveLogic

enum ActiveLogic : uint8_t

Defines the logic for the action execution.

Enumerator
ActiveLow 
ActiveHigh 
ActiveChange 
ActiveTouch 

Constructor & Destructor Documentation

◆ AudioActions()

AudioActions ( bool useInterrupt = false)
inline

Default constructor.

◆ ~AudioActions()

virtual ~AudioActions ( )
inlinevirtual

deletes all actions

Member Function Documentation

◆ add() [1/3]

void add ( Action & action)
inline

Adds an Action.

◆ add() [2/3]

void add ( digital_pin_t pin,
void(* actionOn )(bool pinStatus, digital_pin_t pin, void *ref),
ActiveLogic activeLogic = ActiveLow,
void * ref = nullptr )
inline

Adds an action.

◆ add() [3/3]

void add ( digital_pin_t pin,
void(* actionOn )(bool pinStatus, digital_pin_t pin, void *ref),
void(* actionOff )(bool pinStatus, digital_pin_t pin, void *ref),
ActiveLogic activeLogicPar = ActiveLow,
void * ref = nullptr )
inline

Adds an action.

◆ audioActionsISRZephyr()

void audioActionsISRZephyr ( const struct device * dev,
struct gpio_callback * cb,
uint32_t pins )
inlinestaticprotected

◆ clear()

void clear ( )
inline

◆ findActionById()

Action * findActionById ( int id)
inline

Determines the action for the pin/id.

◆ findActionByPin()

Action * findActionByPin ( digital_pin_t pin)
inline

◆ findActionIdx()

int findActionIdx ( int id)
inline

Determines the action for the pin/id.

◆ insertAction()

void insertAction ( Action * p)
inlineprotected

◆ processActions()

void processActions ( )
inline

Execute all actions if the corresponding pin is low. To minimize the runtime: With each call we process a different pin. When interrupts are enabled, all actions are processed when a pin change is detected.

◆ processAllActions()

void processAllActions ( )
inline

Execute all actions.

◆ selfAudioActions()

AudioActions *& selfAudioActions ( )
inlinestaticprotected

◆ setDebounceDelay()

void setDebounceDelay ( int value)
inline

Defines the debounce delay.

◆ setEnabled()

void setEnabled ( digital_pin_t pin,
bool enabled )
inline

enable/disable pin actions

◆ setPinMode()

void setPinMode ( bool active)
inline

setup pin mode when true

◆ setReadCallback()

void setReadCallback ( bool(* read_cb_par )(digital_pin_t, void *),
void * ref = nullptr )
inline

Sets a callback function to read the pin state.

◆ setTouchLimit()

void setTouchLimit ( int value)
inline

Defines the touch limit (Default 20).

◆ setupInterrupt()

void setupInterrupt ( digital_pin_t pin)
inlineprotected

◆ setupISR()

void setupISR ( digital_pin_t button)
inlineprotected

Setup GPIO interrupt for a given pin.

◆ setupPin()

void setupPin ( digital_pin_t pin,
ActiveLogic logic )
inlineprotected

◆ setUsePinInterrupt()

void setUsePinInterrupt ( bool active)
inline

Use interrupts instead of processActions() call in loop.

Member Data Documentation

◆ actions

Vector<Action*> actions {0}
protected

◆ button_cb_data

struct gpio_callback button_cb_data
staticprotected

◆ debounceDelayValue

int debounceDelayValue = 500
protected

◆ interrupt_pending

volatile bool interrupt_pending = false
protected

◆ read_cb

bool(* read_cb) (digital_pin_t, void *) = nullptr
protected

◆ read_cb_ref

void* read_cb_ref = nullptr
protected

◆ touchLimit

int touchLimit = 20
protected

◆ use_pin_interrupt

bool use_pin_interrupt = false
protected

◆ use_pin_mode

bool use_pin_mode = true
protected

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