14#include "EventInputBase.h"
34 #if defined(FUNCTIONAL_SUPPORTED)
105 #if defined(FUNCTIONAL_SUPPORTED)
107 template <
typename T>
111 (instance->*method)(et, ie);
141 int16_t
position() {
return _reversePosition ? currentPos*-1 : currentPos; }
301 void setSliceNeg() { sliceNeg = max(((startVal-startBoundary-minVal-endBoundary)/negativeIncrements),1); }
306 void setSlicePos() { slicePos = max(((maxVal-endBoundary-startBoundary-startVal)/positiveIncrements),1); }
310 int16_t startVal = 0;
311 int16_t readVal = startVal;
312 int16_t currentVal = startVal;
313 int16_t previousVal = currentVal;
314 int16_t minVal = 100;
315 int16_t maxVal = 980;
316 int16_t startBoundary = 0;
317 int16_t endBoundary = 0;
318 int16_t adcMax = 1023;
321 int16_t negativeIncrements = 25;
322 int16_t positiveIncrements = 25;
323 int16_t sliceNeg = 20;
324 int16_t slicePos = 20;
327 int16_t currentPos = 0;
328 int16_t previousPos = 0;
329 bool _reversePosition =
false;
331 bool autoCalibrate =
true;
332 bool _hasChanged =
false;
333 bool _started =
false;
335 uint16_t rateLimit = 0;
336 unsigned long rateLimitCounter = 0;
338 void setReadPos(int16_t offset);
339 void setInitialReadPos();
The EventAnalog class is for analog inputs - slice an analog range into configurable number of increm...
Definition: EventAnalog.h:30
void setRateLimit(uint16_t ms)
Limit the rate at which events are fired.
Definition: EventAnalog.h:269
void setSlicePos()
Set the size of each positive slice/increment.
Definition: EventAnalog.h:306
void setSliceNeg()
Set the size of each negative slice/increment.
Definition: EventAnalog.h:301
int16_t previousPosition()
Returns the previous position - this is not the analog value but the mapped position of the increment...
Definition: EventAnalog.h:148
void invoke(InputEventType et) override
Override of the EventInputBase::invoke() virtual method.
Definition: EventAnalog.cpp:35
void setNumPositiveIncrements(uint8_t numIncr=10)
Normally increments are set with setNumIncrements() but you can also set the negative and positive si...
Definition: EventAnalog.cpp:150
void setMaxValue(uint16_t val)
The maximmum ADC value that can be read by the analog pin.
Definition: EventAnalog.cpp:118
void unsetCallback() override
Unset a previously set callback function or method.
Definition: EventAnalog.cpp:30
void setNumIncrements(uint8_t numIncr=10)
Split the analog range into this number of slices. The default is 25.
Definition: EventAnalog.cpp:138
void setCallback(T *instance, void(T::*method)(InputEventType, EventAnalog &))
Set the Callback function to a class method.
Definition: EventAnalog.h:108
std::function< void(InputEventType et, EventAnalog &ie)> CallbackFunction
If std::function is supported, this creates the callback type.
Definition: EventAnalog.h:38
void update()
Update the state from the analog input. Must be called from within loop() in order to update state fr...
Definition: EventAnalog.cpp:41
int16_t position()
Returns the current position - this is not the analog value but the mapped position of the increments...
Definition: EventAnalog.h:141
void setEndBoundary(uint16_t width=100)
Used primarily for joysticks.
Definition: EventAnalog.cpp:133
void reversePosition(bool rev=true)
Reverse the increments.
Definition: EventAnalog.h:285
bool hasChanged()
Returns true if the position has changed since previous update()
Definition: EventAnalog.h:157
void setCallback(CallbackFunction f)
Set the Callback function.
Definition: EventAnalog.h:92
void setMinValue(uint16_t val)
The minimum ADC value that can be read by the analog pin.
Definition: EventAnalog.cpp:113
void enableAutoCalibrate(bool enable=true)
If enableAutoCalibrate is set to true (the default), will do auto calibration, setting the minValue a...
Definition: EventAnalog.h:277
EventAnalog(byte analogPin, uint8_t adcBits=10)
Construct an EventAnalog input.
Definition: EventAnalog.cpp:12
CallbackFunction callbackFunction
The callback function member.
Definition: EventAnalog.h:49
void setNumNegativeIncrements(uint8_t numIncr=10)
Normally increments are set with setNumIncrements() but you can also set the negative and positive si...
Definition: EventAnalog.cpp:145
bool isPositionReversed()
Returns true if position is reversed.
Definition: EventAnalog.h:293
void setStartBoundary(uint16_t width=200)
Used primarily for joysticks.
Definition: EventAnalog.cpp:128
void begin()
Initialise the EventAnalog. Must be called from within setup()
Definition: EventAnalog.cpp:19
void setStartValue()
Will set the start value as the current position.
Definition: EventAnalog.cpp:123