This commit is contained in:
2025-06-14 08:33:02 +03:00
parent 1b872f8b82
commit db0e997aad
2 changed files with 167 additions and 10 deletions

View File

@@ -23,6 +23,33 @@ extern "C"
{
#endif
typedef int32_t rotary_encoder_position_t;
// /**
// * @brief Enum representing the direction of rotation.
// */
typedef enum
{
ROTARY_ENCODER_DIRECTION_NOT_SET = 0, ///< Direction not yet known (stationary since reset)
ROTARY_ENCODER_DIRECTION_CLOCKWISE,
ROTARY_ENCODER_DIRECTION_COUNTER_CLOCKWISE,
} rotary_encoder_direction_t;
// // Used internally
// ///@cond INTERNAL
#define TABLE_COLS 4
typedef uint8_t table_row_t[TABLE_COLS];
// ///@endcond
// /**
// * @brief Struct represents the current state of the device in terms of incremental position and direction of last movement
// */
typedef struct
{
rotary_encoder_position_t position; ///< Numerical position since reset. This value increments on clockwise rotation, and decrements on counter-clockewise rotation. Counts full or half steps depending on mode. Set to zero on reset.
rotary_encoder_direction_t direction; ///< Direction of last movement. Set to NOT_SET on reset.
} rotary_encoder_state_t;
typedef struct // Structure for initial initialization of encoder.
{
uint8_t task_priority; // Task priority for the encoder isr processing. @note It is not recommended to set a value less than 10.
@@ -47,6 +74,9 @@ extern "C"
uint8_t encoder_number; // Encoder unique number.
bool is_initialized; // Encoder initialization flag.
const table_row_t *table; ///< Pointer to active state transition table
uint8_t table_state; ///< Internal state
volatile rotary_encoder_state_t state; ///< Device state
} zh_encoder_handle_t;
ESP_EVENT_DECLARE_BASE(ZH_ENCODER);
@@ -115,9 +145,9 @@ extern "C"
// typedef int32_t rotary_encoder_position_t;
// /**
// * @brief Enum representing the direction of rotation.
// */
// // /**
// // * @brief Enum representing the direction of rotation.
// // */
// typedef enum
// {
// ROTARY_ENCODER_DIRECTION_NOT_SET = 0, ///< Direction not yet known (stationary since reset)
@@ -125,15 +155,15 @@ extern "C"
// ROTARY_ENCODER_DIRECTION_COUNTER_CLOCKWISE,
// } rotary_encoder_direction_t;
// // Used internally
// ///@cond INTERNAL
// // // Used internally
// // ///@cond INTERNAL
// #define TABLE_COLS 4
// typedef uint8_t table_row_t[TABLE_COLS];
// ///@endcond
// // ///@endcond
// /**
// * @brief Struct represents the current state of the device in terms of incremental position and direction of last movement
// */
// // /**
// // * @brief Struct represents the current state of the device in terms of incremental position and direction of last movement
// // */
// typedef struct
// {
// rotary_encoder_position_t position; ///< Numerical position since reset. This value increments on clockwise rotation, and decrements on counter-clockewise rotation. Counts full or half steps depending on mode. Set to zero on reset.