diff --git a/examples/lighting-app/cyw30739/src/main.cpp b/examples/lighting-app/cyw30739/src/main.cpp index 98b00955930817..3e5f413a0d994c 100644 --- a/examples/lighting-app/cyw30739/src/main.cpp +++ b/examples/lighting-app/cyw30739/src/main.cpp @@ -47,8 +47,6 @@ using namespace ::chip::Shell; static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; static void InitApp(intptr_t args); -static void EventHandler(const ChipDeviceEvent * event, intptr_t arg); -static void HandleThreadStateChangeEvent(const ChipDeviceEvent * event); static void LightManagerCallback(LightingManager::Actor_t actor, LightingManager::Action_t action, uint8_t value); static wiced_led_config_t chip_lighting_led_config = { @@ -148,7 +146,6 @@ void InitApp(intptr_t args) { ConfigurationMgr().LogDeviceConfig(); - PlatformMgrImpl().AddEventHandler(EventHandler, 0); // Print QR Code URL PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE)); /* Start CHIP datamodel server */ @@ -174,20 +171,6 @@ void InitApp(intptr_t args) #endif } -void EventHandler(const ChipDeviceEvent * event, intptr_t arg) -{ - switch (event->Type) - { - case DeviceEventType::kThreadStateChange: - HandleThreadStateChangeEvent(event); - break; - default: - break; - } -} - -void HandleThreadStateChangeEvent(const ChipDeviceEvent * event) {} - void LightManagerCallback(LightingManager::Actor_t actor, LightingManager::Action_t action, uint8_t level) { if (action == LightingManager::ON_ACTION) diff --git a/examples/lock-app/cyw30739/src/main.cpp b/examples/lock-app/cyw30739/src/main.cpp index e63bb342e1be02..3a7a0d8c3ca235 100644 --- a/examples/lock-app/cyw30739/src/main.cpp +++ b/examples/lock-app/cyw30739/src/main.cpp @@ -60,8 +60,6 @@ wiced_bool_t syncClusterToButtonAction = false; static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; static void InitApp(intptr_t args); -static void EventHandler(const ChipDeviceEvent * event, intptr_t arg); -static void HandleThreadStateChangeEvent(const ChipDeviceEvent * event); static void ActionInitiated(LockManager::Action_t aAction, int32_t aActor); static void ActionCompleted(LockManager::Action_t aAction); static void WriteClusterState(uint8_t value); @@ -173,7 +171,6 @@ APPLICATION_START() void InitApp(intptr_t args) { CHIP_ERROR err = CHIP_NO_ERROR; - PlatformMgrImpl().AddEventHandler(EventHandler, 0); // Print QR Code URL PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE)); /* Start CHIP datamodel server */ @@ -267,20 +264,6 @@ void InitApp(intptr_t args) #endif } -void EventHandler(const ChipDeviceEvent * event, intptr_t arg) -{ - switch (event->Type) - { - case DeviceEventType::kThreadStateChange: - HandleThreadStateChangeEvent(event); - break; - default: - break; - } -} - -void HandleThreadStateChangeEvent(const ChipDeviceEvent * event) {} - void ActionInitiated(LockManager::Action_t aAction, int32_t aActor) { // If the action has been initiated by the lock, update the bolt lock trait diff --git a/examples/platform/cyw30739/OTAConfig.cpp b/examples/platform/cyw30739/OTAConfig.cpp index cf3553d23a9850..05902c113aa451 100644 --- a/examples/platform/cyw30739/OTAConfig.cpp +++ b/examples/platform/cyw30739/OTAConfig.cpp @@ -25,8 +25,13 @@ #include #include +using namespace ::chip; +using namespace ::chip::DeviceLayer; + namespace OTAConfig { +constexpr uint32_t kInitOTARequestorDelaySec = 3; + // Global OTA objects chip::DefaultOTARequestor gRequestorCore; chip::DefaultOTARequestorStorage gRequestorStorage; @@ -34,8 +39,34 @@ chip::DeviceLayer::DefaultOTARequestorDriver gRequestorUser; chip::BDXDownloader gDownloader; chip::OTAImageProcessorImpl gImageProcessor; +static void PlatformEventHandler(const ChipDeviceEvent * event, intptr_t arg); +static void InitRequestor(System::Layer * systemLayer, void * appState); + void Init() { + PlatformMgrImpl().AddEventHandler(PlatformEventHandler, 0); +} + +void PlatformEventHandler(const ChipDeviceEvent * event, intptr_t arg) +{ + switch (event->Type) + { + case DeviceEventType::kThreadConnectivityChange: + if (event->ThreadConnectivityChange.Result == kConnectivity_Established) + SystemLayer().StartTimer(System::Clock::Seconds32(kInitOTARequestorDelaySec), InitRequestor, nullptr); + break; + default: + break; + } +} + +void InitRequestor(System::Layer * systemLayer, void * appState) +{ + if (GetRequestorInstance() != nullptr) + return; + + ChipLogProgress(SoftwareUpdate, "Initializing requestor"); + // Initialize and interconnect the Requestor and Image Processor objects -- START SetRequestorInstance(&gRequestorCore);