diff --git a/examples/lighting-app/qpg/include/AppTask.h b/examples/lighting-app/qpg/include/AppTask.h index edc33a5f88a0c3..510478fb9be3e3 100644 --- a/examples/lighting-app/qpg/include/AppTask.h +++ b/examples/lighting-app/qpg/include/AppTask.h @@ -48,12 +48,12 @@ class AppTask friend AppTask & GetAppTask(void); CHIP_ERROR Init(); + static void InitServer(intptr_t arg); + static void OpenCommissioning(intptr_t arg); static void ActionInitiated(LightingManager::Action_t aAction); static void ActionCompleted(LightingManager::Action_t aAction); - void CancelTimer(void); - void DispatchEvent(AppEvent * event); static void FunctionTimerEventHandler(AppEvent * aEvent); @@ -63,6 +63,7 @@ class AppTask static void TimerEventHandler(chip::System::Layer * aLayer, void * aAppState); void StartTimer(uint32_t aTimeoutMs); + void CancelTimer(void); enum Function_t { diff --git a/examples/lighting-app/qpg/src/AppTask.cpp b/examples/lighting-app/qpg/src/AppTask.cpp index c05c40c0f282c7..13e78387cc4a99 100644 --- a/examples/lighting-app/qpg/src/AppTask.cpp +++ b/examples/lighting-app/qpg/src/AppTask.cpp @@ -44,9 +44,9 @@ #include #include -using namespace chip::TLV; -using namespace chip::Credentials; -using namespace chip::DeviceLayer; +using namespace ::chip::TLV; +using namespace ::chip::Credentials; +using namespace ::chip::DeviceLayer; #include @@ -208,28 +208,8 @@ CHIP_ERROR AppTask::StartAppTask() return CHIP_NO_ERROR; } -CHIP_ERROR AppTask::Init() +void AppTask::InitServer(intptr_t arg) { - CHIP_ERROR err = CHIP_NO_ERROR; - - ChipLogProgress(NotSpecified, "Current Software Version: %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING); - - err = LightingMgr().Init(); - if (err != CHIP_NO_ERROR) - { - ChipLogError(NotSpecified, "LightingMgr().Init() failed"); - return err; - } - LightingMgr().SetCallbacks(ActionInitiated, ActionCompleted); - - // Subscribe with our button callback to the qvCHIP button handler. - qvIO_SetBtnCallback(ButtonEventHandler); - -#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY - chip::app::DnssdServer::Instance().SetExtendedDiscoveryTimeoutSecs(extDiscTimeoutSecs); -#endif - - // Init ZCL Data Model static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); @@ -243,21 +223,52 @@ CHIP_ERROR AppTask::Init() initParams.endpointNativeParams = static_cast(&nativeParams); chip::Server::GetInstance().Init(initParams); - // Init OTA engine - InitializeOTARequestor(); +#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY + chip::app::DnssdServer::Instance().SetExtendedDiscoveryTimeoutSecs(extDiscTimeoutSecs); +#endif + + // Open commissioning after boot if no fabric was available + if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0) + { + PlatformMgr().ScheduleWork(OpenCommissioning, 0); + } +} + +void AppTask::OpenCommissioning(intptr_t arg) +{ + // Enable BLE advertisements + chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow(); + ChipLogProgress(NotSpecified, "BLE advertising started. Waiting for Pairing."); +} + +CHIP_ERROR AppTask::Init() +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + ChipLogProgress(NotSpecified, "Current Software Version: %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING); + + // Init ZCL Data Model and start server + PlatformMgr().ScheduleWork(InitServer, 0); // Initialize device attestation config SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); - UpdateClusterState(); + // Setup light + err = LightingMgr().Init(); + if (err != CHIP_NO_ERROR) + { + ChipLogError(NotSpecified, "LightingMgr().Init() failed"); + return err; + } + LightingMgr().SetCallbacks(ActionInitiated, ActionCompleted); + // Setup button handler + qvIO_SetBtnCallback(ButtonEventHandler); + + // Log device configuration ConfigurationMgr().LogDeviceConfig(); PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); - // Enable BLE advertisements - chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow(); - ChipLogProgress(NotSpecified, "BLE advertising started. Waiting for Pairing."); - return err; } diff --git a/examples/lock-app/qpg/include/AppTask.h b/examples/lock-app/qpg/include/AppTask.h index fd6c1d888a8b7e..005d0aeb9da6e0 100644 --- a/examples/lock-app/qpg/include/AppTask.h +++ b/examples/lock-app/qpg/include/AppTask.h @@ -52,6 +52,7 @@ class AppTask friend AppTask & GetAppTask(void); CHIP_ERROR Init(); + static void InitServer(intptr_t arg); static void ActionInitiated(BoltLockManager::Action_t aAction, int32_t aActor); static void ActionCompleted(BoltLockManager::Action_t aAction); diff --git a/examples/lock-app/qpg/src/AppTask.cpp b/examples/lock-app/qpg/src/AppTask.cpp index ab03f02efcc35e..a9506783a8fb75 100644 --- a/examples/lock-app/qpg/src/AppTask.cpp +++ b/examples/lock-app/qpg/src/AppTask.cpp @@ -108,30 +108,8 @@ CHIP_ERROR AppTask::StartAppTask() return CHIP_NO_ERROR; } -CHIP_ERROR AppTask::Init() +void AppTask::InitServer(intptr_t arg) { - CHIP_ERROR err = CHIP_NO_ERROR; - - ChipLogProgress(NotSpecified, "Current Software Version: %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING); - - err = BoltLockMgr().Init(); - if (err != CHIP_NO_ERROR) - { - ChipLogError(NotSpecified, "BoltLockMgr().Init() failed"); - return err; - } - BoltLockMgr().SetCallbacks(ActionInitiated, ActionCompleted); - - // Subscribe with our button callback to the qvCHIP button handler. - qvIO_SetBtnCallback(ButtonEventHandler); - - qvIO_LedSet(LOCK_STATE_LED, !BoltLockMgr().IsUnlocked()); - -#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY - chip::app::DnssdServer::Instance().SetExtendedDiscoveryTimeoutSecs(extDiscTimeoutSecs); -#endif - - // Init ZCL Data Model static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); @@ -145,12 +123,36 @@ CHIP_ERROR AppTask::Init() initParams.endpointNativeParams = static_cast(&nativeParams); chip::Server::GetInstance().Init(initParams); - // Init OTA engine - InitializeOTARequestor(); +#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY + chip::app::DnssdServer::Instance().SetExtendedDiscoveryTimeoutSecs(extDiscTimeoutSecs); +#endif +} +CHIP_ERROR AppTask::Init() +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + ChipLogProgress(NotSpecified, "Current Software Version: %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING); + + // Init ZCL Data Model and start server + PlatformMgr().ScheduleWork(InitServer, 0); // Initialize device attestation config SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); + // Setup Bolt + err = BoltLockMgr().Init(); + if (err != CHIP_NO_ERROR) + { + ChipLogError(NotSpecified, "BoltLockMgr().Init() failed"); + return err; + } + BoltLockMgr().SetCallbacks(ActionInitiated, ActionCompleted); + + // Setup button handler + qvIO_SetBtnCallback(ButtonEventHandler); + + qvIO_LedSet(LOCK_STATE_LED, !BoltLockMgr().IsUnlocked()); + UpdateClusterState(); ConfigurationMgr().LogDeviceConfig();