|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <esp_log.h> |
| 8 | +#include <esp_matter.h> |
| 9 | +#include <iot_button.h> |
| 10 | +#include <sdkconfig.h> |
| 11 | + |
| 12 | +#include <app/icd/server/ICDNotifier.h> |
| 13 | + |
| 14 | +#include <app_priv.h> |
| 15 | + |
| 16 | +#ifdef CONFIG_ENABLE_USER_ACTIVE_MODE_TRIGGER_BUTTON |
| 17 | +using namespace chip::app::Clusters; |
| 18 | +using namespace esp_matter; |
| 19 | + |
| 20 | +static constexpr char *TAG = "app_driver"; |
| 21 | + |
| 22 | +static void app_driver_button_toggle_cb(void *arg, void *data) |
| 23 | +{ |
| 24 | + // The device will stay active mode for Active Mode Threshold |
| 25 | + chip::DeviceLayer::PlatformMgr().ScheduleWork([](intptr_t) { |
| 26 | + chip::app::ICDNotifier::GetInstance().NotifyNetworkActivityNotification(); |
| 27 | + }); |
| 28 | +} |
| 29 | + |
| 30 | +app_driver_handle_t app_driver_button_init() |
| 31 | +{ |
| 32 | + /* Initialize button */ |
| 33 | + button_config_t config; |
| 34 | + memset(&config, 0, sizeof(button_config_t)); |
| 35 | + config.type = BUTTON_TYPE_GPIO; |
| 36 | + config.gpio_button_config.gpio_num = CONFIG_USER_ACTIVE_MODE_TRIGGER_BUTTON_PIN; |
| 37 | + config.gpio_button_config.active_level = 0; |
| 38 | + config.gpio_button_config.enable_power_save = true; |
| 39 | + button_handle_t handle = iot_button_create(&config); |
| 40 | + |
| 41 | + iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL); |
| 42 | + return (app_driver_handle_t)handle; |
| 43 | +} |
| 44 | + |
| 45 | +#endif // CONFIG_ENABLE_USER_ACTIVE_MODE_TRIGGER_BUTTON |
0 commit comments