diff --git a/components/esp_matter/esp_matter.h b/components/esp_matter/esp_matter.h index e95c6ab09..75d334a74 100644 --- a/components/esp_matter/esp_matter.h +++ b/components/esp_matter/esp_matter.h @@ -103,3 +103,24 @@ typedef enum command_flags { } command_flags_t; } /* esp_matter */ + +#include + +namespace chip { +namespace DeviceLayer { +namespace DeviceEventType { + +/** + * Enumerates platform-specific event types that are visible to the application. + */ +enum +{ + kCommissioningSessionStarted = kRange_PublicPlatformSpecific + 0x1000, + kCommissioningSessionStopped, + kCommissioningWindowOpened, + kCommissioningWindowClosed, +}; + +} // DeviceEventType +} // DeviceLayer +} // chip diff --git a/components/esp_matter/esp_matter_core.cpp b/components/esp_matter/esp_matter_core.cpp index 1a763e0bf..5b3566bba 100644 --- a/components/esp_matter/esp_matter_core.cpp +++ b/components/esp_matter/esp_matter_core.cpp @@ -62,6 +62,45 @@ namespace { #if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER chip::DeviceLayer::ESP32FactoryDataProvider factory_data_provider; #endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER + +class AppDelegateImpl : public AppDelegate +{ +public: + void OnCommissioningSessionStarted() + { + PostEvent(chip::DeviceLayer::DeviceEventType::kCommissioningSessionStarted); + } + + void OnCommissioningSessionStopped() + { + PostEvent(chip::DeviceLayer::DeviceEventType::kCommissioningSessionStopped); + } + + void OnCommissioningWindowOpened() + { + PostEvent(chip::DeviceLayer::DeviceEventType::kCommissioningWindowOpened); + } + + void OnCommissioningWindowClosed() + { + PostEvent(chip::DeviceLayer::DeviceEventType::kCommissioningWindowClosed); + } + +private: + void PostEvent(uint16_t eventType) + { + chip::DeviceLayer::ChipDeviceEvent event; + event.Type = eventType; + CHIP_ERROR error = chip::DeviceLayer::PlatformMgr().PostEvent(&event); + if (error != CHIP_NO_ERROR) + { + ESP_LOGE(TAG, "Failed to post event from AppDelegate, err:%" CHIP_ERROR_FORMAT, error.Format()); + } + } +}; + +AppDelegateImpl s_app_delegate; + } // namespace typedef struct _attribute { @@ -648,8 +687,7 @@ static void esp_matter_chip_init_task(intptr_t context) static chip::CommonCaseDeviceServerInitParams initParams; initParams.InitializeStaticResourcesBeforeServerInit(); - /** TODO: Add these callbacks and pass them on to the application */ - // initParams.appDelegate = &sCallbacks; + initParams.appDelegate = &s_app_delegate; chip::Server::GetInstance().Init(initParams); #if CHIP_DEVICE_CONFIG_ENABLE_THREAD