From 54741bea51c375e1f44fcea94ba24eb77d394d0c Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Fri, 25 Nov 2022 14:54:45 +0530 Subject: [PATCH] Updated button idf_component to 2.3.0 --- .../button/hollow_button/button_driver.c | 2 +- .../button/include/button_gpio.h | 6 +-- .../button_driver/button/include/iot_button.h | 39 +++++++++++++++++-- .../iot_button/idf_component.yml | 2 +- examples/common/app_reset/app_reset.cpp | 8 ++-- examples/light/main/app_driver.cpp | 4 +- examples/light_switch/main/app_driver.cpp | 4 +- examples/zap_light/main/app_driver.cpp | 4 +- 8 files changed, 50 insertions(+), 19 deletions(-) diff --git a/device_hal/button_driver/button/hollow_button/button_driver.c b/device_hal/button_driver/button/hollow_button/button_driver.c index dc99d059d..f4e778cd0 100644 --- a/device_hal/button_driver/button/hollow_button/button_driver.c +++ b/device_hal/button_driver/button/hollow_button/button_driver.c @@ -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; diff --git a/device_hal/button_driver/button/include/button_gpio.h b/device_hal/button_driver/button/include/button_gpio.h index 78bb98564..f5d0b5065 100644 --- a/device_hal/button_driver/button/include/button_gpio.h +++ b/device_hal/button_driver/button/include/button_gpio.h @@ -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 \ No newline at end of file +#endif diff --git a/device_hal/button_driver/button/include/iot_button.h b/device_hal/button_driver/button/include/iot_button.h index 7c68e4a0f..a50976fa6 100644 --- a/device_hal/button_driver/button/include/iot_button.h +++ b/device_hal/button_driver/button/include/iot_button.h @@ -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 diff --git a/device_hal/button_driver/iot_button/idf_component.yml b/device_hal/button_driver/iot_button/idf_component.yml index 3a5ffd6b4..d8018ad8a 100644 --- a/device_hal/button_driver/iot_button/idf_component.yml +++ b/device_hal/button_driver/iot_button/idf_component.yml @@ -1,3 +1,3 @@ ## IDF Component Manager Manifest File dependencies: - espressif/button: "=2.0.1" \ No newline at end of file + espressif/button: "=2.3.0" diff --git a/examples/common/app_reset/app_reset.cpp b/examples/common/app_reset/app_reset.cpp index a84e79d55..2fc29380e 100644 --- a/examples/common/app_reset/app_reset.cpp +++ b/examples/common/app_reset/app_reset.cpp @@ -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; } diff --git a/examples/light/main/app_driver.cpp b/examples/light/main/app_driver.cpp index 3cb25951b..17cbc7acf 100644 --- a/examples/light/main/app_driver.cpp +++ b/examples/light/main/app_driver.cpp @@ -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; } diff --git a/examples/light_switch/main/app_driver.cpp b/examples/light_switch/main/app_driver.cpp index 155d72594..013ef344c 100644 --- a/examples/light_switch/main/app_driver.cpp +++ b/examples/light_switch/main/app_driver.cpp @@ -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 diff --git a/examples/zap_light/main/app_driver.cpp b/examples/zap_light/main/app_driver.cpp index a2527d18f..f5b8ae0c1 100644 --- a/examples/zap_light/main/app_driver.cpp +++ b/examples/zap_light/main/app_driver.cpp @@ -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; }