Skip to content

daisy::PotMonitor

Module: LIBDAISY / UI

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

#include <PotMonitor.h>

Public Functions

Name
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
BackendType & GetBackend()
uint16_t GetNumPotsMonitored() const

Detailed Description

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

A potentiometer monitor that generates events in a UiEventQueue.

Template Parameters:

  • BackendType The class type of the backend that will supply pot values.
  • numPots The number of pots to monitor.

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);

Public Functions Documentation

function PotMonitor

inline PotMonitor()

function Init

inline void Init(
    UiEventQueue & queueToAddEventsTo,
    BackendType & backend,
    uint16_t idleTimeoutMs =500,
    float deadBandIdle =1.0/(1<< 10),
    float deadBand =1.0/(1<< 12)
)

Parameters:

  • queueToAddEventsTo The UiEventQueue to which events should be posted.
  • backend The backend that supplies the current value of each potentiometer.
  • idleTimeoutMs When the pot is currently moving, but no event is generated over "idleTimeoutMs", the pot enters the idle state.
  • deadBandIdle The dead band that must be exceeded before a movement is detected when the pot is currently idle.
  • deadBand The dead band that must be exceeded before a movement is detected when the pot is currently moving.

Initialises the PotMonitor.


function Process

inline void Process()

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


function IsMoving

inline bool IsMoving(
    uint16_t potId
) const

Parameters:

  • potId The unique ID of the potentiometer (< numPots)

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


function GetCurrentPotValue

inline float GetCurrentPotValue(
    uint16_t potId
) const

Parameters:

  • potId The unique ID of the potentiometer (< numPots)

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


function GetBackend

inline BackendType & GetBackend()

Returns the BackendType that is used by the monitor.


function GetNumPotsMonitored

inline uint16_t GetNumPotsMonitored() const

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

---

Updated on 2024-01-03 at 19:41:01 +0000