MIDI Control Surface library for Arduino
|
Go to the documentation of this file.
6 #include <AH/Filters/EMA.hpp>
49 template <uint8_t Precision = 10,
53 min(
sizeof(FilterType) * CHAR_BIT -
ADC_BITS - FilterShiftFactor,
54 sizeof(AnalogType) * CHAR_BIT -
ADC_BITS)>
96 constexpr AnalogType maxval = (1UL << (
ADC_BITS + IncRes)) - 1;
97 map([](AnalogType val) -> AnalogType {
return maxval - val; });
110 AnalogType input = getRawValue();
111 input = filter.filter(input);
113 input = mapFn(input);
114 return hysteresis.update(input);
128 AnalogType
getValue()
const {
return hysteresis.getValue(); }
138 return getValue() * (1.0f / (ldexpf(1.0f, Precision) - 1.0f));
158 #if HAS_ANALOG_READ_RESOLUTION
169 ADC_BITS + IncRes + FilterShiftFactor <=
sizeof(FilterType) * CHAR_BIT,
170 "Error: FilterType is not wide enough to hold the maximum value");
172 ADC_BITS + IncRes <=
sizeof(AnalogType) * CHAR_BIT,
173 "Error: AnalogType is not wide enough to hold the maximum value");
176 "Error: Precision is larger than the increased ADC precision");
void map(MappingFunction fn)
Specify a mapping function that is applied to the raw analog value before filtering.
AnalogType getValue() const
Get the filtered value of the analog input (with the mapping function applied).
AnalogType getRawValue() const
Read the raw value of the analog input any filtering or mapping applied, but with its bit depth incre...
EMA< FilterShiftFactor, FilterType > filter
T_out increaseBitDepth(T_in in)
Increase the bit depth of the given value from Bits_in bits wide to Bits_out bits wide,...
Hysteresis< ADC_BITS+IncRes - Precision, AnalogType, AnalogType > hysteresis
analog_t(*)(analog_t) MappingFunction
A function pointer to a mapping function to map analog values.
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
constexpr uint8_t ANALOG_FILTER_SHIFT_FACTOR
The factor for the analog filter: Difference equation: where .
constexpr auto min(const T &a, const U &b) -> decltype(b< a ? b :a)
Return the smaller of two numbers/objects.
#define AH_DIAGNOSTIC_POP()
FilteredAnalog(pin_t analogPin)
Construct a new FilteredAnalog object.
A class that reads and filters an analog input.
constexpr uint8_t ADC_BITS
The bit depth to use for the ADC (Analog to Digital Converter).
analog_t analogRead(pin_t pin)
An ExtIO version of the Arduino function.
A class for applying hysteresis to a given input.
uint16_t analog_t
The type returned from analogRead and similar functions.
uint16_t ANALOG_FILTER_TYPE
The unsigned integer type to use for analog inputs during filtering.
void invert()
Invert the analog value.
static void setupADC()
Select the configured ADC resolution.
#define AH_DIAGNOSTIC_WERROR()
#define BEGIN_AH_NAMESPACE
float getFloatValue() const
Get the filtered value of the analog input with the mapping function applied as a floating point numb...
bool update()
Read the analog input value, apply the mapping function, and update the average.