/* 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 software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ #include #include #include #include #include #include #include #include static const char *TAG = "app_main"; static uint16_t configured_buttons = 0; static button_endpoint button_list[CONFIG_MAX_CONFIGURABLE_BUTTONS]; using namespace esp_matter; using namespace esp_matter::attribute; using namespace esp_matter::endpoint; using namespace chip::app::Clusters; static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg) { switch (event->Type) { case chip::DeviceLayer::DeviceEventType::kInterfaceIpAddressChanged: ESP_LOGI(TAG, "Interface IP Address changed"); break; case chip::DeviceLayer::DeviceEventType::kCommissioningComplete: ESP_LOGI(TAG, "Commissioning complete"); break; case chip::DeviceLayer::DeviceEventType::kFailSafeTimerExpired: ESP_LOGI(TAG, "Commissioning failed, fail safe timer expired"); break; case chip::DeviceLayer::DeviceEventType::kCommissioningSessionStarted: ESP_LOGI(TAG, "Commissioning session started"); break; case chip::DeviceLayer::DeviceEventType::kCommissioningSessionStopped: ESP_LOGI(TAG, "Commissioning session stopped"); break; case chip::DeviceLayer::DeviceEventType::kCommissioningWindowOpened: ESP_LOGI(TAG, "Commissioning window opened"); break; case chip::DeviceLayer::DeviceEventType::kCommissioningWindowClosed: ESP_LOGI(TAG, "Commissioning window closed"); break; default: break; } } static esp_err_t app_identification_cb(identification::callback_type_t type, uint16_t endpoint_id, uint8_t effect_id, uint8_t effect_variant, void *priv_data) { ESP_LOGI(TAG, "Identification callback: type: %u, effect: %u, variant: %u", type, effect_id, effect_variant); return ESP_OK; } static esp_err_t app_attribute_update_cb(attribute::callback_type_t type, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val, void *priv_data) { esp_err_t err = ESP_OK; if (type == PRE_UPDATE) { /* Driver update */ app_driver_handle_t driver_handle = (app_driver_handle_t)priv_data; err = app_driver_attribute_update(driver_handle, endpoint_id, cluster_id, attribute_id, val); } return err; } static esp_err_t create_button(struct gpio_button* button, node_t* node) { esp_err_t err = ESP_OK; /* Initialize driver */ app_driver_handle_t button_handle = app_driver_button_init(button); /* Create a new endpoint. */ generic_switch::config_t switch_config; endpoint_t *endpoint = generic_switch::create(node, &switch_config, ENDPOINT_FLAG_NONE, button_handle); /* These node and endpoint handles can be used to create/add other endpoints and clusters. */ if (!node || !endpoint) { ESP_LOGE(TAG, "Matter node creation failed"); err = ESP_FAIL; return err; } for (int i = 0; i < configured_buttons; i++) { if (button_list[i].button == button) { break; } } /* Check for maximum physical buttons that can be configured. */ if (configured_buttons