### Doxygen Class Documentation Examples Source: https://madhephaestus.github.io/ESP32Encoder/graph_legend.html Examples of C++ classes with doxygen comments illustrating different documentation and inheritance scenarios. These are used to generate documentation graphs. ```cpp /*! Invisible class because of truncation */ class Invisible { }; ``` ```cpp /*! Truncated class, inheritance relation is hidden */ class Truncated : public Invisible { }; ``` ```cpp /* Class not documented with doxygen comments */ class Undocumented { }; ``` ```cpp /*! Class that is inherited using public inheritance */ class PublicBase : public Truncated { }; ``` ```cpp /*! A template class */ template class Templ { }; ``` ```cpp /*! Class that is inherited using protected inheritance */ class ProtectedBase { }; ``` ```cpp /*! Class that is inherited using private inheritance */ class PrivateBase { }; ``` ```cpp /*! Class that is used by the Inherited class */ class Used { }; ``` ```cpp /*! Super class that inherits a number of other classes */ class Inherited : public PublicBase, protected ProtectedBase, private PrivateBase, public Undocumented, public Templ { private: Used *m_usedClass; }; ``` -------------------------------- ### Initialize and Use ESP32Encoder Source: https://madhephaestus.github.io/ESP32Encoder/Encoder_8ino_source.html This example demonstrates how to initialize two ESP32Encoder objects, attach them to specific pins, set initial counts, and read their values in the loop. It also includes logic to pause and resume one of the encoders. ```cpp #include ESP32Encoder encoder; ESP32Encoder encoder2; // timer and flag for example, not needed for encoders unsigned long encoder2lastToggled; bool encoder2Paused = false; void setup(){ Serial.begin(115200); // Enable the weak pull down resistors //ESP32Encoder::useInternalWeakPullResistors=DOWN; // Enable the weak pull up resistors ESP32Encoder::useInternalWeakPullResistors=UP; // use pin 19 and 18 for the first encoder encoder.attachHalfQuad(19, 18); // use pin 17 and 16 for the second encoder encoder2.attachHalfQuad(17, 16); // set starting count value after attaching encoder.setCount(37); // clear the encoder's raw count and set the tracked count to zero encoder2.clearCount(); Serial.println("Encoder Start = " + String((int32_t)encoder.getCount())); // set the lastToggle encoder2lastToggled = millis(); } void loop(){ // Loop and read the count Serial.println("Encoder count = " + String((int32_t)encoder.getCount()) + " " + String((int32_t)encoder2.getCount())); delay(100); // every 5 seconds toggle encoder 2 if (millis() - encoder2lastToggled >= 5000) { if(encoder2Paused) { Serial.println("Resuming Encoder 2"); encoder2.resumeCount(); } else { Serial.println("Paused Encoder 2"); encoder2.pauseCount(); } encoder2Paused = !encoder2Paused; encoder2lastToggled = millis(); } } ``` -------------------------------- ### Attach Encoder Pins and Configure PCNT Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Attaches the encoder's A and B pins to the ESP32 and configures the PCNT unit for counting. Supports single or full quadrature encoding. Includes GPIO setup and pull-resistor configuration. ```cpp void ESP32Encoder::attach(int a, int b, enum encType et) { if (attached) { Serial.println("Already attached, FAIL!"); return; } int index = 0; for (; index < MAX_ESP32_ENCODERS; index++) { if (ESP32Encoder::encoders[index] == NULL) { encoders[index] = this; break; } } if (index == MAX_ESP32_ENCODERS) { Serial.println("Too many encoders, FAIL!"); return; } // Set data now that pin attach checks are done fullQuad = et != single; unit = (pcnt_unit_t) index; this->aPinNumber = (gpio_num_t) a; this->bPinNumber = (gpio_num_t) b; //Set up the IO state of hte pin gpio_pad_select_gpio(aPinNumber); gpio_pad_select_gpio(bPinNumber); gpio_set_direction(aPinNumber, GPIO_MODE_INPUT); gpio_set_direction(bPinNumber, GPIO_MODE_INPUT); if(useInternalWeakPullResistors==DOWN){ gpio_pulldown_en(aPinNumber); gpio_pulldown_en(bPinNumber); } if(useInternalWeakPullResistors==UP){ gpio_pullup_en(aPinNumber); gpio_pullup_en(bPinNumber); } // Set up encoder PCNT configuration r_enc_config.pulse_gpio_num = aPinNumber; //Rotary Encoder Chan A r_enc_config.ctrl_gpio_num = bPinNumber; //Rotary Encoder Chan B r_enc_config.unit = unit; r_enc_config.channel = PCNT_CHANNEL_0; r_enc_config.pos_mode = fullQuad ? PCNT_COUNT_DEC : PCNT_COUNT_DIS; //Count Only On Rising-Edges r_enc_config.neg_mode = PCNT_COUNT_INC; // Discard Falling-Edge r_enc_config.lctrl_mode = PCNT_MODE_KEEP; // Rising A on HIGH B = CW Step r_enc_config.hctrl_mode = PCNT_MODE_REVERSE; // Rising A on LOW B = CCW Step r_enc_config .counter_h_lim = _INT16_MAX; r_enc_config .counter_l_lim = _INT16_MIN ; pcnt_unit_config(&r_enc_config); if (et == full) { // set up second channel for full quad r_enc_config.pulse_gpio_num = bPinNumber; //make prior control into signal r_enc_config.ctrl_gpio_num = aPinNumber; //and prior signal into control r_enc_config.unit = unit; r_enc_config.channel = PCNT_CHANNEL_1; // channel 1 r_enc_config.pos_mode = PCNT_COUNT_DEC; //Count Only On Rising-Edges r_enc_config.neg_mode = PCNT_COUNT_INC; // Discard Falling-Edge r_enc_config.lctrl_mode = PCNT_MODE_REVERSE; // prior high mode is now low r_enc_config.hctrl_mode = PCNT_MODE_KEEP; // prior low mode is now high r_enc_config .counter_h_lim = _INT16_MAX; r_enc_config .counter_l_lim = _INT16_MIN ; pcnt_unit_config(&r_enc_config); } else { // make sure channel 1 is not set when not full quad r_enc_config.pulse_gpio_num = bPinNumber; //make prior control into signal r_enc_config.ctrl_gpio_num = aPinNumber; //and prior signal into control r_enc_config.unit = unit; r_enc_config.channel = PCNT_CHANNEL_1; // channel 1 r_enc_config.pos_mode = PCNT_COUNT_DIS; //disabling channel 1 r_enc_config.neg_mode = PCNT_COUNT_DIS; // disabling channel 1 } ``` -------------------------------- ### Set Encoder Count Source: https://madhephaestus.github.io/ESP32Encoder/Encoder_8ino_source.html Sets the initial count value for an encoder after it has been attached. This is useful for resetting or starting at a specific position. ```cpp encoder.setCount(37); ``` -------------------------------- ### ESP32Encoder Count Manipulation Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Functions to get, set, clear, pause, and resume the encoder count. ```APIDOC ## ESP32Encoder Count Manipulation ### Description This section covers the functions for managing the encoder's count value, including retrieving the current count, setting a specific count, clearing the count to zero, and pausing or resuming the counting process. ### Methods - `setCount(int64_t value)`: Sets the current count to a specific value. - `getCountRaw()`: Retrieves the raw counter value from the PCNT unit. - `getCount()`: Retrieves the current count, adjusted by any offset. - `clearCount()`: Resets the encoder count to zero. - `pauseCount()`: Pauses the encoder's counting mechanism. - `resumeCount()`: Resumes the encoder's counting mechanism. ### Endpoint N/A (Library functions) ### Parameters - **setCount**: `value` (int64_t) - The desired count value. ### Request Example ```cpp ESP32Encoder encoder; // Set the count to 100 encoder.setCount(100); // Get the current count int64_t currentCount = encoder.getCount(); // Clear the count encoder.clearCount(); // Pause counting encoder.pauseCount(); // Resume counting encoder.resumeCount(); ``` ### Response - `getCountRaw()`: Returns `int16_t` (raw counter value). - `getCount()`: Returns `int64_t` (adjusted count value). - `clearCount()`: Returns the result of `pcnt_counter_clear`. - `pauseCount()`: Returns the result of `pcnt_counter_pause`. - `resumeCount()`: Returns the result of `pcnt_counter_resume`. ### Error Handling - `clearCount()` returns the status of `pcnt_counter_clear`. - `pauseCount()` returns the status of `pcnt_counter_pause`. - `resumeCount()` returns the status of `pcnt_counter_resume`. ``` -------------------------------- ### Get Current Encoder Count Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Returns the current encoder count, which is the raw counter value plus any offset applied by setCount(). ```cpp int64_t ESP32Encoder::getCount() { return getCountRaw() + count; } ``` -------------------------------- ### Get Encoder Count Source: https://madhephaestus.github.io/ESP32Encoder/Encoder_8ino_source.html Retrieves the current count value of the encoder. This function can be called repeatedly to monitor the encoder's position. ```cpp encoder.getCount() ``` ```cpp encoder2.getCount() ``` -------------------------------- ### Get Raw Encoder Counter Value Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Retrieves the current raw value from the PCNT counter. This value does not include the offset managed by the 'count' variable. ```cpp int64_t ESP32Encoder::getCountRaw() { int16_t c; pcnt_get_counter_value(unit, &c); return c; } ``` -------------------------------- ### ESP32Encoder Initialization and Attachment Source: https://madhephaestus.github.io/ESP32Encoder/Encoder_8ino_source.html Demonstrates how to initialize and attach ESP32Encoder objects to specific GPIO pins for quadrature encoding. ```APIDOC ## ESP32Encoder Initialization and Attachment ### Description This section covers the initialization of the ESP32Encoder library and the attachment of encoder objects to GPIO pins using the `attachHalfQuad` method. It also shows how to set initial count values and clear counts. ### Method - `ESP32Encoder::useInternalWeakPullResistors = UP;` - `encoder.attachHalfQuad(int aPinNumber, int bPinNumber);` - `encoder.setCount(int64_t value);` - `encoder.clearCount();` ### Parameters #### `ESP32Encoder::useInternalWeakPullResistors` - **`UP`** (enum puType) - Enables internal weak pull-up resistors. #### `attachHalfQuad` - **`aPinNumber`** (int) - The GPIO pin number for the first channel of the encoder. - **`bPinNumber`** (int) - The GPIO pin number for the second channel of the encoder. #### `setCount` - **`value`** (int64_t) - The initial count value to set for the encoder. #### `clearCount` - This method does not take any parameters. ### Request Example ```cpp #include ESP32Encoder encoder; ESP32Encoder encoder2; void setup(){ Serial.begin(115200); ESP32Encoder::useInternalWeakPullResistors=UP; encoder.attachHalfQuad(19, 18); encoder2.attachHalfQuad(17, 16); encoder.setCount(37); encoder2.clearCount(); Serial.println("Encoder Start = " + String((int32_t)encoder.getCount())); } ``` ### Response #### Success Response (200) - The `setup()` function does not return a value. Serial output will indicate the initial encoder counts. #### Response Example ``` Encoder Start = 37 ``` ``` -------------------------------- ### ESP32Encoder Initialization and Configuration Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html This section details the initialization and configuration of the ESP32 encoder, including setting up the PCNT unit, limits, and interrupts. ```APIDOC ## ESP32Encoder Initialization and Configuration ### Description Initializes the Pulse Counter (PCNT) unit for encoder functionality. This includes setting control modes, counter limits, enabling specific events, and registering an Interrupt Service Routine (ISR) handler. ### Method `attach(int aPintNumber, int bPinNumber, enum encType et)` ### Endpoint N/A (This is a library function, not an API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp // Example of attaching an encoder ESP32Encoder encoder; encoder.attachHalfQuad(2, 3); ``` ### Response None (This is a configuration function) ### Error Handling - Prints "Encoder wrap interrupt failed" to Serial if ISR registration fails. ``` -------------------------------- ### Initialize and Attach Encoder Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Initializes the PCNT unit, clears the counter, and attaches the encoder with a specified mode. Ensure the PCNT unit is configured before calling this. ```cpp pcnt_counter_pause(unit); // Initial PCNT init pcnt_counter_clear(unit); pcnt_counter_resume(unit); ``` -------------------------------- ### ESP32Encoder Project Structure Source: https://madhephaestus.github.io/ESP32Encoder/dir_d28a4824dc47e487b107a5db32ef43c4.html Overview of the ESP32Encoder project's directory and file structure. ```APIDOC ## Project: /websites/madhephaestus_github_io_esp32encoder ### Overview This project contains the ESP32Encoder library, which provides functionality for using rotary encoders with ESP32 microcontrollers. ### Directory Structure - `examples/` - Contains example projects demonstrating the usage of the ESP32Encoder library. ### Directory Dependency Graph ``` directory | Encoder ``` ### Key Components - **Data Structures**: Information about the data structures used within the library. - **Files**: Details about the files comprising the library. - **Globals**: Global functions, variables, enumerations, and macros. - **Examples**: Demonstrations of how to use the encoder functionality. ``` -------------------------------- ### Global Variables Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp.html Documentation for global variables and enumerations defined in the library. ```APIDOC ## enum puType ESP32Encoder ### Description Enumeration defining the pull-up type configuration for the encoder pins. ``` -------------------------------- ### ESP32Encoder Class and Configuration Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8h.html Overview of the main class and configuration types used for initializing rotary encoders on the ESP32. ```APIDOC ## Class: ESP32Encoder ### Description The primary class for interfacing with rotary encoders using the ESP32 PCNT peripheral. ### Enumerations #### encType - **single**: Single edge counting - **half**: Half step counting - **full**: Full step counting #### puType - **UP**: Internal pull-up enabled - **DOWN**: Internal pull-down enabled - **NONE**: No internal resistor ### Macros - **MAX_ESP32_ENCODERS**: Maximum number of encoders supported (defined by PCNT_UNIT_MAX) - **_INT16_MAX**: 32766 - **_INT16_MIN**: -32766 ``` -------------------------------- ### ESP32Encoder Library File Structure Source: https://madhephaestus.github.io/ESP32Encoder/files.html Overview of the files included in the ESP32Encoder library. ```APIDOC ## ESP32Encoder Library File Structure ### Description This section outlines the directory and file structure of the ESP32Encoder library. ### Files - `examples/` - `Encoder/` - `Encoder.ino` - `src/` - `ESP32Encoder.cpp` - `ESP32Encoder.h` ``` -------------------------------- ### ESP32Encoder Class Constructor Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Initializes the ESP32Encoder object with default values. Sets up internal variables for tracking encoder state. ```cpp ESP32Encoder::ESP32Encoder() { attached = false; aPinNumber = (gpio_num_t) 0; bPinNumber = (gpio_num_t) 0; working = false; direction = false; unit = (pcnt_unit_t) -1; } ``` -------------------------------- ### ESP32Encoder Class Methods Source: https://madhephaestus.github.io/ESP32Encoder/functions_func.html Methods for initializing, configuring, and controlling rotary encoder instances. ```APIDOC ## ESP32Encoder Methods ### Description Methods to attach pins, configure quadrature modes, and manage encoder counts. ### Methods - **attach(int aPin, int bPin)**: Attaches the encoder to the specified pins. - **attachFullQuad(int aPin, int bPin)**: Attaches the encoder in full quadrature mode. - **attachHalfQuad(int aPin, int bPin)**: Attaches the encoder in half quadrature mode. - **attachSingleEdge(int aPin, int bPin)**: Attaches the encoder in single edge mode. - **getCount()**: Returns the current encoder count. - **getCountRaw()**: Returns the raw encoder count. - **setCount(int64_t count)**: Sets the current encoder count. - **clearCount()**: Resets the encoder count to zero. - **pauseCount()**: Pauses the encoder counting. - **resumeCount()**: Resumes the encoder counting. - **isAttached()**: Returns true if the encoder is currently attached. - **setFilter(uint8_t filterVal)**: Sets the hardware filter value. ``` -------------------------------- ### ESP32Encoder Library Functions Source: https://madhephaestus.github.io/ESP32Encoder/Encoder_8ino.html Core functions for initializing and managing the encoder lifecycle. ```APIDOC ## void setup() ### Description Initializes the encoder hardware, configures pull-up resistors, and sets initial counts. ### Parameters - None ## void loop() ### Description Main execution loop that handles encoder state monitoring, including pausing and resuming counts based on logic. ### Parameters - None ``` -------------------------------- ### ESP32Encoder Attachment Methods Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Provides methods to attach encoders using different modes: half quad, single edge, and full quad. ```APIDOC ## ESP32Encoder Attachment Methods ### Description These methods allow you to attach a rotary encoder to specific GPIO pins using different quadrature decoding modes. ### Methods - `attachHalfQuad(int aPintNumber, int bPinNumber)`: Attaches an encoder in half quadrature mode. - `attachSingleEdge(int aPintNumber, int bPinNumber)`: Attaches an encoder in single edge mode. - `attachFullQuad(int aPintNumber, int bPinNumber)`: Attaches an encoder in full quadrature mode. ### Endpoint N/A (Library functions) ### Parameters - **aPintNumber** (int) - Required - The GPIO pin number for the encoder's A channel. - **bPinNumber** (int) - Required - The GPIO pin number for the encoder's B channel. ### Request Example ```cpp ESP32Encoder encoder; // Attach using half quad mode encoder.attachHalfQuad(2, 3); // Attach using single edge mode // encoder.attachSingleEdge(4, 5); // Attach using full quad mode // encoder.attachFullQuad(6, 7); ``` ### Response None ### Error Handling None explicitly mentioned for these attachment methods, but underlying `attach` function may have error handling. ``` -------------------------------- ### ESP32Encoder Methods Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Methods for attaching pins to an encoder and managing the raw count values. ```APIDOC ## void attachFullQuad(int aPintNumber, int bPinNumber) ### Description Initializes the encoder by attaching the specified A and B pins for full quadrature decoding. ### Parameters - **aPintNumber** (int) - Required - The GPIO pin number for channel A. - **bPinNumber** (int) - Required - The GPIO pin number for channel B. --- ## int64_t getCountRaw() ### Description Retrieves the current raw count value from the encoder. ### Response - **int64_t** - The current raw count value. --- ## int64_t clearCount() ### Description Resets the encoder count to zero and returns the previous count value. ### Response - **int64_t** - The count value before it was cleared. ``` -------------------------------- ### Attach Encoder with Custom Pins and Mode Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Attaches the encoder to specified pins and selects the encoding mode (half, single, or full quadrature). This is a core function for setting up the encoder. ```cpp void attach(int aPintNumber, int bPinNumber, enum encType et) ``` -------------------------------- ### void setFilter(uint16_t value) Source: https://madhephaestus.github.io/ESP32Encoder/classESP32Encoder.html Sets the filter value for the encoder unit. ```APIDOC ## void setFilter(uint16_t value) ### Description Configures the pulse counter filter value for the encoder unit. ### Parameters #### Request Body - **value** (uint16_t) - Required - The filter value to apply. ``` -------------------------------- ### Configure Internal Pull-up Resistors Source: https://madhephaestus.github.io/ESP32Encoder/Encoder_8ino_source.html Sets the internal weak pull-up resistors for the encoder pins. This is an important configuration step before attaching encoders. ```cpp ESP32Encoder::useInternalWeakPullResistors=UP; ``` -------------------------------- ### ESP32Encoder Library Definitions Source: https://madhephaestus.github.io/ESP32Encoder/globals_enum.html Overview of the data structures and global types available in the ESP32Encoder library. ```APIDOC ## ESP32Encoder Library Definitions ### Description This library provides an interface for handling rotary encoders on the ESP32 platform. It defines specific data structures and global types for encoder configuration. ### Data Structures - **encType** (Defined in ESP32Encoder.h) - **puType** (Defined in ESP32Encoder.h) ### Globals - **Functions**: Available for encoder management. - **Variables**: Global state variables for encoder instances. - **Enumerations**: Defined types for encoder behavior. - **Macros**: Preprocessor definitions for library configuration. ``` -------------------------------- ### ESP32Encoder Header Definition Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8h_source.html The primary header file defining the ESP32Encoder class, configuration enums, and hardware-specific constants. ```cpp #pragma once #include #include #include #define MAX_ESP32_ENCODERS PCNT_UNIT_MAX #define _INT16_MAX 32766 #define _INT16_MIN -32766 enum encType { single, half, full }; enum puType { UP, DOWN, NONE }; class ESP32Encoder { private: void attach(int aPintNumber, int bPinNumber, enum encType et); boolean attached=false; static pcnt_isr_handle_t user_isr_handle; //user's ISR service handle bool direction; bool working; static bool attachedInterrupt; int64_t getCountRaw(); public: ESP32Encoder(); ~ESP32Encoder(); void attachHalfQuad(int aPintNumber, int bPinNumber); void attachFullQuad(int aPintNumber, int bPinNumber); void attachSingleEdge(int aPintNumber, int bPinNumber); int64_t getCount(); int64_t clearCount(); int64_t pauseCount(); int64_t resumeCount(); boolean isAttached(){return attached;} void setCount(int64_t value); void setFilter(uint16_t value); static ESP32Encoder *encoders[MAX_ESP32_ENCODERS]; gpio_num_t aPinNumber; gpio_num_t bPinNumber; pcnt_unit_t unit; bool fullQuad=false; int countsMode = 2; volatile int64_t count=0; pcnt_config_t r_enc_config; static enum puType useInternalWeakPullResistors; }; //Added by Sloeber #pragma once ``` -------------------------------- ### ESP32Encoder Global Definitions Source: https://madhephaestus.github.io/ESP32Encoder/globals_eval.html This section lists the global definitions available in the ESP32Encoder library, primarily related to encoder states or modes. ```APIDOC ## Global Definitions ### Description These are the globally accessible constants or enumerations provided by the ESP32Encoder library. ### Enumerations #### `encoder_state_t` (or similar, inferred from context) - **`NONE`**: Represents a neutral or uninitialized state. - **`UP`**: Indicates an upward rotation or increment. - **`DOWN`**: Indicates a downward rotation or decrement. - **`single`**: Potentially represents a single step or event. - **`half`**: Potentially represents a half-step or partial event. - **`full`**: Potentially represents a full step or complete event. ### Source File - `ESP32Encoder.h` ``` -------------------------------- ### ESP32Encoder Reading and Control Source: https://madhephaestus.github.io/ESP32Encoder/Encoder_8ino_source.html Details on how to read the current count of an encoder, and how to pause and resume its counting functionality. ```APIDOC ## ESP32Encoder Reading and Control ### Description This section explains how to continuously read the count from ESP32Encoder objects within the `loop` function and demonstrates the usage of `pauseCount` and `resumeCount` methods to control the encoder's counting behavior. ### Method - `encoder.getCount()` - `encoder.pauseCount()` - `encoder.resumeCount()` ### Parameters #### `getCount` - This method does not take any parameters. #### `pauseCount` - This method does not take any parameters. #### `resumeCount` - This method does not take any parameters. ### Request Example ```cpp #include ESP32Encoder encoder; ESP32Encoder encoder2; unsigned long encoder2lastToggled; bool encoder2Paused = false; void setup(){ Serial.begin(115200); ESP32Encoder::useInternalWeakPullResistors=UP; encoder.attachHalfQuad(19, 18); encoder2.attachHalfQuad(17, 16); encoder.setCount(37); encoder2.clearCount(); Serial.println("Encoder Start = " + String((int32_t)encoder.getCount())); encoder2lastToggled = millis(); } void loop(){ Serial.println("Encoder count = " + String((int32_t)encoder.getCount()) + " " + String((int32_t)encoder2.getCount())); delay(100); if (millis() - encoder2lastToggled >= 5000) { if(encoder2Paused) { Serial.println("Resuming Encoder 2"); encoder2.resumeCount(); } else { Serial.println("Paused Encoder 2"); encoder2.pauseCount(); } encoder2Paused = !encoder2Paused; encoder2lastToggled = millis(); } } ``` ### Response #### Success Response (200) - The `getCount()` method returns the current count as an `int64_t`. - The `pauseCount()` and `resumeCount()` methods do not return a value but control the encoder's state. - Serial output will show the encoder counts and status messages. #### Response Example ``` Encoder count = 42 15 Resuming Encoder 2 Encoder count = 45 15 Paused Encoder 2 Encoder count = 48 15 ``` ``` -------------------------------- ### ESP32Encoder Globals Source: https://madhephaestus.github.io/ESP32Encoder/files.html Information regarding global elements within the ESP32Encoder library. ```APIDOC ## ESP32Encoder Globals ### Description This section covers global elements within the ESP32Encoder library. ### Globals - **All**: All global elements. - **Functions**: Global functions. - **Variables**: Global variables. - **Enumerations**: Global enumerations. - **Enumerator**: Enumerator values. - **Macros**: Global macros. ``` -------------------------------- ### ESP32Encoder Data Structures Source: https://madhephaestus.github.io/ESP32Encoder/files.html Details about the data structures used within the ESP32Encoder library. ```APIDOC ## ESP32Encoder Data Structures ### Description This section details the data structures available in the ESP32Encoder library. ### Data Structures - **Data Structures**: General information about data structures. - **Data Structure Index**: An index of all data structures. - **Data Fields**: Fields within the data structures. - **All**: All fields. - **Functions**: Functions related to data structures. - **Variables**: Variables within data structures. ``` -------------------------------- ### Configure PCNT Unit for Encoder Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Configures the Pulse Counter (PCNT) unit for encoder functionality, setting limits and disabling specific modes. Ensure PCNT unit is initialized before use. ```cpp r_enc_config.lctrl_mode = PCNT_MODE_DISABLE; // disabling channel 1 r_enc_config.hctrl_mode = PCNT_MODE_DISABLE; // disabling channel 1 r_enc_config .counter_h_lim = _INT16_MAX; r_enc_config .counter_l_lim = _INT16_MIN ; pcnt_unit_config(&r_enc_config); ``` -------------------------------- ### Attach Encoder with Half Quadrature Mode Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Attaches the encoder to the specified pins using the half quadrature mode. This mode typically uses one edge of each channel signal. ```cpp void ESP32Encoder::attachHalfQuad(int aPintNumber, int bPinNumber) { attach(aPintNumber, bPinNumber, half); } ``` -------------------------------- ### ESP32Encoder Global Variables Source: https://madhephaestus.github.io/ESP32Encoder/Encoder_8ino.html Global variables used for tracking encoder instances and their operational states. ```APIDOC ## Variables - **encoder** (ESP32Encoder) - Primary encoder instance. - **encoder2** (ESP32Encoder) - Secondary encoder instance. - **encoder2lastToggled** (unsigned long) - Timestamp of the last toggle event for the second encoder. - **encoder2Paused** (bool) - Flag indicating if the second encoder is currently paused (default: false). ``` -------------------------------- ### Attach Encoder with Full Quadrature Mode Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Attaches the encoder to the specified pins using the full quadrature mode. This mode utilizes both edges of both channel signals for maximum resolution. ```cpp void ESP32Encoder::attachFullQuad(int aPintNumber, int bPinNumber) { attach(aPintNumber, bPinNumber, full); } ``` -------------------------------- ### Internal Interrupt Handler Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp.html Documentation for the static interrupt handler function used for pulse counting. ```APIDOC ## static void IRAM_ATTR pcnt_example_intr_handler(void *arg) ### Description Internal interrupt handler function for the pulse counter (PCNT) peripheral. ### Parameters - **arg** (void *) - Required - Pointer to the encoder instance context. ### References - ESP32Encoder::count - ESP32Encoder::r_enc_config ``` -------------------------------- ### ESP32Encoder Class Methods Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8h_source.html This section details the public methods available in the ESP32Encoder class for controlling and reading encoder values. ```APIDOC ## ESP32Encoder Class Methods ### Description Provides methods to initialize, control, and retrieve data from rotary encoders connected to an ESP32. ### Methods - `ESP32Encoder()`: Constructor for the ESP32Encoder class. - `~ESP32Encoder()`: Destructor for the ESP32Encoder class. - `attachHalfQuad(int aPintNumber, int bPinNumber)`: Attaches an encoder using half quadrature mode. - `attachFullQuad(int aPintNumber, int bPinNumber)`: Attaches an encoder using full quadrature mode. - `attachSingleEdge(int aPintNumber, int bPinNumber)`: Attaches an encoder using single edge mode. - `getCount()`: Retrieves the current count of the encoder. - `clearCount()`: Resets the encoder count to zero. - `pauseCount()`: Pauses the encoder counting. - `resumeCount()`: Resumes the encoder counting. - `isAttached()`: Checks if the encoder is currently attached. - `setCount(int64_t value)`: Sets the encoder count to a specific value. - `setFilter(uint16_t value)`: Sets the filter value for the encoder. - `getCountRaw()`: Retrieves the raw count from the encoder. ### Data Fields - `aPinNumber` (gpio_num_t): GPIO number for the 'A' channel of the encoder. - `bPinNumber` (gpio_num_t): GPIO number for the 'B' channel of the encoder. - `unit` (pcnt_unit_t): The PCNT unit assigned to this encoder. - `fullQuad` (bool): Flag indicating if full quadrature mode is enabled. - `countsMode` (int): The mode for counting encoder steps. - `count` (volatile int64_t): The current accumulated count. - `r_enc_config` (pcnt_config_t): Configuration structure for the PCNT unit. - `useInternalWeakPullResistors` (static enum puType): Specifies the use of internal weak pull resistors. - `attached` (boolean): Status flag indicating if the encoder is attached. - `direction` (bool): Current direction of rotation. - `working` (bool): Status flag indicating if the encoder is operational. - `user_isr_handle` (static pcnt_isr_handle_t): Handle for the user-defined ISR. - `attachedInterrupt` (static bool): Flag indicating if an interrupt is attached. - `encoders` (static ESP32Encoder *[MAX_ESP32_ENCODERS]): Array to hold pointers to all encoder instances. ### Enumerations - `encType`: Defines the quadrature encoding modes (`single`, `half`, `full`). - `puType`: Defines pull-up/pull-down resistor types (`UP`, `DOWN`, `NONE`). ### Macros - `MAX_ESP32_ENCODERS`: Maximum number of encoders supported. ``` -------------------------------- ### void setCount(int64_t value) Source: https://madhephaestus.github.io/ESP32Encoder/classESP32Encoder.html Sets the current count value for the encoder. ```APIDOC ## void setCount(int64_t value) ### Description Sets the current count value for the encoder instance. ### Parameters #### Request Body - **value** (int64_t) - Required - The new count value to set. ``` -------------------------------- ### Enable PCNT Limit Events and Interrupts Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Enables events for maximum and minimum limit values and registers an Interrupt Service Routine (ISR) handler for the PCNT unit. This is crucial for handling encoder rollovers. ```cpp pcnt_event_enable(unit, PCNT_EVT_H_LIM); pcnt_event_enable(unit, PCNT_EVT_L_LIM); /* Register ISR handler and enable interrupts for PCNT unit */ if(attachedInterrupt==false){ attachedInterrupt=true; esp_err_t er = pcnt_isr_register(pcnt_example_intr_handler,(void *) NULL, (int)0, (pcnt_isr_handle_t *)&ESP32Encoder::user_isr_handle); if (er != ESP_OK){ Serial.println("Encoder wrap interrupt failed"); } } pcnt_intr_enable(unit); ``` -------------------------------- ### ESP32Encoder Filter Configuration Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Configures the filter to reduce noise and debounce the encoder signals. ```APIDOC ## ESP32Encoder Filter Configuration ### Description This function allows you to configure the digital filter for the encoder inputs to mitigate noise and debouncing issues. A value of 0 disables the filter. ### Method `setFilter(uint16_t value)` ### Endpoint N/A (Library function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp ESP32Encoder encoder; // Set filter value to 250 (e.g., for runt pulses) encoder.setFilter(250); // Disable the filter // encoder.setFilter(0); ``` ### Response None ### Error Handling None explicitly mentioned. ``` -------------------------------- ### Attach Encoder to Pins Source: https://madhephaestus.github.io/ESP32Encoder/Encoder_8ino_source.html Attaches an ESP32Encoder object to two specified pins for half-quadrature decoding. Ensure these pins are correctly connected to your encoder. ```cpp encoder.attachHalfQuad(19, 18); ``` ```cpp encoder2.attachHalfQuad(17, 16); ``` -------------------------------- ### CESP32Encoder Data Structure Source: https://madhephaestus.github.io/ESP32Encoder/annotated.html Details regarding the primary data structure used for encoder management. ```APIDOC ## Data Structure: CESP32Encoder ### Description The CESP32Encoder structure serves as the primary object for managing encoder instances within the library. ### Members - **CESP32Encoder** (struct) - The main data structure representing an encoder instance. ``` -------------------------------- ### Attach Encoder with Single Edge Mode Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Attaches the encoder to the specified pins using the single edge mode. This mode is simpler and may be suitable for basic counting. ```cpp void ESP32Encoder::attachSingleEdge(int aPintNumber, int bPinNumber) { attach(aPintNumber, bPinNumber, single); } ``` -------------------------------- ### Resume Encoder Counting Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Resumes the PCNT counter after it has been paused. Returns the result of the PCNT resume operation. ```cpp int64_t ESP32Encoder::resumeCount() { return pcnt_counter_resume(unit); } ``` -------------------------------- ### ESP32Encoder Class Data Fields Source: https://madhephaestus.github.io/ESP32Encoder/classESP32Encoder.html This section details the public data fields of the ESP32Encoder class, representing the internal state and configuration of the encoder. ```APIDOC ## ESP32Encoder Class Data Fields ### aPinNumber - **Type:** gpio_num_t - **Description:** The GPIO pin number for input A. ### bPinNumber - **Type:** gpio_num_t - **Description:** The GPIO pin number for input B. ### unit - **Type:** pcnt_unit_t - **Description:** The PCNT unit assigned to this encoder. ### fullQuad - **Type:** bool - **Description:** Flag indicating if full quadrature mode is enabled. ### countsMode - **Type:** int - **Description:** The mode for counting pulses. ### count - **Type:** volatile int64_t - **Description:** The current accumulated count of the encoder. ### r_enc_config - **Type:** pcnt_config_t - **Description:** Configuration structure for the PCNT unit. ``` -------------------------------- ### Resume Encoder Count Source: https://madhephaestus.github.io/ESP32Encoder/Encoder_8ino_source.html Resumes the encoder's counting mechanism after it has been paused. The encoder will continue counting from where it left off. ```cpp encoder2.resumeCount() ``` -------------------------------- ### ESP32Encoder Class Static Public Attributes Source: https://madhephaestus.github.io/ESP32Encoder/classESP32Encoder.html This section details the static public attributes of the ESP32Encoder class, which are shared across all instances of the class. ```APIDOC ## ESP32Encoder Class Static Public Attributes ### encoders - **Type:** ESP32Encoder * - **Description:** Array to hold pointers to all ESP32Encoder instances. ### useInternalWeakPullResistors - **Type:** enum puType - **Description:** Specifies the type of internal weak pull-up resistors to use. ``` -------------------------------- ### Set Encoder Count Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Sets the current encoder count to a specific value. This is done by calculating the difference between the desired value and the raw current count. ```cpp void ESP32Encoder::setCount(int64_t value) { count = value - getCountRaw(); } ``` -------------------------------- ### ESP32Encoder Class Member Functions Source: https://madhephaestus.github.io/ESP32Encoder/classESP32Encoder.html This section details the public member functions of the ESP32Encoder class, which are used to interact with and control rotary encoders. ```APIDOC ## ESP32Encoder Class Member Functions ### attachHalfQuad ```cpp void ESP32Encoder::attachHalfQuad(int _aPintNumber_, int _bPinNumber_) ``` **Description:** Attaches the encoder using half quadrature mode. ### attachFullQuad ```cpp void ESP32Encoder::attachFullQuad(int _aPintNumber_, int _bPinNumber_) ``` **Description:** Attaches the encoder using full quadrature mode. ### attachSingleEdge ```cpp void ESP32Encoder::attachSingleEdge(int _aPintNumber_, int _bPinNumber_) ``` **Description:** Attaches the encoder using single edge mode. ### getCount ```cpp int64_t ESP32Encoder::getCount() ``` **Description:** Retrieves the current count of the encoder. ### clearCount ```cpp int64_t ESP32Encoder::clearCount() ``` **Description:** Clears the current count of the encoder to zero. ### pauseCount ```cpp int64_t ESP32Encoder::pauseCount() ``` **Description:** Pauses the encoder count. ### resumeCount ```cpp int64_t ESP32Encoder::resumeCount() ``` **Description:** Resumes the encoder count. ### isAttached ```cpp bool ESP32Encoder::isAttached() ``` **Description:** Checks if the encoder is currently attached. ### setCount ```cpp void ESP32Encoder::setCount(int64_t value) ``` **Description:** Sets the encoder count to a specific value. ### setFilter ```cpp void ESP32Encoder::setFilter(uint16_t value) ``` **Description:** Sets the filter value for debouncing the encoder signals. ``` -------------------------------- ### Set PCNT Filter Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Sets a filter value to reduce noise and bounces on encoder signals. Disables the filter if the value is 0. ```cpp setFilter(250); // Filter Runt Pulses ``` ```cpp if(value==0) { pcnt_filter_disable(unit); } else { pcnt_set_filter_value(unit, value); pcnt_filter_enable(unit); } ``` -------------------------------- ### ESP32Encoder Class Destructor Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html The destructor for the ESP32Encoder class. Currently empty, but can be used for cleanup if necessary. ```cpp ESP32Encoder::~ESP32Encoder() { } ``` -------------------------------- ### PCNT Interrupt Handler Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Handles interrupts from the PCNT unit. It identifies the source of the interrupt, updates the encoder count, and clears the interrupt status. This function is marked IRAM_ATTR for performance. ```cpp static void IRAM_ATTR pcnt_example_intr_handler(void *arg) { ESP32Encoder * ptr; uint32_t intr_status = PCNT.int_st.val; int i; for (i = 0; i < PCNT_UNIT_MAX; i++) { if (intr_status & (BIT(i))) { ptr = ESP32Encoder::encoders[i]; /* Save the PCNT event type that caused an interrupt to pass it to the main program */ int64_t status=0; if(PCNT.status_unit[i].h_lim_lat){ status=ptr->r_enc_config.counter_h_lim; } if(PCNT.status_unit[i].l_lim_lat){ status=ptr->r_enc_config.counter_l_lim; } //pcnt_counter_clear(ptr->unit); PCNT.int_clr.val = BIT(i); // clear the interrupt ptr->count = status + ptr->count; } } } ``` -------------------------------- ### Clear Encoder Count Source: https://madhephaestus.github.io/ESP32Encoder/Encoder_8ino_source.html Clears the encoder's raw count and resets the tracked count to zero. Use this to reset the encoder's position. ```cpp encoder2.clearCount(); ``` -------------------------------- ### Clear Encoder Count Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Resets the encoder's internal count to zero and clears the PCNT counter. Returns the result of the PCNT clear operation. ```cpp int64_t ESP32Encoder::clearCount() { count = 0; return pcnt_counter_clear(unit); } ``` -------------------------------- ### Pause Encoder Counting Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html Pauses the PCNT counter, stopping further increments or decrements. Returns the result of the PCNT pause operation. ```cpp int64_t ESP32Encoder::pauseCount() { return pcnt_counter_pause(unit); } ``` -------------------------------- ### ISR Handler for PCNT Events Source: https://madhephaestus.github.io/ESP32Encoder/ESP32Encoder_8cpp_source.html An Interrupt Service Routine (ISR) handler for Pulse Counter (PCNT) events. This function is called automatically when a configured PCNT event occurs, such as reaching a limit. ```c static void IRAM_ATTR pcnt_example_intr_handler(void *arg) ``` -------------------------------- ### Pause Encoder Count Source: https://madhephaestus.github.io/ESP32Encoder/Encoder_8ino_source.html Pauses the encoder's counting mechanism. The encoder will not update its count while paused. ```cpp encoder2.pauseCount() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.