A potentiometer monitor that generates events in a UiEventQueue. More...
A potentiometer monitor that generates events in a UiEventQueue.
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);
BackendType | The class type of the backend that will supply pot values. |
numPots | The 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 |
BackendType & | GetBackend () |
uint16_t | GetNumPotsMonitored () const |
|
inline |
|
inline |
Returns the BackendType that is used by the monitor.
|
inline |
For a given potentiometer, this will return the last value that was posted to the UiEventQueue.
potId | The unique ID of the potentiometer (< numPots) |
|
inline |
Returns the number of pots that are monitored by this class.
|
inline |
Initialises the PotMonitor.
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. |
|
inline |
Returns true, if the requested pot is currently being moved.
potId | The unique ID of the potentiometer (< numPots) |
|
inline |
Checks the value of each pot and generates messages for the UIEventQueue. Call this at regular intervals, ideally from your main() idle loop.