libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
daisy::PotMonitor< BackendType, numPots > Class Template Reference

A potentiometer monitor that generates events in a UiEventQueue. More...

Detailed Description

template<typename BackendType, uint32_t numPots>
class daisy::PotMonitor< BackendType, numPots >

A potentiometer monitor that generates events in a UiEventQueue.

Author
jelliesen

This class monitors a number of potentiometers and detects pot movements. When a movement is detected, an event is added to a UiEventQueue. Pots can be either "idle" or "moving" in which case different dead bands are applied to them. The current state and value of a pot can be requested at any time.

This class can monitor an arbitrary number of potentiometers, as configured by its template argument numPots. Each of the pots is identified by an ID number from 0 .. numPots - 1. This number will also be used when events are posted to the UiEventQueue. It's suggested to define an enum in your project like this:

enum PotId { potA = 0, potB = 1, potC = 2 };

In different projects, diffent ways of reading the potentiometer positions will be used. That's why this class uses a generic backend that you'll have to write. The BackendType class will provide the source data for each potentiometer. An instance of this backend must be supplied via the constructor. It must implement the following public function via which the PotMonitor will request the current value of the potentiometer in the range 0 .. 1:

float GetPotValue(uint16_t potId);
Template Parameters
BackendTypeThe class type of the backend that will supply pot values.
numPotsThe number of pots to monitor.

#include <PotMonitor.h>

Public Member Functions

 PotMonitor ()
 
void Init (UiEventQueue &queueToAddEventsTo, BackendType &backend, uint16_t idleTimeoutMs=500, float deadBandIdle=1.0/(1<< 10), float deadBand=1.0/(1<< 12))
 
void Process ()
 
bool IsMoving (uint16_t potId) const
 
float GetCurrentPotValue (uint16_t potId) const
 
BackendTypeGetBackend ()
 
uint16_t GetNumPotsMonitored () const
 

Constructor & Destructor Documentation

◆ PotMonitor()

template<typename BackendType , uint32_t numPots>
daisy::PotMonitor< BackendType, numPots >::PotMonitor ( )
inline

Member Function Documentation

◆ GetBackend()

template<typename BackendType , uint32_t numPots>
BackendType & daisy::PotMonitor< BackendType, numPots >::GetBackend ( )
inline

Returns the BackendType that is used by the monitor.

◆ GetCurrentPotValue()

template<typename BackendType , uint32_t numPots>
float daisy::PotMonitor< BackendType, numPots >::GetCurrentPotValue ( uint16_t  potId) const
inline

For a given potentiometer, this will return the last value that was posted to the UiEventQueue.

Parameters
potIdThe unique ID of the potentiometer (< numPots)

◆ GetNumPotsMonitored()

template<typename BackendType , uint32_t numPots>
uint16_t daisy::PotMonitor< BackendType, numPots >::GetNumPotsMonitored ( ) const
inline

Returns the number of pots that are monitored by this class.

◆ Init()

template<typename BackendType , uint32_t numPots>
void daisy::PotMonitor< BackendType, numPots >::Init ( UiEventQueue queueToAddEventsTo,
BackendType backend,
uint16_t  idleTimeoutMs = 500,
float  deadBandIdle = 1.0 / (1 << 10),
float  deadBand = 1.0 / (1 << 12) 
)
inline

Initialises the PotMonitor.

Parameters
queueToAddEventsToThe UiEventQueue to which events should be posted.
backendThe backend that supplies the current value of each potentiometer.
idleTimeoutMsWhen the pot is currently moving, but no event is generated over "idleTimeoutMs", the pot enters the idle state.
deadBandIdleThe dead band that must be exceeded before a movement is detected when the pot is currently idle.
deadBandThe dead band that must be exceeded before a movement is detected when the pot is currently moving.

◆ IsMoving()

template<typename BackendType , uint32_t numPots>
bool daisy::PotMonitor< BackendType, numPots >::IsMoving ( uint16_t  potId) const
inline

Returns true, if the requested pot is currently being moved.

Parameters
potIdThe unique ID of the potentiometer (< numPots)

◆ Process()

template<typename BackendType , uint32_t numPots>
void daisy::PotMonitor< BackendType, numPots >::Process ( )
inline

Checks the value of each pot and generates messages for the UIEventQueue. Call this at regular intervals, ideally from your main() idle loop.


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