Skip to content

Commit 1767328

Browse files
jmartinez-silabsrestyled-commits
authored andcommitted
[Silabs]Always print in logs the QR code unconditionnally of the LCD presence (#28663)
* Always print the qr code payload and url to the console at init and on pb0 press * Restyled by whitespace --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 773b858 commit 1767328

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

examples/platform/silabs/BaseApplication.cpp

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -222,24 +222,7 @@ CHIP_ERROR BaseApplication::Init()
222222

223223
ConfigurationMgr().LogDeviceConfig();
224224

225-
// Create buffer for QR code that can fit max size and null terminator.
226-
char qrCodeBuffer[chip::QRCodeBasicSetupPayloadGenerator::kMaxQRCodeBase38RepresentationLength + 1];
227-
chip::MutableCharSpan QRCode(qrCodeBuffer);
228-
229-
if (Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider().GetSetupPayload(QRCode) == CHIP_NO_ERROR)
230-
{
231-
// Print setup info on LCD if available
232-
#ifdef QR_CODE_ENABLED
233-
slLCD.SetQRCode((uint8_t *) QRCode.data(), QRCode.size());
234-
slLCD.ShowQRCode(true, true);
235-
#else
236-
PrintQrCodeURL(QRCode);
237-
#endif // QR_CODE_ENABLED
238-
}
239-
else
240-
{
241-
SILABS_LOG("Getting QR code failed!");
242-
}
225+
OutputQrCode(true /*refreshLCD at init*/);
243226

244227
PlatformMgr().AddEventHandler(OnPlatformEvent, 0);
245228
#ifdef SL_WIFI
@@ -457,6 +440,7 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
457440
CancelFunctionTimer();
458441
mFunction = kFunction_NoneSelected;
459442

443+
OutputQrCode(false);
460444
#ifdef QR_CODE_ENABLED
461445
// TOGGLE QRCode/LCD demo UI
462446
slLCD.ToggleQRCode();
@@ -700,3 +684,30 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t)
700684
sIsProvisioned = event->ServiceProvisioningChange.IsServiceProvisioned;
701685
}
702686
}
687+
688+
void BaseApplication::OutputQrCode(bool refreshLCD)
689+
{
690+
(void) refreshLCD; // could be unused
691+
692+
// Create buffer for the Qr code setup payload that can fit max size and null terminator.
693+
char setupPayloadBuffer[chip::QRCodeBasicSetupPayloadGenerator::kMaxQRCodeBase38RepresentationLength + 1];
694+
chip::MutableCharSpan setupPayload(setupPayloadBuffer);
695+
696+
if (Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider().GetSetupPayload(setupPayload) == CHIP_NO_ERROR)
697+
{
698+
// Print setup info on LCD if available
699+
#ifdef QR_CODE_ENABLED
700+
if (refreshLCD)
701+
{
702+
slLCD.SetQRCode((uint8_t *) setupPayload.data(), setupPayload.size());
703+
slLCD.ShowQRCode(true, true);
704+
}
705+
#endif // QR_CODE_ENABLED
706+
707+
PrintQrCodeURL(setupPayload);
708+
}
709+
else
710+
{
711+
SILABS_LOG("Getting QR code failed!");
712+
}
713+
}

examples/platform/silabs/BaseApplication.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ class BaseApplication
202202
static void ScheduleFactoryReset();
203203

204204
static void OnPlatformEvent(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t);
205+
206+
/**
207+
* @brief Outputs the QRcode payload and URL to the QR code in the logs
208+
* and conditionally on the device LCD.
209+
*
210+
* @param refreshLCD When true, The LCD of the device will be refreshed to show the QR code
211+
*/
212+
static void OutputQrCode(bool refreshLCD);
213+
205214
/**********************************************************
206215
* Protected Attributes declaration
207216
*********************************************************/

0 commit comments

Comments
 (0)