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