Skip to content

Commit

Permalink
Update example with acceleration.
Browse files Browse the repository at this point in the history
Update documentation of rotary_encoder_enable_acceleration and rotary_encoder_disable_acceleration functions
  • Loading branch information
NemesisXB committed May 14, 2024
1 parent ae09378 commit e844783
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions components/encoder/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,15 @@ esp_err_t rotary_encoder_remove(rotary_encoder_t *re)

esp_err_t rotary_encoder_enable_acceleration(rotary_encoder_t *re, uint16_t coeff)
{
CHECK_ARG(re);
re->acceleration.coeff = coeff;
re->acceleration.last_time = esp_timer_get_time();
return ESP_OK;
}

esp_err_t rotary_encoder_disable_acceleration(rotary_encoder_t *re)
{
CHECK_ARG(re);
re->acceleration.coeff = 0;
return ESP_OK;
}
14 changes: 14 additions & 0 deletions components/encoder/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,23 @@ esp_err_t rotary_encoder_add(rotary_encoder_t *re);
*/
esp_err_t rotary_encoder_remove(rotary_encoder_t *re);

/**
* @brief Enable acceleration on the rotary encoder
*
* @param re Encoder descriptor
* @param coeff Acceleration coefficient. Higher value means faster acceleration
* @return esp_err_t
*/
esp_err_t rotary_encoder_enable_acceleration(rotary_encoder_t *re, uint16_t coeff);

/**
* @brief Disable acceleration on the rotary encoder
*
* @param re Encoder descriptor
* @return `ESP_OK` on success
*/
esp_err_t rotary_encoder_disable_acceleration(rotary_encoder_t *re);

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions examples/encoder/default/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ void test(void *arg)
break;
case RE_ET_BTN_CLICKED:
ESP_LOGI(TAG, "Button clicked");
rotary_encoder_enable_acceleration(&re, 100);
ESP_LOGI(TAG, "Acceleration enabled");
break;
case RE_ET_BTN_LONG_PRESSED:
ESP_LOGI(TAG, "Looooong pressed button");
rotary_encoder_disable_acceleration(&re);
ESP_LOGI(TAG, "Acceleration disabled");
break;
case RE_ET_CHANGED:
val += e.diff;
Expand Down

0 comments on commit e844783

Please sign in to comment.