ChaosDMX
Open-Source DMX-Interface
Loading...
Searching...
No Matches
button_actions.c File Reference

Dynamic hardware button execution mapped directly to app configuration. More...

#include "button_actions.h"
#include "button_gpio.h"
#include "config.h"
#include "driver/gpio.h"
#include "esp_system.h"
#include "iot_button.h"
#include "led.h"
#include "logger.h"
Include dependency graph for button_actions.c:

Go to the source code of this file.

Macros

#define LOG_TAG   "BUTTON"
 Logging tag for the button actions component.
#define BUTTON_GPIO_NUM   GPIO_NUM_5
 GPIO number assigned to the hardware button.
#define RESET_HOLD_TIME_MS   3000
 Duration (ms) the button must be held for a reset trigger.

Functions

static void execute_button_action (config_button_action_t assigned_action)
 Executes the action compiled into the configuration for the triggered event.
static void iot_button_single_click_cb (void *arg, void *usr_data)
 Callback for single click events.
static void iot_button_double_click_cb (void *arg, void *usr_data)
 Callback for double click events.
static void iot_button_multiple_click_cb (void *arg, void *usr_data)
 Callback for multiple click events.
esp_err_t button_init (void)
 Initializes the hardware button configuration and event callbacks.
bool button_is_pressed (void)
 Checks if the button is currently physically pressed.

Variables

static button_handle_t s_btn_handle = NULL
 Internal handle for the IoT button instance.

Detailed Description

Dynamic hardware button execution mapped directly to app configuration.

Definition in file button_actions.c.

Macro Definition Documentation

◆ BUTTON_GPIO_NUM

#define BUTTON_GPIO_NUM   GPIO_NUM_5

GPIO number assigned to the hardware button.

Definition at line 24 of file button_actions.c.

Referenced by button_init().

◆ LOG_TAG

#define LOG_TAG   "BUTTON"

Logging tag for the button actions component.

Definition at line 10 of file button_actions.c.

◆ RESET_HOLD_TIME_MS

#define RESET_HOLD_TIME_MS   3000

Duration (ms) the button must be held for a reset trigger.

Definition at line 29 of file button_actions.c.

Referenced by button_init().

Function Documentation

◆ button_init()

esp_err_t button_init ( void )

Initializes the hardware button configuration and event callbacks.

Configures the designated GPIO pin, sets up the debounce thresholds, and registers callbacks for both a single/double/triple short click

Returns
  • ESP_OK: Success
  • ESP_FAIL: Failed to initialize the button or register callbacks

Definition at line 120 of file button_actions.c.

References BUTTON_GPIO_NUM, iot_button_double_click_cb(), iot_button_multiple_click_cb(), iot_button_single_click_cb(), LOGE, LOGI, RESET_HOLD_TIME_MS, and s_btn_handle.

Referenced by app_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ button_is_pressed()

bool button_is_pressed ( void )

Checks if the button is currently physically pressed.

Returns
true if pressed (active level), false otherwise.

Definition at line 163 of file button_actions.c.

References s_btn_handle.

Referenced by app_main().

Here is the caller graph for this function:

◆ execute_button_action()

void execute_button_action ( config_button_action_t assigned_action)
static

Executes the action compiled into the configuration for the triggered event.

This evaluates the current NVS/RAM configuration dynamically on every click, making it fully hot-swappable from the Web UI without registering callbacks.

Parameters
assigned_actionThe configured action to execute.

Definition at line 45 of file button_actions.c.

References APP_BUTTON_ACTION_NONE, APP_BUTTON_ACTION_REBOOT, APP_BUTTON_ACTION_TOGGLE_LED, config_get_led_brightness(), config_save(), config_set_led_brightness(), and LOGI.

Referenced by iot_button_double_click_cb(), iot_button_multiple_click_cb(), and iot_button_single_click_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iot_button_double_click_cb()

void iot_button_double_click_cb ( void * arg,
void * usr_data )
static

Callback for double click events.

Parameters
argPointer to the button handle (unused).
usr_dataUser data passed during registration (unused).

Definition at line 101 of file button_actions.c.

References APP_BUTTON_EVENT_DOUBLE_CLICK, config_get_button_action(), execute_button_action(), and LOGI.

Referenced by button_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iot_button_multiple_click_cb()

void iot_button_multiple_click_cb ( void * arg,
void * usr_data )
static

Callback for multiple click events.

Parameters
argPointer to the button handle (unused).
usr_dataUser data passed during registration (unused).

Definition at line 112 of file button_actions.c.

References APP_BUTTON_EVENT_MULTIPLE_CLICK, config_get_button_action(), execute_button_action(), and LOGI.

Referenced by button_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iot_button_single_click_cb()

void iot_button_single_click_cb ( void * arg,
void * usr_data )
static

Callback for single click events.

Parameters
argPointer to the button handle (unused).
usr_dataUser data passed during registration (unused).

Definition at line 90 of file button_actions.c.

References APP_BUTTON_EVENT_SINGLE_CLICK, config_get_button_action(), execute_button_action(), and LOGI.

Referenced by button_init().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ s_btn_handle

button_handle_t s_btn_handle = NULL
static

Internal handle for the IoT button instance.

Definition at line 34 of file button_actions.c.

Referenced by button_init(), and button_is_pressed().