Skip to content
Merged
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
127 changes: 2 additions & 125 deletions sld250-matter-references/custom-matter-device.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,128 +9,7 @@ using Matter.

## Extending Base App Implementation

### CustomerAppTask

To customize app behavior, override any Silicon Labs implemented API in `CustomerAppTask`. This example provides `CustomerAppTask.h` and `CustomerAppTask.cpp` for that purpose. The build system generates the base implementation and the complete set of overridable `*Impl()` APIs in `autogen/AppTask.cpp` and `autogen/AppTaskImpl.h`. Any `*Impl()` methods that you do not override use the Silicon Labs default implementation.
### How to Override APIs

`CustomerAppTask` extends the base `AppTask` by using the Curiously Recurring Template Pattern (CRTP). The base class declares one `*Impl()` method for each overridable API. Override only the `*Impl()` methods that you need. To override a `*Impl()` method:

1. Find the method to override in the base API. For more information, see [Override API reference](#override-api-reference).
2. Declare the same method signature in `CustomerAppTask.h` under the `private:` section. Match the base `*Impl()` signature exactly.
> **NOTE:**
> `*Impl()` overrides are non-static instance methods, even when the corresponding public dispatcher (for example, `ButtonEventHandler`) is static.
3. Implement the method in `CustomerAppTask.cpp`.
4. Build the project. If you implement the corresponding `*Impl()` method in `CustomerAppTask`, your implementation is used. Otherwise, the Silicon Labs default implementation is used. You only need to implement the methods that you want to customize. All other methods automatically use the default implementation.

### DataModelCallbacks and CustomerAppTask

What used to live in `DataModelCallbacks.cpp` before Matter Extension 2.9.1 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()` from
the lighting app implementation.

**CustomerAppTask.h**

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

/**
* Minimal AppTaskImpl-derived class. Override only the *Impl() methods you need;
* add AppInitImpl(), GetAppTask(), and sAppTask as required by the CRTP base.
*/
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 "AppConfig.h"
#include "AppEvent.h"
#include <platform/CHIPDeviceLayer.h>
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>

using namespace ::chip::DeviceLayer::Silabs;

#define APP_FUNCTION_BUTTON 0
#define APP_LIGHT_SWITCH 1

CustomerAppTask CustomerAppTask::sAppTask;

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

CHIP_ERROR CustomerAppTask::AppInitImpl()
{
SILABS_LOG("CustomerAppTask: custom implementation (AppInitImpl)");
CHIP_ERROR err = this->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 button_event = {};
button_event.Type = AppEvent::kEventType_Button;
button_event.ButtonEvent.Action = btnAction;
if (button == APP_LIGHT_SWITCH && btnAction == static_cast<uint8_t>(SilabsPlatform::ButtonAction::ButtonPressed))
{
button_event.Handler = LightActionEventHandler;
AppTask::GetAppTask().PostEvent(&button_event);
}
else if (button == APP_FUNCTION_BUTTON)
{
button_event.Handler = BaseApplication::ButtonHandler;
AppTask::GetAppTask().PostEvent(&button_event);
}
}
```

### Override API Reference

The base API and implementation are generated into the `autogen/` directory. These files are regenerated whenever you upgrade the project and match the installed SDK version. Use them as a 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 provides the default `AppTask` implementation. Any `*Impl()` methods that you don't override use this implementation. Use it as a reference when customizing app behavior. |
To customize app behavior through the overridable APIs exposed by each app, see [Matter API Reference](/matter/{build-docspace-version}/matter-api-reference/).

## Using Matter with Clusters

Expand Down Expand Up @@ -186,7 +65,7 @@ through this function. The command can then be dissected using conditional logic
to call the proper application functions based on the most recent command
received.

Attribute changes route through `CustomerAppTask` and `DMPostAttributeChangeCallbackImpl()`. For more information, see [Extending Base App Implementation](#extending-base-app-implementation).
Attribute changes route through `CustomerAppTask` and `DMPostAttributeChangeCallbackImpl()`. For more information, see [Matter API Reference](/matter/{build-docspace-version}/matter-api-reference/).

## Adding a Cluster to a ZAP Configuration

Expand Down Expand Up @@ -257,5 +136,3 @@ In order to use a custom cluster in an application, follow these steps:
```
For an example, see [Sample ZAP file](https://github.com/SiliconLabsSoftware/matter_extension/blob/v2.9.1/slc/apps/performance_test_app/thread/performance-test-app.zap)
- Install the **Custom ZAP generation** component under **Silicon Labs Matter -> Stack** in the project's Component Editor.


14 changes: 14 additions & 0 deletions sld295-matter-api-reference/air-quality-sensor-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Air Quality Sensor Application Override APIs

To override any of the following hooks, declare the corresponding `*Impl()` method in `CustomerAppTask.h` and implement it in `CustomerAppTask.cpp`. Ensure that the method signature matches the declaration in `autogen/AppTaskImpl.h`.

## AppTask

| Override | Public API | Default behavior |
|---|---|---|
| `AppInitImpl` | `AppInit` | Registers the button callback, configures the LCD UI, and initializes the air quality sensor. |
| `InitAirQualitySensorImpl` | `InitAirQualitySensor` | Creates the periodic sensor timer, initializes the sensor hardware when available, and starts sampling. |
| `GetAirQualityValueImpl` | `GetAirQualityValue` | Reads the value from the onboard air quality sensor. If the sensor is unavailable, returns a simulated value. |
| `ButtonEventHandlerImpl` | `ButtonEventHandler` | Routes function-button events to the base application handler. |
| `SensorTimerEventHandlerImpl` | `SensorTimerEventHandler` | Reads the sensor value and schedules an update to the Air Quality attribute. |
| `DMPostAttributeChangeCallbackImpl` | `DMPostAttributeChangeCallback` | Logs changes to the Identify attribute. |
44 changes: 0 additions & 44 deletions sld295-matter-api-reference/attributes.md

This file was deleted.

15 changes: 15 additions & 0 deletions sld295-matter-api-reference/base-platform-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Base Platform Application Override APIs

To override any of the following hooks, declare the corresponding `*Impl()` method in `CustomerAppTask.h` and implement it in `CustomerAppTask.cpp`. Ensure that the method signature matches the declaration in `autogen/AppTaskImpl.h`.

## AppTask

| Override | Public API | Default behavior |
|---|---|---|
| `AppInitImpl` | `AppInit` | Registers the button callback, initializes the LED, and shows the demo UI or QR code when enabled. |
| `ButtonEventHandlerImpl` | `ButtonEventHandler` | Routes user-action button events to `ApplicationEventHandler` and function-button events to the base application handler. |
| `ApplicationEventHandlerImpl` | `ApplicationEventHandler` | Toggles the LED when the user-action button is pressed. |
| `OnEnterActiveModeImpl` | `OnEnterActiveMode` | Updates the demo UI when the ICD server enters active mode. Available when `CHIP_CONFIG_ENABLE_ICD_SERVER` is enabled. |
Comment thread
miduggan24 marked this conversation as resolved.
Resolved
| `OnEnterIdleModeImpl` | `OnEnterIdleMode` | Updates the demo UI when the ICD server enters idle mode. Available when `CHIP_CONFIG_ENABLE_ICD_SERVER` is enabled. |
| `OnTransitionToIdleImpl` | `OnTransitionToIdle` | Logs the transition while the ICD server moves to idle mode. Available when `CHIP_CONFIG_ENABLE_ICD_SERVER` is enabled. |
| `OnICDModeChangeImpl` | `OnICDModeChange` | Logs changes between Short Idle Time (SIT) and Long Idle Time (LIT) operating modes. Available when `CHIP_CONFIG_ENABLE_ICD_SERVER` is enabled. |
38 changes: 38 additions & 0 deletions sld295-matter-api-reference/closure-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Closure Application Override APIs

To override any of the following AppTask hooks, declare the corresponding `*Impl()` method in `CustomerAppTask.h` and implement it in `CustomerAppTask.cpp`. Ensure that the method signature matches the declaration in `autogen/AppTaskImpl.h`.

## AppTask

| Override | Public API | Default behavior |
|---|---|---|
| `AppInitImpl` | `AppInit` | Registers the button callback, initializes the display, and initializes Closure Manager. |
| `ButtonEventHandlerImpl` | `ButtonEventHandler` | Routes closure button presses to `ClosureButtonActionEventHandler` and function button events to the base application handler. |
| `ClosureButtonActionEventHandlerImpl` | `ClosureButtonActionEventHandler` | Stops motion if a closure action is in progress; otherwise, it starts a MoveTo toward the opposite position. |
| `DMPostAttributeChangeCallbackImpl` | `DMPostAttributeChangeCallback` | Logs Identify attribute changes. |
| `DMClosureControlClusterAttributeChangedCallbackImpl` | `DMClosureControlClusterAttributeChangedCallback` | Refreshes the UI when Closure Control `MainState` or `OverallCurrentState` changes. |
| `DMClosureDimensionClusterAttributeChangedCallbackImpl` | `DMClosureDimensionClusterAttributeChangedCallback` | Logs Closure Dimension attribute changes. |

## ClosureManager

These APIs use the Closure app's separate manager override chain. Declare and
implement the corresponding `*Impl()` methods in `CustomerAppManager`, which
derives from `ClosureManagerImpl<CustomerAppManager>`. Use
`autogen/ClosureManagerImpl.h` for exact signatures. Do not place these
overrides in `CustomerAppTask`.

| Override | Public API | Default behavior |
|---|---|---|
| `InitImpl` | `Init` | Initializes the closure timer, closure endpoints, and panel endpoints. |
| `OnCalibrateCommandImpl` | `OnCalibrateCommand` | Validates and starts an asynchronous closure calibration. |
| `OnMoveToCommandImpl` | `OnMoveToCommand` | Validates a MoveTo command and sets overall panel targets. |
| `OnStopCommandImpl` | `OnStopCommand` | Stops the active closure operation and completes the stop action. |
| `OnSetTargetCommandImpl` | `OnSetTargetCommand` | Validates a SetTarget command and sets the selected panel target. |
| `OnStepCommandImpl` | `OnStepCommand` | Validates a Step command and sets the selected panel step target. |
| `HandleClosureActionCompleteImpl` | `HandleClosureActionComplete` | Finalizes a completed calibrate, stop, move, or unlatch action. |
| `HandleClosureMotionActionImpl` | `HandleClosureMotionAction` | Advances closure panels toward their target positions. |
| `HandleClosureUnlatchActionImpl` | `HandleClosureUnlatchAction` | Updates closure and panel states for an unlatch action. |
| `GetPanelNextPositionImpl` | `GetPanelNextPosition` | Calculates the next position between a panel's current and target positions. |
| `HandlePanelSetTargetActionImpl` | `HandlePanelSetTargetAction` | Advances one panel toward a SetTarget position. |
| `HandlePanelUnlatchActionImpl` | `HandlePanelUnlatchAction` | Updates one panel for an unlatch action. |
| `HandlePanelStepActionImpl` | `HandlePanelStepAction` | Applies a Step action to one panel. |
7 changes: 0 additions & 7 deletions sld295-matter-api-reference/cluster-implementation.md

This file was deleted.

16 changes: 0 additions & 16 deletions sld295-matter-api-reference/cluster.md

This file was deleted.

11 changes: 0 additions & 11 deletions sld295-matter-api-reference/commands.md

This file was deleted.

15 changes: 0 additions & 15 deletions sld295-matter-api-reference/datamodeltypes.md

This file was deleted.

13 changes: 0 additions & 13 deletions sld295-matter-api-reference/event.md

This file was deleted.

Loading