diff --git a/examples/platform/silabs/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp index b0d1dd0ea8a414..cd37c4615fa4bb 100644 --- a/examples/platform/silabs/BaseApplication.cpp +++ b/examples/platform/silabs/BaseApplication.cpp @@ -222,24 +222,7 @@ CHIP_ERROR BaseApplication::Init() ConfigurationMgr().LogDeviceConfig(); - // Create buffer for QR code that can fit max size and null terminator. - char qrCodeBuffer[chip::QRCodeBasicSetupPayloadGenerator::kMaxQRCodeBase38RepresentationLength + 1]; - chip::MutableCharSpan QRCode(qrCodeBuffer); - - if (Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider().GetSetupPayload(QRCode) == CHIP_NO_ERROR) - { - // Print setup info on LCD if available -#ifdef QR_CODE_ENABLED - slLCD.SetQRCode((uint8_t *) QRCode.data(), QRCode.size()); - slLCD.ShowQRCode(true, true); -#else - PrintQrCodeURL(QRCode); -#endif // QR_CODE_ENABLED - } - else - { - SILABS_LOG("Getting QR code failed!"); - } + OutputQrCode(true /*refreshLCD at init*/); PlatformMgr().AddEventHandler(OnPlatformEvent, 0); #ifdef SL_WIFI @@ -457,6 +440,7 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent) CancelFunctionTimer(); mFunction = kFunction_NoneSelected; + OutputQrCode(false); #ifdef QR_CODE_ENABLED // TOGGLE QRCode/LCD demo UI slLCD.ToggleQRCode(); @@ -700,3 +684,30 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t) sIsProvisioned = event->ServiceProvisioningChange.IsServiceProvisioned; } } + +void BaseApplication::OutputQrCode(bool refreshLCD) +{ + (void) refreshLCD; // could be unused + + // Create buffer for the Qr code setup payload that can fit max size and null terminator. + char setupPayloadBuffer[chip::QRCodeBasicSetupPayloadGenerator::kMaxQRCodeBase38RepresentationLength + 1]; + chip::MutableCharSpan setupPayload(setupPayloadBuffer); + + if (Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider().GetSetupPayload(setupPayload) == CHIP_NO_ERROR) + { + // Print setup info on LCD if available +#ifdef QR_CODE_ENABLED + if (refreshLCD) + { + slLCD.SetQRCode((uint8_t *) setupPayload.data(), setupPayload.size()); + slLCD.ShowQRCode(true, true); + } +#endif // QR_CODE_ENABLED + + PrintQrCodeURL(setupPayload); + } + else + { + SILABS_LOG("Getting QR code failed!"); + } +} diff --git a/examples/platform/silabs/BaseApplication.h b/examples/platform/silabs/BaseApplication.h index 9e99580811293c..b3a9db893183e5 100644 --- a/examples/platform/silabs/BaseApplication.h +++ b/examples/platform/silabs/BaseApplication.h @@ -202,6 +202,15 @@ class BaseApplication static void ScheduleFactoryReset(); static void OnPlatformEvent(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t); + + /** + * @brief Outputs the QRcode payload and URL to the QR code in the logs + * and conditionally on the device LCD. + * + * @param refreshLCD When true, The LCD of the device will be refreshed to show the QR code + */ + static void OutputQrCode(bool refreshLCD); + /********************************************************** * Protected Attributes declaration *********************************************************/