Code: Select all
static void button_single_click_cb(void *arg, void *usr_data) {
RotaryEncoderConfig *config = (RotaryEncoderConfig *)usr_data;
ESP_LOGI(TAG, "Button %lu single click", config->led_channel_index);
free(usr_data);
}
void setup_buttons() {
ESP_LOGI(TAG, "Initializing rotary encoder buttons.");
for (uint8_t index = 0; index < LEDC_TEST_CH_NUM; index++) {
button_config_t gpio_btn_cfg = {
.type = BUTTON_TYPE_GPIO,
.long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS,
.short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS,
.gpio_button_config = {
.gpio_num = rotaryEncoderConfigs[index].gpio_sw,
.active_level = BUTTON_ACTIVE_LEVEL,
},
};
ESP_LOGI(TAG, "Registering button index %d", index);
button_handle_t gpio_btn = iot_button_create(&gpio_btn_cfg);
if(NULL == gpio_btn) {
ESP_LOGE(TAG, "Button create failed");
} else {
RotaryEncoderConfig *channel = &rotaryEncoderConfigs[index];
ESP_LOGI(TAG, "Registering button callbacks for index %d", index);
iot_button_register_cb(gpio_btn, BUTTON_SINGLE_CLICK, button_single_click_cb, channel);
}
}
}