Skip to content

Commit

Permalink
[Silabs]Always print in logs the QR code unconditionnally of the LCD …
Browse files Browse the repository at this point in the history
…presence (project-chip#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>
  • Loading branch information
jmartinez-silabs and restyled-commits authored Aug 12, 2023
1 parent 85c0937 commit 1309e7d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
47 changes: 29 additions & 18 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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!");
}
}
9 changes: 9 additions & 0 deletions examples/platform/silabs/BaseApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*********************************************************/
Expand Down

0 comments on commit 1309e7d

Please sign in to comment.