#include <AH/Hardware/FilteredAnalog.hpp>
FilteredAnalog base class with generic MappingFunction.
Definition at line 39 of file FilteredAnalog.hpp.
Public Member Functions | |
GenericFilteredAnalog (pin_t analogPin, MappingFunction mapFn, AnalogType initial=0) | |
Construct a new GenericFilteredAnalog object. More... | |
void | reset (AnalogType value=0) |
Reset the filter to the given value. More... | |
void | resetToCurrentValue () |
Reset the filtered value to the value that's currently being measured at the analog input. More... | |
void | map (MappingFunction fn) |
Specify a mapping function/functor that is applied to the analog value after filtering and before applying hysteresis. More... | |
MappingFunction & | getMappingFunction () |
Get a reference to the mapping function. More... | |
const MappingFunction & | getMappingFunction () const |
Get a reference to the mapping function. More... | |
bool | update () |
Read the analog input value, apply the mapping function, and update the average. More... | |
AnalogType | getValue () const |
Get the filtered value of the analog input (with the mapping function applied). More... | |
float | getFloatValue () const |
Get the filtered value of the analog input with the mapping function applied as a floating point number from 0.0 to 1.0. More... | |
AnalogType | getRawValue () const |
Read the raw value of the analog input without any filtering or mapping applied, but with its bit depth increased by IncRes . More... | |
Static Public Member Functions | |
static constexpr AnalogType | getMaxRawValue () |
Get the maximum value that can be returned from getRawValue. More... | |
static void | setupADC () |
Select the configured ADC resolution. More... | |
Private Types | |
using | EMA_t = EMA< FilterShiftFactor, AnalogType, FilterType > |
Private Member Functions | |
template<typename M = MappingFunction> | |
std::enable_if< std::is_constructible< bool, M >::value, AnalogType >::type | mapFnHelper (AnalogType input) |
Helper function that applies the mapping function if it's enabled. More... | |
template<typename M = MappingFunction> | |
std::enable_if<!std::is_constructible< bool, M >::value, AnalogType >::type | mapFnHelper (AnalogType input) |
Helper function that applies the mapping function without checking if it's enabled. More... | |
Private Attributes | |
pin_t | analogPin |
MappingFunction | mapFn |
EMA_t | filter |
Hysteresis< ADC_BITS+IncRes - Precision, AnalogType, AnalogType > | hysteresis |
Definition at line 211 of file FilteredAnalog.hpp.
|
inline |
Construct a new GenericFilteredAnalog object.
analogPin | The analog pin to read from. |
mapFn | The mapping function |
initial | The initial value of the filter. |
Definition at line 51 of file FilteredAnalog.hpp.
|
inline |
Reset the filter to the given value.
value | The value to reset the filter state to. |
Definition at line 66 of file FilteredAnalog.hpp.
|
inline |
Reset the filtered value to the value that's currently being measured at the analog input.
This is useful to avoid transient effects upon initialization.
Definition at line 79 of file FilteredAnalog.hpp.
|
inline |
Specify a mapping function/functor that is applied to the analog value after filtering and before applying hysteresis.
fn | This functor should have a call operator that takes the filtered value (of ADC_BITS + IncRes bits wide) as a parameter, and returns a value of ADC_BITS + IncRes bits wide. |
Definition at line 101 of file FilteredAnalog.hpp.
|
inline |
Get a reference to the mapping function.
Definition at line 106 of file FilteredAnalog.hpp.
|
inline |
Get a reference to the mapping function.
Definition at line 110 of file FilteredAnalog.hpp.
|
inline |
Read the analog input value, apply the mapping function, and update the average.
true | The value changed since last time it was updated. |
false | The value is still the same. |
Definition at line 121 of file FilteredAnalog.hpp.
|
inline |
Get the filtered value of the analog input (with the mapping function applied).
Precision
bits wide. Definition at line 139 of file FilteredAnalog.hpp.
|
inline |
Get the filtered value of the analog input with the mapping function applied as a floating point number from 0.0 to 1.0.
Definition at line 148 of file FilteredAnalog.hpp.
|
inline |
Read the raw value of the analog input without any filtering or mapping applied, but with its bit depth increased by IncRes
.
Definition at line 156 of file FilteredAnalog.hpp.
|
inlinestaticconstexpr |
Get the maximum value that can be returned from getRawValue.
Definition at line 168 of file FilteredAnalog.hpp.
|
inlinestatic |
Select the configured ADC resolution.
By default, it is set to the maximum resolution supported by the hardware.
Definition at line 179 of file FilteredAnalog.hpp.
|
inlineprivate |
Helper function that applies the mapping function if it's enabled.
This function is only enabled if MappingFunction is explicitly convertible to bool.
Definition at line 192 of file FilteredAnalog.hpp.
|
inlineprivate |
Helper function that applies the mapping function without checking if it's enabled.
This function is only enabled if MappingFunction is not convertible to bool.
Definition at line 203 of file FilteredAnalog.hpp.
|
private |
Definition at line 208 of file FilteredAnalog.hpp.
|
private |
Definition at line 209 of file FilteredAnalog.hpp.
|
private |
Definition at line 225 of file FilteredAnalog.hpp.
|
private |
Definition at line 227 of file FilteredAnalog.hpp.