feat: added encoder positive rotation select
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
.a_gpio_number = GPIO_NUM_MAX, \
|
||||
.b_gpio_number = GPIO_NUM_MAX, \
|
||||
.pullup = true, \
|
||||
.rotation = true, \
|
||||
.encoder_pulses = 0}
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -33,6 +34,7 @@ extern "C"
|
||||
uint8_t a_gpio_number; /*!< Encoder A GPIO number. */
|
||||
uint8_t b_gpio_number; /*!< Encoder B GPIO number. */
|
||||
bool pullup; /*!< Pullup GPIO enable/disable. */
|
||||
bool rotation; /*!< Encoder rotation (true - positive for CW rotation, false - positive for CCW rotation). */
|
||||
uint16_t encoder_pulses; /*!< Number of pulses per one rotation. */
|
||||
} zh_inclinometer_init_config_t;
|
||||
|
||||
@@ -45,6 +47,7 @@ extern "C"
|
||||
pcnt_channel_handle_t pcnt_channel_a_handle; /*!< Inclinometer unique pcnt channel handle. */
|
||||
pcnt_channel_handle_t pcnt_channel_b_handle; /*!< Inclinometer unique pcnt channel handle. */
|
||||
float degrees_per_pulse; /*!< Number of degrees per pulse. */
|
||||
bool rotation; /*!< Encoder rotation. */
|
||||
bool is_initialized; /*!< Inclinometer initialization flag. */
|
||||
} zh_inclinometer_handle_t;
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
2.0.0
|
||||
2.1.0
|
||||
@@ -26,6 +26,7 @@ esp_err_t zh_inclinometer_init(const zh_inclinometer_init_config_t *config, zh_i
|
||||
err = _zh_inclinometer_pcnt_init(config, handle);
|
||||
ZH_ERROR_CHECK(err == ESP_OK, err, NULL, "Inclinometer initialization failed. PCNT initialization failed.");
|
||||
handle->degrees_per_pulse = 360.0 / config->encoder_pulses;
|
||||
handle->rotation = config->rotation;
|
||||
handle->is_initialized = true;
|
||||
ZH_LOGI("Inclinometer initialization completed successfully.");
|
||||
return ESP_OK;
|
||||
@@ -54,7 +55,7 @@ esp_err_t zh_inclinometer_get(zh_inclinometer_handle_t *handle, float *angle)
|
||||
int pcnt_count = 0;
|
||||
pcnt_unit_get_count(handle->pcnt_unit_handle, &pcnt_count);
|
||||
float angle_temp = pcnt_count * handle->degrees_per_pulse;
|
||||
*angle = (angle_temp < 0) ? -angle_temp : angle_temp;
|
||||
*angle = (handle->rotation == true) ? angle_temp : -angle_temp;
|
||||
ZH_LOGI("Inclinometer get position completed successfully.");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user