diff --git a/examples/fan/main/app_driver.c b/examples/fan/main/app_driver.c index 277ebb7..d79e876 100644 --- a/examples/fan/main/app_driver.c +++ b/examples/fan/main/app_driver.c @@ -10,9 +10,10 @@ #include #include +#include #include -#include -#include +#include +#include #include #include @@ -63,7 +64,7 @@ esp_err_t app_fan_init(void) return ESP_OK; } -static void push_btn_cb(void *arg) +static void push_btn_cb(void *arg, void *data) { uint8_t old_speed = g_speed; g_speed++; @@ -90,10 +91,19 @@ static void push_btn_cb(void *arg) void app_driver_init() { app_fan_init(); - button_handle_t btn_handle = iot_button_create(BUTTON_GPIO, BUTTON_ACTIVE_LEVEL); - if (btn_handle) { - /* Register a callback for a button tap (short press) event */ - iot_button_set_evt_cb(btn_handle, BUTTON_CB_TAP, push_btn_cb, NULL); + button_config_t btn_cfg = { + .long_press_time = 0, /* Use default */ + .short_press_time = 0, /* Use default */ + }; + button_gpio_config_t gpio_cfg = { + .gpio_num = BUTTON_GPIO, + .active_level = BUTTON_ACTIVE_LEVEL, + .enable_power_save = false, + }; + button_handle_t btn_handle = NULL; + if (iot_button_new_gpio_device(&btn_cfg, &gpio_cfg, &btn_handle) == ESP_OK && btn_handle) { + /* Register a callback for a button single click event */ + iot_button_register_cb(btn_handle, BUTTON_SINGLE_CLICK, NULL, push_btn_cb, NULL); /* Register Wi-Fi reset and factory reset functionality on same button */ app_reset_button_register(btn_handle, WIFI_RESET_BUTTON_TIMEOUT, FACTORY_RESET_BUTTON_TIMEOUT); } diff --git a/examples/fan/main/idf_component.yml b/examples/fan/main/idf_component.yml index 745e5de..cd369eb 100644 --- a/examples/fan/main/idf_component.yml +++ b/examples/fan/main/idf_component.yml @@ -6,3 +6,5 @@ dependencies: espressif/esp_rainmaker: version: ">=1.0" override_path: '../../../components/esp_rainmaker/' + espressif/button: + version: "^4.1.4" diff --git a/examples/homekit_switch/main/app_driver.c b/examples/homekit_switch/main/app_driver.c index 04a18ec..320f30b 100644 --- a/examples/homekit_switch/main/app_driver.c +++ b/examples/homekit_switch/main/app_driver.c @@ -1,5 +1,5 @@ /* Switch demo implementation using button and RGB LED - + This example code is in the Public Domain (or CC0 licensed, at your option.) Unless required by applicable law or agreed to in writing, this @@ -10,8 +10,9 @@ #include #include +#include #include -#include +#include #include #include @@ -47,7 +48,7 @@ static void app_indicator_init(void) ws2812_led_init(); app_indicator_set(g_power_state); } -static void push_btn_cb(void *arg) +static void push_btn_cb(void *arg, void *data) { bool new_state = !g_power_state; app_driver_set_state(new_state); @@ -65,10 +66,19 @@ static void set_power_state(bool target) void app_driver_init() { - button_handle_t btn_handle = iot_button_create(BUTTON_GPIO, BUTTON_ACTIVE_LEVEL); - if (btn_handle) { - /* Register a callback for a button tap (short press) event */ - iot_button_set_evt_cb(btn_handle, BUTTON_CB_TAP, push_btn_cb, NULL); + button_config_t btn_cfg = { + .long_press_time = 0, /* Use default */ + .short_press_time = 0, /* Use default */ + }; + button_gpio_config_t gpio_cfg = { + .gpio_num = BUTTON_GPIO, + .active_level = BUTTON_ACTIVE_LEVEL, + .enable_power_save = false, + }; + button_handle_t btn_handle = NULL; + if (iot_button_new_gpio_device(&btn_cfg, &gpio_cfg, &btn_handle) == ESP_OK && btn_handle) { + /* Register a callback for a button single click event */ + iot_button_register_cb(btn_handle, BUTTON_SINGLE_CLICK, NULL, push_btn_cb, NULL); /* Register Wi-Fi reset and factory reset functionality on same button */ app_reset_button_register(btn_handle, WIFI_RESET_BUTTON_TIMEOUT, FACTORY_RESET_BUTTON_TIMEOUT); } diff --git a/examples/homekit_switch/main/idf_component.yml b/examples/homekit_switch/main/idf_component.yml index 745e5de..cd369eb 100644 --- a/examples/homekit_switch/main/idf_component.yml +++ b/examples/homekit_switch/main/idf_component.yml @@ -6,3 +6,5 @@ dependencies: espressif/esp_rainmaker: version: ">=1.0" override_path: '../../../components/esp_rainmaker/' + espressif/button: + version: "^4.1.4" diff --git a/examples/led_light/main/app_driver.c b/examples/led_light/main/app_driver.c index 2792383..04a2f21 100644 --- a/examples/led_light/main/app_driver.c +++ b/examples/led_light/main/app_driver.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -121,7 +122,7 @@ esp_err_t app_light_set_saturation(uint16_t saturation) return app_light_set_led(g_hue, g_saturation, g_value); } -static void push_btn_cb(void *arg) +static void push_btn_cb(void *arg, void *data) { app_light_set_power(!g_power); esp_rmaker_param_update_and_report( @@ -132,10 +133,19 @@ static void push_btn_cb(void *arg) void app_driver_init() { app_light_init(); - button_handle_t btn_handle = iot_button_create(BUTTON_GPIO, BUTTON_ACTIVE_LEVEL); - if (btn_handle) { - /* Register a callback for a button tap (short press) event */ - iot_button_set_evt_cb(btn_handle, BUTTON_CB_TAP, push_btn_cb, NULL); + button_config_t btn_cfg = { + .long_press_time = 0, /* Use default */ + .short_press_time = 0, /* Use default */ + }; + button_gpio_config_t gpio_cfg = { + .gpio_num = BUTTON_GPIO, + .active_level = BUTTON_ACTIVE_LEVEL, + .enable_power_save = false, + }; + button_handle_t btn_handle = NULL; + if (iot_button_new_gpio_device(&btn_cfg, &gpio_cfg, &btn_handle) == ESP_OK && btn_handle) { + /* Register a callback for a button single click event */ + iot_button_register_cb(btn_handle, BUTTON_SINGLE_CLICK, NULL, push_btn_cb, NULL); /* Register Wi-Fi reset and factory reset functionality on same button */ app_reset_button_register(btn_handle, WIFI_RESET_BUTTON_TIMEOUT, FACTORY_RESET_BUTTON_TIMEOUT); } diff --git a/examples/led_light/main/idf_component.yml b/examples/led_light/main/idf_component.yml index 745e5de..cd369eb 100644 --- a/examples/led_light/main/idf_component.yml +++ b/examples/led_light/main/idf_component.yml @@ -6,3 +6,5 @@ dependencies: espressif/esp_rainmaker: version: ">=1.0" override_path: '../../../components/esp_rainmaker/' + espressif/button: + version: "^4.1.4" diff --git a/examples/multi_device/main/app_driver.c b/examples/multi_device/main/app_driver.c index 89c6ebe..d7ea2d4 100644 --- a/examples/multi_device/main/app_driver.c +++ b/examples/multi_device/main/app_driver.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -83,7 +84,7 @@ static void app_indicator_init(void) app_indicator_set(g_power_state); } -static void push_btn_cb(void *arg) +static void push_btn_cb(void *arg, void *data) { bool new_state = !g_power_state; app_driver_set_state(new_state); @@ -100,10 +101,19 @@ static void set_power_state(bool target) void app_driver_init() { - button_handle_t btn_handle = iot_button_create(BUTTON_GPIO, BUTTON_ACTIVE_LEVEL); - if (btn_handle) { - /* Register a callback for a button tap (short press) event */ - iot_button_set_evt_cb(btn_handle, BUTTON_CB_TAP, push_btn_cb, NULL); + button_config_t btn_cfg = { + .long_press_time = 0, /* Use default */ + .short_press_time = 0, /* Use default */ + }; + button_gpio_config_t gpio_cfg = { + .gpio_num = BUTTON_GPIO, + .active_level = BUTTON_ACTIVE_LEVEL, + .enable_power_save = false, + }; + button_handle_t btn_handle = NULL; + if (iot_button_new_gpio_device(&btn_cfg, &gpio_cfg, &btn_handle) == ESP_OK && btn_handle) { + /* Register a callback for a button single click event */ + iot_button_register_cb(btn_handle, BUTTON_SINGLE_CLICK, NULL, push_btn_cb, NULL); /* Register Wi-Fi reset and factory reset functionality on same button */ app_reset_button_register(btn_handle, WIFI_RESET_BUTTON_TIMEOUT, FACTORY_RESET_BUTTON_TIMEOUT); } diff --git a/examples/multi_device/main/idf_component.yml b/examples/multi_device/main/idf_component.yml index 745e5de..cd369eb 100644 --- a/examples/multi_device/main/idf_component.yml +++ b/examples/multi_device/main/idf_component.yml @@ -6,3 +6,5 @@ dependencies: espressif/esp_rainmaker: version: ">=1.0" override_path: '../../../components/esp_rainmaker/' + espressif/button: + version: "^4.1.4" diff --git a/examples/switch/main/app_driver.c b/examples/switch/main/app_driver.c index e62e99a..4eb8176 100644 --- a/examples/switch/main/app_driver.c +++ b/examples/switch/main/app_driver.c @@ -1,5 +1,5 @@ /* Switch demo implementation using button and RGB LED - + This example code is in the Public Domain (or CC0 licensed, at your option.) Unless required by applicable law or agreed to in writing, this @@ -10,8 +10,9 @@ #include #include +#include #include -#include +#include #include #include @@ -47,7 +48,7 @@ static void app_indicator_init(void) ws2812_led_init(); app_indicator_set(g_power_state); } -static void push_btn_cb(void *arg) +static void push_btn_cb(void *arg, void *data) { bool new_state = !g_power_state; app_driver_set_state(new_state); @@ -82,10 +83,19 @@ static void set_power_state(bool target) void app_driver_init() { - button_handle_t btn_handle = iot_button_create(BUTTON_GPIO, BUTTON_ACTIVE_LEVEL); - if (btn_handle) { - /* Register a callback for a button tap (short press) event */ - iot_button_set_evt_cb(btn_handle, BUTTON_CB_TAP, push_btn_cb, NULL); + button_config_t btn_cfg = { + .long_press_time = 0, /* Use default */ + .short_press_time = 0, /* Use default */ + }; + button_gpio_config_t gpio_cfg = { + .gpio_num = BUTTON_GPIO, + .active_level = BUTTON_ACTIVE_LEVEL, + .enable_power_save = false, + }; + button_handle_t btn_handle = NULL; + if (iot_button_new_gpio_device(&btn_cfg, &gpio_cfg, &btn_handle) == ESP_OK && btn_handle) { + /* Register a callback for a button single click event */ + iot_button_register_cb(btn_handle, BUTTON_SINGLE_CLICK, NULL, push_btn_cb, NULL); /* Register Wi-Fi reset and factory reset functionality on same button */ app_reset_button_register(btn_handle, WIFI_RESET_BUTTON_TIMEOUT, FACTORY_RESET_BUTTON_TIMEOUT); } diff --git a/examples/switch/main/idf_component.yml b/examples/switch/main/idf_component.yml index 745e5de..cd369eb 100644 --- a/examples/switch/main/idf_component.yml +++ b/examples/switch/main/idf_component.yml @@ -6,3 +6,5 @@ dependencies: espressif/esp_rainmaker: version: ">=1.0" override_path: '../../../components/esp_rainmaker/' + espressif/button: + version: "^4.1.4"