Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
AHEncoder Class Reference

#include <Submodules/Encoder/AHEncoder.hpp>

Detailed Description

Class for reading quadrature encoders, heavily influenced by http://www.pjrc.com/teensy/td_libs_Encoder.html.

Definition at line 24 of file AHEncoder.hpp.

+ Collaboration diagram for AHEncoder:

Public Member Functions

 AHEncoder (ArduinoPin_t pinA, ArduinoPin_t pinB)
 Constructor.
 
 AHEncoder (const AHEncoder &)=delete
 Copy constructor: copying an Encoder object is semantically meaningless, so it has been deleted.
 
AHEncoderoperator= (const AHEncoder &)=delete
 Copy assignment: copying an Encoder object is semantically meaningless, so it has been deleted.
 
 AHEncoder (AHEncoder &&other)
 Move constructor.
 
AHEncoderoperator= (AHEncoder &&other)
 Move assignment.
 
 ~AHEncoder ()
 Destructor, detaches the interrupts.
 
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).
 
void end ()
 Disable the interrupts used by this encoder.
 
int32_t read ()
 Read the current absolute position of the encoder.
 
int32_t readAndReset (int32_t newpos=0)
 Read the current absolute position of the encoder and reset it to zero afterwards.
 
void write (int32_t p)
 Set the absolute position to the given value.
 

Private Types

using isr_func_t = void (*)()
 The type of a handler function.
 

Private Member Functions

void attachInterruptCtx (interrupt_t interrupt)
 Register the interrupt handler for this instance.
 
void detachInterruptCtx (interrupt_t interrupt)
 Un-register the interrupt handler for this instance.
 
void update ()
 Private handler function that is called from the ISR.
 

Static Private Member Functions

template<interrupt_t NumISR = NUM_DIGITAL_PINS>
static isr_func_t get_isr (interrupt_t interrupt)
 Get a pointer to the interrupt handler function for the given interrupt.
 

Private Attributes

AH::Array< ArduinoPin_t, 2 > pins
 
uint8_t interrupts_in_use = 0
 
uint8_t state = 0
 
AH::Array< DirectPinRead, 2 > direct_pins
 
AtomicPosition< int32_t > position {0}
 

Static Private Attributes

static AHEncoderinstance_table [NUM_DIGITAL_PINS] {}
 Array of pointers to all instances with active interrupts.
 

Member Typedef Documentation

◆ isr_func_t

using isr_func_t = void (*)()
private

The type of a handler function.

Definition at line 73 of file AHEncoder.hpp.

Constructor & Destructor Documentation

◆ AHEncoder() [1/3]

Constructor.

Parameters
pinAThe first pin, connected to the encoder's "A" pin.
pinBThe 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).

Definition at line 14 of file AHEncoder.cpp.

◆ AHEncoder() [2/3]

AHEncoder ( const AHEncoder & )
delete

Copy constructor: copying an Encoder object is semantically meaningless, so it has been deleted.

◆ AHEncoder() [3/3]

AHEncoder ( AHEncoder && other)

Move constructor.

Definition at line 23 of file AHEncoder.cpp.

◆ ~AHEncoder()

~AHEncoder ( )

Destructor, detaches the interrupts.

Definition at line 72 of file AHEncoder.cpp.

Member Function Documentation

◆ operator=() [1/2]

AHEncoder & operator= ( const AHEncoder & )
delete

Copy assignment: copying an Encoder object is semantically meaningless, so it has been deleted.

◆ operator=() [2/2]

AHEncoder & operator= ( AHEncoder && other)

Move assignment.

Definition at line 29 of file AHEncoder.cpp.

◆ begin()

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 79 of file AHEncoder.cpp.

◆ end()

void end ( )

Disable the interrupts used by this encoder.

Definition at line 104 of file AHEncoder.cpp.

◆ read()

int32_t read ( )

Read the current absolute position of the encoder.

◆ readAndReset()

int32_t readAndReset ( int32_t newpos = 0)

Read the current absolute position of the encoder and reset it to zero afterwards.

◆ write()

void write ( int32_t p)

Set the absolute position to the given value.

◆ get_isr()

template<interrupt_t NumISR = NUM_DIGITAL_PINS>
static isr_func_t get_isr ( interrupt_t interrupt)
staticprivate

Get a pointer to the interrupt handler function for the given interrupt.

◆ attachInterruptCtx()

void attachInterruptCtx ( interrupt_t interrupt)
private

Register the interrupt handler for this instance.

Definition at line 111 of file AHEncoder.cpp.

◆ detachInterruptCtx()

void detachInterruptCtx ( interrupt_t interrupt)
private

Un-register the interrupt handler for this instance.

Definition at line 133 of file AHEncoder.cpp.

◆ update()

void update ( )
private

Private handler function that is called from the ISR.

Member Data Documentation

◆ pins

AH::Array<ArduinoPin_t, 2> pins
private

Definition at line 83 of file AHEncoder.hpp.

◆ interrupts_in_use

uint8_t interrupts_in_use = 0
private

Definition at line 84 of file AHEncoder.hpp.

◆ state

uint8_t state = 0
private

Definition at line 85 of file AHEncoder.hpp.

◆ direct_pins

AH::Array<DirectPinRead, 2> direct_pins
private

Definition at line 86 of file AHEncoder.hpp.

◆ position

AtomicPosition<int32_t> position {0}
private

Definition at line 87 of file AHEncoder.hpp.

◆ instance_table

AHEncoder * instance_table {}
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 146 of file AHEncoder.hpp.


The documentation for this class was generated from the following files: