10#define LOG_TAG "BUTTON"
13#include "button_gpio.h"
15#include "driver/gpio.h"
16#include "esp_system.h"
17#include "iot_button.h"
24#define BUTTON_GPIO_NUM GPIO_NUM_5
29#define RESET_HOLD_TIME_MS 3000
46 switch (assigned_action) {
48 LOGI(
"Button action: Toggle LED Brightness");
52 static const uint8_t levels[] = {0, 1, 20, 100, 255};
53 const uint8_t num_levels =
sizeof(levels) /
sizeof(levels[0]);
56 uint8_t next_brightness = levels[0];
58 for (uint8_t i = 0; i < num_levels; i++) {
59 if (current_brightness < levels[i]) {
60 next_brightness = levels[i];
71 LOGI(
"Button action: Reboot");
78 LOGI(
"No action or APP_BUTTON_ACTION_NONE assigned to this event.");
91 LOGI(
"Single click detected.");
102 LOGI(
"Double click detected.");
113 LOGI(
"Multiple click detected.");
121 LOGI(
"Initializing runtime-configurable hardware button handler...");
124 button_config_t btn_cfg = {
129 button_gpio_config_t gpio_cfg = {
136 iot_button_new_gpio_device(&btn_cfg, &gpio_cfg, &
s_btn_handle);
138 LOGE(
"Failed to instantiate IoT button driver!");
146 static button_event_args_t multi_args = {.multiple_clicks = {.clicks = 3}};
148 ESP_ERROR_CHECK(iot_button_register_cb(
s_btn_handle, BUTTON_SINGLE_CLICK,
151 ESP_ERROR_CHECK(iot_button_register_cb(
s_btn_handle, BUTTON_DOUBLE_CLICK,
155 ESP_ERROR_CHECK(iot_button_register_cb(
s_btn_handle, BUTTON_MULTIPLE_CLICK,
159 LOGI(
"Dynamic button router successfully running.");
Thread-safe configuration component utilizing NVS for ESP32.
bool config_set_led_brightness(uint8_t brightness)
Sets the status LED brightness level in RAM.
config_button_action_t
Actions that can be dynamically assigned to button events.
@ APP_BUTTON_ACTION_REBOOT
@ APP_BUTTON_ACTION_TOGGLE_LED
uint8_t config_get_led_brightness(void)
Gets the current status LED brightness level.
@ APP_BUTTON_EVENT_SINGLE_CLICK
@ APP_BUTTON_EVENT_MULTIPLE_CLICK
@ APP_BUTTON_EVENT_DOUBLE_CLICK
config_button_action_t config_get_button_action(app_button_event_t event)
Retrieves the action assigned to a specific button event.
esp_err_t config_save(void)
Flushes all staged RAM changes permanently to the non-volatile storage.
LED control component with flexible blinking and breathing modes.
Project-wide logging macros based on ESP-IDF's logging library.
#define LOGI(...)
Log a message at Info level.
#define LOGE(...)
Log a message at Error level.