Updated button idf_component to 2.3.0

This commit is contained in:
Rohit Jadhav
2022-11-25 14:54:45 +05:30
parent 65da485411
commit 54741bea51
8 changed files with 50 additions and 19 deletions
@@ -28,7 +28,7 @@ esp_err_t iot_button_delete(button_handle_t btn_handle)
return ESP_OK;
}
esp_err_t iot_button_register_cb(button_handle_t btn_handle, button_event_t event, button_cb_t cb)
esp_err_t iot_button_register_cb(button_handle_t btn_handle, button_event_t event, button_cb_t cb, void *usr_data)
{
ESP_LOGI(TAG, "Button register callback");
return ESP_OK;
@@ -25,8 +25,8 @@ extern "C" {
*
*/
typedef struct {
int32_t gpio_num;
uint8_t active_level;
int32_t gpio_num; /**< num of gpio */
uint8_t active_level; /**< gpio level when press down */
} button_gpio_config_t;
/**
@@ -62,4 +62,4 @@ uint8_t button_gpio_get_key_level(void *gpio_num);
}
#endif
#endif
#endif
@@ -21,7 +21,7 @@
extern "C" {
#endif
typedef void (* button_cb_t)(void *);
typedef void (* button_cb_t)(void *button_handle, void *usr_data);
typedef void *button_handle_t;
/**
@@ -32,6 +32,7 @@ typedef enum {
BUTTON_PRESS_DOWN = 0,
BUTTON_PRESS_UP,
BUTTON_PRESS_REPEAT,
BUTTON_PRESS_REPEAT_DONE,
BUTTON_SINGLE_CLICK,
BUTTON_DOUBLE_CLICK,
BUTTON_LONG_PRESS_START,
@@ -55,9 +56,11 @@ typedef enum {
*/
typedef struct {
button_type_t type; /**< button type, The corresponding button configuration must be filled */
uint16_t long_press_time; /**< Trigger time(ms) for long press, if 0 default to BUTTON_LONG_PRESS_TIME_MS */
uint16_t short_press_time; /**< Trigger time(ms) for short press, if 0 default to BUTTON_SHORT_PRESS_TIME_MS */
union {
button_gpio_config_t gpio_button_config; /**< gpio button configuration */
button_adc_config_t adc_button_config; /**< adc button configuration */
button_gpio_config_t gpio_button_config; /**< gpio button configuration */
button_adc_config_t adc_button_config; /**< adc button configuration */
}; /**< button configuration */
} button_config_t;
@@ -87,12 +90,13 @@ esp_err_t iot_button_delete(button_handle_t btn_handle);
* @param btn_handle A button handle to register
* @param event Button event
* @param cb Callback function.
* @param usr_data user data
*
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG Arguments is invalid.
*/
esp_err_t iot_button_register_cb(button_handle_t btn_handle, button_event_t event, button_cb_t cb);
esp_err_t iot_button_register_cb(button_handle_t btn_handle, button_event_t event, button_cb_t cb, void *usr_data);
/**
* @brief Unregister the button event callback function.
@@ -106,6 +110,15 @@ esp_err_t iot_button_register_cb(button_handle_t btn_handle, button_event_t even
*/
esp_err_t iot_button_unregister_cb(button_handle_t btn_handle, button_event_t event);
/**
* @brief how many Callbacks are still registered.
*
* @param btn_handle A button handle to unregister
*
* @return 0 if no callbacks registered, or 1 .. (BUTTON_EVENT_MAX-1) for the number of Registered Buttons.
*/
size_t iot_button_count_cb(button_handle_t btn_handle);
/**
* @brief Get button event
*
@@ -124,6 +137,24 @@ button_event_t iot_button_get_event(button_handle_t btn_handle);
*/
uint8_t iot_button_get_repeat(button_handle_t btn_handle);
/**
* @brief Get button ticks time
*
* @param btn_handle Button handle
*
* @return Actual time from press down to up (ms).
*/
uint16_t iot_button_get_ticks_time(button_handle_t btn_handle);
/**
* @brief Get button long press hold count
*
* @param btn_handle Button handle
*
* @return Count of trigger cb(BUTTON_LONG_PRESS_HOLD)
*/
uint16_t iot_button_get_long_press_hold_cnt(button_handle_t btn_handle);
#ifdef __cplusplus
}
#endif
@@ -1,3 +1,3 @@
## IDF Component Manager Manifest File
dependencies:
espressif/button: "=2.0.1"
espressif/button: "=2.3.0"
+4 -4
View File
@@ -17,7 +17,7 @@
static const char *TAG = "app_reset";
static bool perform_factory_reset = false;
static void button_factory_reset_pressed_cb(void *arg)
static void button_factory_reset_pressed_cb(void *arg, void *data)
{
if (!perform_factory_reset) {
ESP_LOGI(TAG, "Factory reset triggered. Release the button to start factory reset.");
@@ -25,7 +25,7 @@ static void button_factory_reset_pressed_cb(void *arg)
}
}
static void button_factory_reset_released_cb(void *arg)
static void button_factory_reset_released_cb(void *arg, void *data)
{
if (perform_factory_reset) {
ESP_LOGI(TAG, "Starting factory reset");
@@ -42,7 +42,7 @@ esp_err_t app_reset_button_register(void *handle)
}
button_handle_t button_handle = (button_handle_t)handle;
esp_err_t err = ESP_OK;
err |= iot_button_register_cb(button_handle, BUTTON_LONG_PRESS_HOLD, button_factory_reset_pressed_cb);
err |= iot_button_register_cb(button_handle, BUTTON_PRESS_UP, button_factory_reset_released_cb);
err |= iot_button_register_cb(button_handle, BUTTON_LONG_PRESS_HOLD, button_factory_reset_pressed_cb, NULL);
err |= iot_button_register_cb(button_handle, BUTTON_PRESS_UP, button_factory_reset_released_cb, NULL);
return err;
}
+2 -2
View File
@@ -52,7 +52,7 @@ static esp_err_t app_driver_light_set_temperature(led_driver_handle_t handle, es
return led_driver_set_temperature(handle, value);
}
static void app_driver_button_toggle_cb(void *arg)
static void app_driver_button_toggle_cb(void *arg, void *data)
{
ESP_LOGI(TAG, "Toggle button pressed");
uint16_t endpoint_id = light_endpoint_id;
@@ -158,6 +158,6 @@ app_driver_handle_t app_driver_button_init()
/* Initialize button */
button_config_t config = button_driver_get_config();
button_handle_t handle = iot_button_create(&config);
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb);
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL);
return (app_driver_handle_t)handle;
}
+2 -2
View File
@@ -563,7 +563,7 @@ void app_driver_client_group_command_callback(uint8_t fabric_index, client::comm
}
}
static void app_driver_button_toggle_cb(void *arg)
static void app_driver_button_toggle_cb(void *arg, void *data)
{
ESP_LOGI(TAG, "Toggle button pressed");
client::command_handle_t cmd_handle;
@@ -581,7 +581,7 @@ app_driver_handle_t app_driver_switch_init()
/* Initialize button */
button_config_t config = button_driver_get_config();
button_handle_t handle = iot_button_create(&config);
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb);
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL);
/* Other initializations */
#if CONFIG_ENABLE_CHIP_SHELL
+2 -2
View File
@@ -54,7 +54,7 @@ static esp_err_t app_driver_light_set_temperature(led_driver_handle_t handle, es
return led_driver_set_temperature(handle, value);
}
static void app_driver_button_toggle_cb(void *arg)
static void app_driver_button_toggle_cb(void *arg, void *data)
{
ESP_LOGI(TAG, "Toggle button pressed");
uint16_t endpoint_id = light_endpoint_id;
@@ -163,6 +163,6 @@ app_driver_handle_t app_driver_button_init()
/* Initialize button */
button_config_t config = button_driver_get_config();
button_handle_t handle = iot_button_create(&config);
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb);
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL);
return (app_driver_handle_t)handle;
}