Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions slc/apps/refrigerator_app/thread/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The Matter over Thread refrigerator example is a baseline demonstration of a fri
- [Purpose/Scope](#purposescope)
- [Prerequisites/Setup Requirements](#prerequisitessetup-requirements)
- [Steps to Run Demo](#steps-to-run-demo)
- [Extending Base App Implementation](#extending-base-app-implementation)
- [Troubleshooting](#troubleshooting)
- [Resources](#resources)
- [Report Bugs & Get Support](#report-bugs--get-support)
Expand Down Expand Up @@ -94,6 +95,126 @@ This sample app works out of the box with no additional configuration required.
| LED 0 | Short flash off | Provisioned, no full Thread connectivity |
| LED 0 | Solid on | Fully provisioned with Thread connectivity |

## Extending Base App Implementation

### CustomerAppTask

To implement custom app behavior you can override any Silicon Labs implemented API in the CustomerAppTask file. This example provides `CustomerAppTask.h` and `CustomerAppTask.cpp` for that purpose. The base implementation and the full set of overridable `*Impl()` APIs are supplied by the build system in `AppTask.cpp` and `AppTaskImpl.h` under `autogen/`. Any `*Impl()` you do not override keeps the Silicon Labs default behavior.

### How to Override APIs

`CustomerAppTask` derives from the base AppTask through the Curiously Recurring
Template Pattern (CRTP). You override only the `*Impl()` methods you need, the
base declares one `*Impl()` per overridable API. Steps:

1. Find the method to override in the base API (see
[Override API reference](#override-api-reference) below).
2. Declare the same method signature in `CustomerAppTask` in your
`CustomerAppTask.h` under `private:`. Match the base `*Impl()` signature
exactly — note that `*Impl()` overrides are **non-static instance methods**
even when the public dispatcher (e.g. `ButtonEventHandler`) is `static`.
3. Implement the method in `CustomerAppTask.cpp`.
4. Build. The CRTP layer automatically routes each call to your `*Impl()` if
present, otherwise to the Silicon Labs default.

### DataModelCallbacks and CustomerAppTask

What used to live in `DataModelCallbacks.cpp` now lives in `AppTask.cpp`. The
Matter SDK's `MatterPostAttributeChangeCallback` is implemented in
`examples/platform/silabs/BaseApplication.cpp` and forwards to
`AppTask::DMPostAttributeChangeCallback` (defined in `AppTask.cpp`), which you
can customize via `DMPostAttributeChangeCallbackImpl()` in `CustomerAppTask`.

Forwarding into `AppTask` still goes through CRTP as in
[How to Override APIs](#how-to-override-apis).

- **Methods that already exist in the AppTask** — Customize them by overriding
the matching `*Impl()` method in `CustomerAppTask`. Do not edit the
`AppTask.cpp` for app-specific behavior.

- **New custom data model methods** — Add them in `CustomerAppTask` directly.
Do not add new application logic in autogenerated sources; those edits will
not survive regeneration or project upgrades.

### Sample Implementation

The following shows a minimal example `CustomerAppTask` that overrides
`AppInitImpl()` and `ButtonEventHandlerImpl()`.

**CustomerAppTask.h**

```cpp
#pragma once
#include "AppTaskImpl.h"

/** Minimal AppTaskImpl-derived class. Override only the *Impl() methods you need **/
class CustomerAppTask : public AppTaskImpl<CustomerAppTask>
{
public:
static CustomerAppTask & GetAppTask() { return sAppTask; }

private:
friend class AppTaskImpl<CustomerAppTask>;
CHIP_ERROR AppInitImpl();
void ButtonEventHandlerImpl(uint8_t button, uint8_t btnAction);
static CustomerAppTask sAppTask;
};
```

**CustomerAppTask.cpp**

```cpp
#include "CustomerAppTask.h"
#include "AppTask.h"
#include "AppEvent.h"
#include <platform/CHIPDeviceLayer.h>
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>

#define APP_FUNCTION_BUTTON 0

CustomerAppTask CustomerAppTask::sAppTask;

AppTask & AppTask::GetAppTask()
{
return CustomerAppTask::GetAppTask();
}

CHIP_ERROR CustomerAppTask::AppInitImpl()
{
SILABS_LOG("CustomerAppTask: custom implementation (AppInitImpl)");
CHIP_ERROR err = AppTask::AppInit();
if (err == CHIP_NO_ERROR)
{
// Override the SDK default button handler registered in AppTask::AppInit().
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(CustomerAppTask::ButtonEventHandler);
}
return err;
}

void CustomerAppTask::ButtonEventHandlerImpl(uint8_t button, uint8_t btnAction)
{
SILABS_LOG("CustomerAppTask: custom implementation (ButtonEventHandlerImpl)");
AppEvent aEvent = {};
aEvent.Type = AppEvent::kEventType_Button;
aEvent.ButtonEvent.Action = btnAction;

if (button == APP_FUNCTION_BUTTON)
{
aEvent.Handler = BaseApplication::ButtonHandler;
AppTask::GetAppTask().PostEvent(&aEvent);
}
}
```

### Override API Reference

The base API and implementation are generated into your project and live under `autogen/` directory. These files are regenerated on every project upgrade and match your installed SDK version. Use them as the reference for overridable methods and app configuration.

| File | Purpose |
|------|--------|
| `autogen/AppTaskImpl.h` | Declarations of every overridable `*Impl()` method. Copy the signatures you need from here into `CustomerAppTask.h`. |
| `autogen/AppTask.cpp` | Silicon Labs default implementation of AppTask. This is what runs for any `*Impl()` you do not override. Use as reference when customizing behavior. |

## Troubleshooting

**Device does not advertise over BLE**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,28 @@ config_file:
- path: ../../../../provision.mattpconf
directory: provision
file_id: provision_config
- path: ../../../../third_party/matter_sdk/examples/refrigerator-app/silabs/include/RefrigeratorConfig.h
file_id: refrigerator_config

include:
- path: ../../../../third_party/matter_sdk/examples/refrigerator-app/silabs/include
file_list:
- path: AppConfig.h
- path: AppEvent.h
- path: AppTask.h
- path: CHIPProjectConfig.h
- path: RefrigeratorManager.h
- path: refrigerator-and-temperature-controlled-cabinet-mode.h
- path: ../../../../third_party/matter_sdk/examples/refrigerator-app/refrigerator-common/include
file_list:
- path: static-supported-temperature-levels.h
- path: ../../../../third_party/matter_sdk/examples/platform/silabs/customer
file_list:
- path: CustomerAppTask.h
directory: include

source:
- path: ../../../../third_party/matter_sdk/examples/refrigerator-app/silabs/src/AppTask.cpp
directory: src
- path: ../../../../third_party/matter_sdk/examples/refrigerator-app/silabs/src/RefrigeratorManager.cpp
- path: ../../../../third_party/matter_sdk/examples/platform/silabs/customer/CustomerAppTask.cpp
directory: src
- path: ../../../../third_party/matter_sdk/examples/platform/silabs/main.cpp
directory: src
- path: ../../../../third_party/matter_sdk/examples/refrigerator-app/silabs/src/DataModelCallbacks.cpp
directory: src
- path: ../../../../third_party/matter_sdk/examples/refrigerator-app/silabs/src/refrigerator-and-temperature-controlled-cabinet-mode.cpp
directory: src
- path: ../../../../third_party/matter_sdk/examples/refrigerator-app/refrigerator-common/src/static-supported-temperature-levels.cpp
directory: src

Expand Down
121 changes: 121 additions & 0 deletions slc/apps/refrigerator_app/wifi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The Matter over Wi-Fi refrigerator example is a baseline demonstration of a frid
- [Purpose/Scope](#purposescope)
- [Prerequisites/Setup Requirements](#prerequisitessetup-requirements)
- [Steps to Run Demo](#steps-to-run-demo)
- [Extending Base App Implementation](#extending-base-app-implementation)
- [Troubleshooting](#troubleshooting)
- [Resources](#resources)
- [Report Bugs & Get Support](#report-bugs--get-support)
Expand Down Expand Up @@ -88,6 +89,126 @@ This sample app works out of the box with no additional configuration required.
| LED 0 | Short flash off | Provisioned, no full service connectivity |
| LED 0 | Solid on | Fully provisioned with service connectivity |

## Extending Base App Implementation

### CustomerAppTask

To implement custom app behavior you can override any Silicon Labs implemented API in the CustomerAppTask file. This example provides `CustomerAppTask.h` and `CustomerAppTask.cpp` for that purpose. The base implementation and the full set of overridable `*Impl()` APIs are supplied by the build system in `AppTask.cpp` and `AppTaskImpl.h` under `autogen/`. Any `*Impl()` you do not override keeps the Silicon Labs default behavior.

### How to Override APIs

`CustomerAppTask` derives from the base AppTask through the Curiously Recurring
Template Pattern (CRTP). You override only the `*Impl()` methods you need, the
base declares one `*Impl()` per overridable API. Steps:

1. Find the method to override in the base API (see
[Override API reference](#override-api-reference) below).
2. Declare the same method signature in `CustomerAppTask` in your
`CustomerAppTask.h` under `private:`. Match the base `*Impl()` signature
exactly — note that `*Impl()` overrides are **non-static instance methods**
even when the public dispatcher (e.g. `ButtonEventHandler`) is `static`.
3. Implement the method in `CustomerAppTask.cpp`.
4. Build. The CRTP layer automatically routes each call to your `*Impl()` if
present, otherwise to the Silicon Labs default.

### DataModelCallbacks and CustomerAppTask

What used to live in `DataModelCallbacks.cpp` now lives in `AppTask.cpp`. The
Matter SDK's `MatterPostAttributeChangeCallback` is implemented in
`examples/platform/silabs/BaseApplication.cpp` and forwards to
`AppTask::DMPostAttributeChangeCallback` (defined in `AppTask.cpp`), which you
can customize via `DMPostAttributeChangeCallbackImpl()` in `CustomerAppTask`.

Forwarding into `AppTask` still goes through CRTP as in
[How to Override APIs](#how-to-override-apis).

- **Methods that already exist in the AppTask** — Customize them by overriding
the matching `*Impl()` method in `CustomerAppTask`. Do not edit the
`AppTask.cpp` for app-specific behavior.

- **New custom data model methods** — Add them in `CustomerAppTask` directly.
Do not add new application logic in autogenerated sources; those edits will
not survive regeneration or project upgrades.

### Sample Implementation

The following shows a minimal example `CustomerAppTask` that overrides
`AppInitImpl()` and `ButtonEventHandlerImpl()`.

**CustomerAppTask.h**

```cpp
#pragma once
#include "AppTaskImpl.h"

/** Minimal AppTaskImpl-derived class. Override only the *Impl() methods you need **/
class CustomerAppTask : public AppTaskImpl<CustomerAppTask>
{
public:
static CustomerAppTask & GetAppTask() { return sAppTask; }

private:
friend class AppTaskImpl<CustomerAppTask>;
CHIP_ERROR AppInitImpl();
void ButtonEventHandlerImpl(uint8_t button, uint8_t btnAction);
static CustomerAppTask sAppTask;
};
```

**CustomerAppTask.cpp**

```cpp
#include "CustomerAppTask.h"
#include "AppTask.h"
#include "AppEvent.h"
#include <platform/CHIPDeviceLayer.h>
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>

#define APP_FUNCTION_BUTTON 0

CustomerAppTask CustomerAppTask::sAppTask;

AppTask & AppTask::GetAppTask()
{
return CustomerAppTask::GetAppTask();
}

CHIP_ERROR CustomerAppTask::AppInitImpl()
{
SILABS_LOG("CustomerAppTask: custom implementation (AppInitImpl)");
CHIP_ERROR err = AppTask::AppInit();
if (err == CHIP_NO_ERROR)
{
// Override the SDK default button handler registered in AppTask::AppInit().
chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(CustomerAppTask::ButtonEventHandler);
}
return err;
}

void CustomerAppTask::ButtonEventHandlerImpl(uint8_t button, uint8_t btnAction)
{
SILABS_LOG("CustomerAppTask: custom implementation (ButtonEventHandlerImpl)");
AppEvent aEvent = {};
aEvent.Type = AppEvent::kEventType_Button;
aEvent.ButtonEvent.Action = btnAction;

if (button == APP_FUNCTION_BUTTON)
{
aEvent.Handler = BaseApplication::ButtonHandler;
AppTask::GetAppTask().PostEvent(&aEvent);
}
}
```

### Override API Reference

The base API and implementation are generated into your project and live under `autogen/` directory. These files are regenerated on every project upgrade and match your installed SDK version. Use them as the reference for overridable methods and app configuration.

| File | Purpose |
|------|--------|
| `autogen/AppTaskImpl.h` | Declarations of every overridable `*Impl()` method. Copy the signatures you need from here into `CustomerAppTask.h`. |
| `autogen/AppTask.cpp` | Silicon Labs default implementation of AppTask. This is what runs for any `*Impl()` you do not override. Use as reference when customizing behavior. |

## Troubleshooting

**Device does not advertise over BLE**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,31 +98,28 @@ config_file:
- path: ../../../../provision.mattpconf
directory: provision
file_id: provision_config
- path: ../../../../third_party/matter_sdk/examples/refrigerator-app/silabs/include/RefrigeratorConfig.h
file_id: refrigerator_config

include:
- path: ../../../../third_party/matter_sdk/examples/refrigerator-app/silabs/include
file_list:
- path: AppConfig.h
- path: AppEvent.h
- path: AppTask.h
- path: CHIPProjectConfig.h
- path: RefrigeratorManager.h
- path: refrigerator-and-temperature-controlled-cabinet-mode.h
- path: ../../../../third_party/matter_sdk/examples/refrigerator-app/refrigerator-common/include
file_list:
- path: static-supported-temperature-levels.h
- path: ../../../../third_party/matter_sdk/examples/platform/silabs/customer
file_list:
- path: CustomerAppTask.h
directory: include

source:
- path: ../../../../third_party/matter_sdk/examples/refrigerator-app/silabs/src/AppTask.cpp
directory: src
- path: ../../../../third_party/matter_sdk/examples/refrigerator-app/silabs/src/RefrigeratorManager.cpp
- path: ../../../../third_party/matter_sdk/examples/platform/silabs/customer/CustomerAppTask.cpp
directory: src
- path: ../../../../third_party/matter_sdk/examples/platform/silabs/main.cpp
directory: src
- path: ../../../../third_party/matter_sdk/examples/refrigerator-app/silabs/src/DataModelCallbacks.cpp
directory: src
- path: ../../../../third_party/matter_sdk/examples/refrigerator-app/silabs/src/refrigerator-and-temperature-controlled-cabinet-mode.cpp
directory: src
- path: ../../../../third_party/matter_sdk/examples/refrigerator-app/refrigerator-common/src/static-supported-temperature-levels.cpp
directory: src

Expand Down
7 changes: 7 additions & 0 deletions slc/component/matter-examples/matter_refrigerator.slcc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,12 @@ id: matter_refrigerator
quality: production
provides:
- name: matter_refrigerator
metadata:
sbom:
license: "Apache 2.0"
template_file:
- path: third_party/matter_sdk/examples/refrigerator-app/silabs/include/AppTask.h
- path: third_party/matter_sdk/examples/refrigerator-app/silabs/include/AppTaskImpl.h
- path: third_party/matter_sdk/examples/refrigerator-app/silabs/src/AppTask.cpp
Comment thread
miduggan24 marked this conversation as resolved.
ui_hints:
visibility: never