#include <Submodules/Encoder/AHEncoder.hpp>
Class for reading quadrature encoders, heavily influenced by http://www.pjrc.com/teensy/td_libs_Encoder.html.
Definition at line 21 of file AHEncoder.hpp.
Public Member Functions | |
AHEncoder (ArduinoPin_t pinA, ArduinoPin_t pinB) | |
Constructor. More... | |
AHEncoder (const AHEncoder &)=delete | |
Copy constructor: copying an Encoder object is semantically meaningless, so it has been deleted. More... | |
AHEncoder & | operator= (const AHEncoder &)=delete |
Copy assignment: copying an Encoder object is semantically meaningless, so it has been deleted. More... | |
AHEncoder (AHEncoder &&other) | |
Move constructor. More... | |
AHEncoder & | operator= (AHEncoder &&other) |
Move assignment. More... | |
~AHEncoder () | |
Destructor, detaches the interrupts. More... | |
void | begin () |
Initialize this encoder by enabling the pull-up resistors and attaching the interrupts handlers (if interrupts are enabled and available on the the given pins). More... | |
void | end () |
Disable the interrupts used by this encoder. More... | |
int32_t | read () |
Read the current absolute position of the encoder. More... | |
int32_t | readAndReset (int32_t newpos=0) |
Read the current absolute position of the encoder and reset it to zero afterwards. More... | |
void | write (int32_t p) |
Set the absolute position to the given value. More... | |
template<unsigned NumISR> | |
auto | get_isr (unsigned interrupt) -> isr_func_t |
Private Types | |
using | isr_func_t = void(*)() |
The type of a handler function. More... | |
Private Member Functions | |
void | attachInterruptCtx (int interrupt) |
Register the interrupt handler for this instance. More... | |
void | detachInterruptCtx (int interrupt) |
Un-register the interrupt handler for this instance. More... | |
void | update () |
Private handler function that is called from the ISR. More... | |
Static Private Member Functions | |
template<unsigned NumISR = NUM_DIGITAL_PINS> | |
static isr_func_t | get_isr (unsigned interrupt) |
Get a pointer to the interrupt handler function for the given interrupt. More... | |
template<> | |
auto | get_isr (unsigned) -> isr_func_t |
Private Attributes | |
ArduinoPin_t | pins [2] |
uint8_t | interrupts_in_use = 0 |
uint8_t | state = 0 |
DirectPinRead | direct_pins [2] |
AtomicPosition< int32_t > | position {0} |
Static Private Attributes | |
static AHEncoder * | instance_table [NUM_DIGITAL_PINS] {} |
Array of pointers to all instances with active interrupts. More... | |
|
private |
The type of a handler function.
Definition at line 70 of file AHEncoder.hpp.
AHEncoder | ( | ArduinoPin_t | pinA, |
ArduinoPin_t | pinB | ||
) |
Constructor.
pinA | The first pin, connected to the encoder's "A" pin. |
pinB | The second pin, connected to the encoder's "B" pin. |
The internal pull-up resistors will be enabled on these pins upon initialization (when calling the begin
method).
Copy constructor: copying an Encoder object is semantically meaningless, so it has been deleted.
Move constructor.
Definition at line 18 of file AHEncoder.cpp.
~AHEncoder | ( | ) |
Destructor, detaches the interrupts.
Definition at line 63 of file AHEncoder.cpp.
Copy assignment: copying an Encoder object is semantically meaningless, so it has been deleted.
Move assignment.
Definition at line 20 of file AHEncoder.cpp.
void begin | ( | ) |
Initialize this encoder by enabling the pull-up resistors and attaching the interrupts handlers (if interrupts are enabled and available on the the given pins).
Definition at line 70 of file AHEncoder.cpp.
void end | ( | ) |
Disable the interrupts used by this encoder.
Definition at line 93 of file AHEncoder.cpp.
|
inline |
Read the current absolute position of the encoder.
Definition at line 19 of file AHEncoder.ipp.
|
inline |
Read the current absolute position of the encoder and reset it to zero afterwards.
Definition at line 25 of file AHEncoder.ipp.
|
inline |
Set the absolute position to the given value.
Definition at line 31 of file AHEncoder.ipp.
|
staticprivate |
Get a pointer to the interrupt handler function for the given interrupt.
|
private |
Register the interrupt handler for this instance.
Definition at line 100 of file AHEncoder.cpp.
|
private |
Un-register the interrupt handler for this instance.
Definition at line 121 of file AHEncoder.cpp.
|
inlineprivate |
Private handler function that is called from the ISR.
Definition at line 62 of file AHEncoder.ipp.
auto get_isr | ( | unsigned | interrupt | ) | -> isr_func_t |
Definition at line 8 of file AHEncoder.ipp.
|
inlinestaticprivate |
Definition at line 15 of file AHEncoder.ipp.
|
private |
Definition at line 80 of file AHEncoder.hpp.
|
private |
Definition at line 81 of file AHEncoder.hpp.
|
private |
Definition at line 82 of file AHEncoder.hpp.
|
private |
Definition at line 83 of file AHEncoder.hpp.
|
private |
Definition at line 84 of file AHEncoder.hpp.
|
staticprivate |
Array of pointers to all instances with active interrupts.
Used to look up the instance to call the handler for in the ISR.
Definition at line 91 of file AHEncoder.hpp.