25#include "MovingAverage.h"
33 DEBOUNCE_PROMPT_DETECT
37#define EXTERNAL_PULLDOWN DIRECT
38#define EXTERNAL_PULLUP INVERTED
39#define ANALOG_DEFAULT DIRECT
40#define ANALOG_INVERTED INVERTED
48 virtual void smooth(
float smoothTime=PLAQUETTE_DEFAULT_SMOOTH_WINDOW) {
timeWindow(smoothTime); }
67 virtual float _read() = 0;
70 virtual float _sampleRate()
const = 0;
73 virtual void _begin();
79 virtual float _smoothed() {
return _avg.
get(); }
91 virtual void debounce(
float debounceTime=PLAQUETTE_DEFAULT_DEBOUNCE_WINDOW) {
timeWindow(debounceTime); }
97 virtual void smooth(
float smoothTime=PLAQUETTE_DEFAULT_DEBOUNCE_WINDOW) {
debounce(smoothTime); }
103 virtual void timeWindow(
float seconds) { _interval = seconds; }
119 virtual bool _isOn() = 0;
122 virtual float _time()
const = 0;
125 virtual void _begin();
128 virtual void _step();
131 virtual bool _debounced();
133 inline void _changeState();
134 inline void _setStateFlag(
const uint8_t flag) { _state |= flag; }
135 inline void _unsetStateFlag(
const uint8_t flag) { _state &= ~flag; }
136 inline void _toggleStateFlag(
const uint8_t flag) { _state ^= flag; }
137 inline bool _getStateFlag(
const uint8_t flag) {
return((_state & flag) != 0); }
143 uint8_t _debounceMode;
159 virtual float get() {
return _smoothed(); }
162 virtual float mapTo(
float toLow,
float toHigh);
171 virtual void begin();
174 virtual float _read();
175 virtual float _sampleRate()
const {
return sampleRate(); }
200 virtual bool _isOn();
201 virtual float _time()
const {
return seconds(); }
203 virtual void _init();
205 virtual void begin();
A generic class representing a simple analog input.
Definition PqInputs.h:147
virtual float mapTo(float toLow, float toHigh)
Maps value to new range.
Definition PqInputs.cpp:148
virtual float get()
Returns value in [0, 1].
Definition PqInputs.h:159
int rawRead() const
Directly reads raw value from the pin (bypasses mode, smoothing, and engine).
Definition PqInputs.cpp:156
float read() const
Direcly reads value from the pin (bypasses mode, smoothing, and engine).
Definition PqInputs.cpp:152
Superclass for components that can be debounced.
Definition PqInputs.h:86
virtual void smooth(float smoothTime=PLAQUETTE_DEFAULT_DEBOUNCE_WINDOW)
Deprecated. Left for backwards compatibility.
Definition PqInputs.h:97
float timeWindow() const
Returns the debouncing window (expressed in seconds).
Definition PqInputs.h:106
void debounceMode(uint8_t mode)
Sets debounce mode.
Definition PqInputs.h:115
virtual void noDebounce()
Remove smoothing.
Definition PqInputs.h:94
virtual void noSmooth()
Remove smoothing.
Definition PqInputs.h:100
virtual void timeWindow(float seconds)
Changes the debouncing window (expressed in seconds).
Definition PqInputs.h:103
virtual void debounce(float debounceTime=PLAQUETTE_DEFAULT_DEBOUNCE_WINDOW)
Apply smoothing to object.
Definition PqInputs.h:91
uint8_t debounceMode() const
Returns the debounce mode.
Definition PqInputs.h:109
A generic class representing a simple digital input.
Definition PqInputs.h:179
float read() const
Directly reads value from the pin as 1 or 0 (bypasses mode, debounce, and engine).
Definition PqInputs.cpp:182
int rawRead() const
Directly reads raw value from the pin as HIGH or LOW (bypasses mode, debounce, and engine).
Definition PqInputs.cpp:186
A digital source that contains a true/false value.
Definition PqCore.h:462
The main Plaquette static class containing all the units.
Definition PqCore.h:60
static Engine & primary()
Returns the main instance of Plaquette.
Definition PqCore.cpp:31
float get()
Returns the value of the moving average. This is undefined if isValid() == false.
Definition MovingAverage.h:73
void timeWindow(float seconds)
Changes the smoothing window (expressed in seconds).
Definition MovingAverage.cpp:48
void cutoff(float hz)
Changes the smoothing window cutoff frequency (expressed in Hz).
Definition MovingAverage.cpp:52
Superclass for pin-based components.
Definition PqCore.h:647
uint8_t pin() const
Returns the pin this component is attached to.
Definition PqCore.h:653
uint8_t mode() const
Returns the mode of the component.
Definition PqCore.h:656
Superclass for components that can be smoothed.
Definition PqInputs.h:43
virtual void smooth(float smoothTime=PLAQUETTE_DEFAULT_SMOOTH_WINDOW)
Apply smoothing to object.
Definition PqInputs.h:48
virtual void timeWindow(float seconds)
Changes the smoothing window (expressed in seconds).
Definition PqInputs.h:54
virtual void noSmooth()
Remove smoothing.
Definition PqInputs.h:51
virtual void cutoff(float hz)
Changes the smoothing window cutoff frequency (expressed in Hz).
Definition PqInputs.h:60
float cutoff() const
Returns the smoothing window cutoff frequency (expressed in Hz).
Definition PqInputs.h:63
float timeWindow() const
Returns the smoothing window (expressed in seconds).
Definition PqInputs.h:57
A generic class representing a unit in the system.
Definition PqCore.h:335
float seconds() const
Returns engine time in seconds.
Definition PqCore.h:348
Engine * engine() const
Returns the engine that owns this unit.
Definition PqCore.h:382
float sampleRate() const
Returns engine sample rate.
Definition PqCore.h:360