Skip to content

Commit 628d0f3

Browse files
Add Apptask behavior in the LIT ICD app (#33116)
1 parent 5e925ca commit 628d0f3

File tree

3 files changed

+72
-5
lines changed

3 files changed

+72
-5
lines changed

examples/lit-icd-app/silabs/include/AppTask.h

+26-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "AppEvent.h"
3030
#include "BaseApplication.h"
31+
#include <app/icd/server/ICDStateObserver.h>
3132
#include <ble/Ble.h>
3233
#include <cmsis_os2.h>
3334
#include <lib/core/CHIPError.h>
@@ -49,11 +50,12 @@
4950
* AppTask Declaration
5051
*********************************************************/
5152

52-
class AppTask : public BaseApplication
53+
class AppTask : public BaseApplication, public chip::app::ICDStateObserver
5354
{
5455

5556
public:
56-
AppTask() = default;
57+
AppTask() = default;
58+
virtual ~AppTask() = default;
5759

5860
static AppTask & GetAppTask() { return sAppTask; }
5961

@@ -76,6 +78,28 @@ class AppTask : public BaseApplication
7678
*/
7779
static void ButtonEventHandler(uint8_t button, uint8_t btnAction);
7880

81+
/**
82+
* @brief When the ICD enters ActiveMode, update LCD to reflect the ICD current state.
83+
* Set LCD to ActiveMode UI.
84+
*/
85+
void OnEnterActiveMode();
86+
87+
/**
88+
* @brief When the ICD enters IdleMode, update LCD to reflect the ICD current state.
89+
* Set LCD to IdleMode UI.
90+
*/
91+
void OnEnterIdleMode();
92+
93+
/**
94+
* @brief AppTask has no action to do on this ICD event. Do nothing.
95+
*/
96+
void OnTransitionToIdle(){};
97+
98+
/**
99+
* @brief AppTask has no action to do on this ICD event. Do nothing.
100+
*/
101+
void OnICDModeChange(){};
102+
79103
private:
80104
static AppTask sAppTask;
81105

examples/lit-icd-app/silabs/include/CHIPProjectConfig.h

+7
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,10 @@
8686
* A size, in bytes, of the individual debug event logging buffer.
8787
*/
8888
#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512)
89+
90+
/**
91+
* @brief CHIP_CONFIG_ICD_OBSERVERS_POOL_SIZE
92+
*
93+
* Increase default(2) by 1 to account for the AppTask registering
94+
*/
95+
#define CHIP_CONFIG_ICD_OBSERVERS_POOL_SIZE 3

examples/lit-icd-app/silabs/src/AppTask.cpp

+39-3
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@
3333
#endif // QR_CODE_ENABLED
3434
#endif // DISPLAY_ENABLED
3535

36+
#include <app-common/zap-generated/attributes/Accessors.h>
37+
#include <app-common/zap-generated/ids/Clusters.h>
3638
#include <app/server/OnboardingCodesUtil.h>
3739
#include <app/server/Server.h>
3840
#include <app/util/attribute-storage.h>
3941
#include <assert.h>
4042
#include <lib/support/CodeUtils.h>
4143
#include <platform/CHIPDeviceLayer.h>
44+
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>
4245
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
4346
#include <setup_payload/SetupPayload.h>
4447

45-
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>
46-
4748
/**********************************************************
4849
* Defines and Constants
4950
*********************************************************/
@@ -103,6 +104,8 @@ void AppTask::AppTaskMain(void * pvParameter)
103104
appError(err);
104105
}
105106

107+
chip::Server::GetInstance().GetICDManager().RegisterObserver(&sAppTask);
108+
106109
#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER)
107110
sAppTask.StartStatusLEDTimer();
108111
#endif
@@ -122,7 +125,28 @@ void AppTask::AppTaskMain(void * pvParameter)
122125
void AppTask::ApplicationEventHandler(AppEvent * aEvent)
123126
{
124127
VerifyOrReturn(aEvent->Type == AppEvent::kEventType_Button);
125-
// TODO - trigger some application event
128+
VerifyOrReturn(aEvent->ButtonEvent.Action == static_cast<uint8_t>(SilabsPlatform::ButtonAction::ButtonPressed));
129+
130+
// Simple Application logic that toggles the BoleanState StateValue attribute.
131+
// DO NOT COPY for product logic. LIT ICD app is a test app with very simple application logic to enable testing.
132+
// The goal of the app is just to enable testing of LIT ICD features without impacting product sample apps.
133+
PlatformMgr().ScheduleWork([](intptr_t) {
134+
bool state = true;
135+
136+
Protocols::InteractionModel::Status status = chip::app::Clusters::BooleanState::Attributes::StateValue::Get(1, &state);
137+
if (status != Protocols::InteractionModel::Status::Success)
138+
{
139+
// Failed to read StateValue. Default to true (open state)
140+
state = true;
141+
ChipLogError(NotSpecified, "ERR: reading boolean status value %x", to_underlying(status));
142+
}
143+
144+
status = chip::app::Clusters::BooleanState::Attributes::StateValue::Set(1, !state);
145+
if (status != Protocols::InteractionModel::Status::Success)
146+
{
147+
ChipLogError(NotSpecified, "ERR: updating boolean status value %x", to_underlying(status));
148+
}
149+
});
126150
}
127151

128152
void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
@@ -142,3 +166,15 @@ void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
142166
sAppTask.PostEvent(&button_event);
143167
}
144168
}
169+
170+
// DO NOT COPY for product logic. LIT ICD app is a test app with very simple application logic to enable testing.
171+
void AppTask::OnEnterActiveMode()
172+
{
173+
sAppTask.GetLCD().WriteDemoUI(true);
174+
}
175+
176+
// DO NOT COPY for product logic. LIT ICD app is a test app with very simple application logic to enable testing.
177+
void AppTask::OnEnterIdleMode()
178+
{
179+
sAppTask.GetLCD().WriteDemoUI(false);
180+
}

0 commit comments

Comments
 (0)