Skip to content

Commit d891fd8

Browse files
committed
Commands implementation
1 parent 06b215d commit d891fd8

File tree

11 files changed

+282
-11
lines changed

11 files changed

+282
-11
lines changed

examples/oven-app/oven-app-common/include/CookSurfaceEndpoint.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,17 @@ class CookSurfaceEndpoint
3939
*/
4040
CHIP_ERROR Init();
4141

42-
void HandleOffCommand();
42+
/**
43+
* @brief Returns the cached current On/Off state without querying attributes.
44+
*/
45+
bool CurrentState() const { return currentOnOffState; }
46+
47+
bool GetOnOffState();
48+
49+
/**
50+
* @brief Set On/Off state for the CookSurface.
51+
*/
52+
void SetOnOffState(bool state);
4353

4454
EndpointId GetEndpointId() const { return mEndpointId; }
4555

examples/oven-app/oven-app-common/include/CookTopEndpoint.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ class CookTopEndpoint
3838
*/
3939
CHIP_ERROR Init();
4040

41-
void HandleOffCommand();
41+
/**
42+
* @brief Handle the "off" command for the cooktop.
43+
*/
44+
void SetOnOffState(bool state);
4245

4346
private:
4447
bool currentOnOffState = false;

examples/oven-app/oven-app-common/src/CookSurfaceEndpoint.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,34 @@
1717
*/
1818

1919
#include "CookSurfaceEndpoint.h"
20-
#include <lib/core/CHIPError.h>
20+
#include <app/clusters/on-off-server/on-off-server.h>
21+
#include <protocols/interaction_model/StatusCode.h>
2122

2223
using namespace chip;
24+
using namespace chip::app::Clusters;
2325
using namespace chip::app::Clusters::CookSurface;
2426

2527
CHIP_ERROR CookSurfaceEndpoint::Init()
2628
{
29+
bool state = false;
30+
OnOffServer::Instance().getOnOffValue(mEndpointId, &state);
31+
currentOnOffState = state;
2732
return CHIP_NO_ERROR;
2833
}
2934

30-
void CookSurfaceEndpoint::HandleOffCommand() {}
35+
bool CookSurfaceEndpoint::GetOnOffState()
36+
{
37+
bool state = false;
38+
OnOffServer::Instance().getOnOffValue(mEndpointId, &state);
39+
return state;
40+
}
41+
42+
void CookSurfaceEndpoint::SetOnOffState(bool state)
43+
{
44+
CommandId commandId = state ? OnOff::Commands::On::Id : OnOff::Commands::Off::Id;
45+
auto status = OnOffServer::Instance().setOnOffValue(mEndpointId, commandId, false);
46+
if (status == chip::Protocols::InteractionModel::Status::Success)
47+
{
48+
currentOnOffState = state;
49+
}
50+
}

examples/oven-app/oven-app-common/src/CookTopEndpoint.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,13 @@ CHIP_ERROR CookTopEndpoint::Init()
2727
return CHIP_NO_ERROR;
2828
}
2929

30-
void CookTopEndpoint::HandleOffCommand() {}
30+
void CookTopEndpoint::SetOnOffState(bool state)
31+
{
32+
CommandId commandId = state ? OnOff::Commands::On::Id : OnOff::Commands::Off::Id;
33+
auto status = OnOffServer::Instance().setOnOffValue(mEndpointId, commandId, false);
34+
if (status == chip::Protocols::InteractionModel::Status::Success)
35+
{
36+
currentOnOffState = state;
37+
}
38+
return;
39+
}

examples/oven-app/silabs/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ if (wifi_soc) {
7676
"${examples_plat_dir}",
7777
"${chip_root}/src/lib",
7878
"${examples_common_plat_dir}",
79+
# Added for oven app Option A: expose shared oven-app-common headers to all upstream targets
80+
"${example_oven_dir}/oven-app-common/include",
7981
]
8082

8183
defines = []

examples/oven-app/silabs/include/AppEvent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct AppEvent : public BaseAppEvent
3535
{
3636
uint8_t Action;
3737
int32_t Actor;
38+
void * Context;
3839
} OvenEvent;
3940
};
4041
};

examples/oven-app/silabs/include/AppTask.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "AppEvent.h"
3030
#include "BaseApplication.h"
31+
#include "OvenManager.h"
3132

3233
#include "FreeRTOS.h"
3334
#include "timers.h" // provides FreeRTOS timer support
@@ -81,6 +82,9 @@ class AppTask : public BaseApplication
8182
private:
8283
static AppTask sAppTask;
8384

85+
static void ActionInitiated(OvenManager::Action_t aAction, int32_t aActor, uint8_t * value);
86+
static void ActionCompleted(OvenManager::Action_t aAction);
87+
8488
/**
8589
* @brief Override of BaseApplication::AppInit() virtual method, called by BaseApplication::Init()
8690
*

examples/oven-app/silabs/include/OvenManager.h

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,41 @@
2727
#pragma once
2828

2929
#include "AppSupportedTemperatureLevelsDelegate.h"
30-
#include "CookSurfaceEndpoint.h"
31-
#include "CookTopEndpoint.h"
30+
// Corrected relative paths (silabs/include -> go up two levels to oven-app root)
3231
#include "OvenEndpoint.h"
32+
#include "CookTopEndpoint.h"
33+
#include "CookSurfaceEndpoint.h"
34+
35+
#include "AppEvent.h"
36+
37+
#include <app-common/zap-generated/ids/Attributes.h>
38+
#include <app/clusters/on-off-server/on-off-server.h>
3339
#include <lib/core/DataModelTypes.h>
3440

3541
class OvenManager
3642
{
3743
public:
44+
enum Action_t
45+
{
46+
ON_ACTION = 0,
47+
OFF_ACTION,
48+
49+
INVALID_ACTION
50+
} Action;
51+
52+
enum State_t
53+
{
54+
kState_OffInitiated = 0,
55+
kState_OffCompleted,
56+
kState_OnInitiated,
57+
kState_OnCompleted,
58+
} State;
59+
60+
bool InitiateAction(int32_t aActor, Action_t aAction, uint8_t * aValue);
61+
typedef void (*Callback_fn_initiated)(Action_t, int32_t aActor, uint8_t * value);
62+
typedef void (*Callback_fn_completed)(Action_t);
63+
void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB);
64+
3865
/**
3966
* @brief Initializes the OvenManager and its associated resources.
4067
*
@@ -51,11 +78,20 @@ class OvenManager
5178
CHIP_ERROR SetCookSurfaceInitialState(chip::EndpointId cookSurfaceEndpoint);
5279

5380
CHIP_ERROR SetTemperatureControlledCabinetInitialState(chip::EndpointId temperatureControlledCabinetEndpoint);
81+
void TempCtrlAttributeChangeHandler(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value, uint16_t size);
82+
void OnOffAttributeChangeHandler(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value, uint16_t size);
5483

5584
private:
5685
static OvenManager sOvenMgr;
5786
chip::app::Clusters::AppSupportedTemperatureLevelsDelegate mTemperatureControlDelegate;
5887

88+
State_t mState;
89+
90+
Callback_fn_initiated mActionInitiated_CB;
91+
Callback_fn_completed mActionCompleted_CB;
92+
93+
static void ActuatorMovementHandler(AppEvent * aEvent);
94+
5995
// Define the endpoint ID for the Oven
6096
static constexpr chip::EndpointId kOvenEndpoint = 1;
6197
static constexpr chip::EndpointId kTemperatureControlledCabinetEndpoint = 2;

examples/oven-app/silabs/src/AppTask.cpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ CHIP_ERROR AppTask::AppInit()
7070
GetLCD().Init((uint8_t *) "Oven-App");
7171
#endif
7272

73-
// Initialization of Oven Manager and endpoints of oven and ovenpanel.
73+
// Initialization of Oven Manager and endpoints of oven.
7474
OvenManager::GetInstance().Init();
75-
75+
OvenManager::GetInstance().SetCallbacks(ActionInitiated, ActionCompleted);
7676
// Update the LCD with the Stored value. Show QR Code if not provisioned
7777
#ifdef DISPLAY_ENABLED
7878
GetLCD().WriteDemoUI(false);
@@ -129,3 +129,41 @@ void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
129129
button_event.Handler = BaseApplication::ButtonHandler;
130130
AppTask::GetAppTask().PostEvent(&button_event);
131131
}
132+
133+
void AppTask::ActionInitiated(OvenManager::Action_t aAction, int32_t aActor, uint8_t * aValue)
134+
{
135+
// Action initiated
136+
bool lightOn = aAction == OvenManager::ON_ACTION;
137+
SILABS_LOG("Turning light %s", (lightOn) ? "On" : "Off");
138+
139+
//TODO: Update LED state
140+
141+
#ifdef DISPLAY_ENABLED
142+
sAppTask.GetLCD().WriteDemoUI(lightOn);
143+
#endif
144+
145+
if (aActor == AppEvent::kEventType_Button)
146+
{
147+
sAppTask.mSyncClusterToButtonAction = true;
148+
}
149+
}
150+
151+
void AppTask::ActionCompleted(OvenManager::Action_t aAction)
152+
{
153+
// action has been completed on the oven
154+
if (aAction == OvenManager::ON_ACTION)
155+
{
156+
SILABS_LOG("Oven ON")
157+
}
158+
else if (aAction == OvenManager::OFF_ACTION)
159+
{
160+
SILABS_LOG("Oven OFF")
161+
}
162+
163+
if (sAppTask.mSyncClusterToButtonAction)
164+
{
165+
// chip::DeviceLayer::PlatformMgr().ScheduleWork(UpdateClusterState, reinterpret_cast<intptr_t>(nullptr));
166+
// Schedule work to Update CookTop and CookSurfaceEndpoints (turn on/off)
167+
sAppTask.mSyncClusterToButtonAction = false;
168+
}
169+
}

examples/oven-app/silabs/src/DataModelCallbacks.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <AppConfig.h>
2424

25+
#include "OvenManager.h"
2526
#include <app-common/zap-generated/attributes/Accessors.h>
2627
#include <app-common/zap-generated/callback.h>
2728
#include <app-common/zap-generated/cluster-objects.h>
@@ -36,11 +37,24 @@ using namespace ::chip;
3637
void MatterPostAttributeChangeCallback(const app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size,
3738
uint8_t * value)
3839
{
39-
switch (attributePath.mClusterId)
40+
ClusterId clusterId = attributePath.mClusterId;
41+
AttributeId attributeId = attributePath.mAttributeId;
42+
switch (clusterId)
4043
{
4144
case app::Clusters::Identify::Id:
4245
ChipLogProgress(Zcl, "Identify cluster ID: " ChipLogFormatMEI " Type: %u Value: %u, length %u",
43-
ChipLogValueMEI(attributePath.mAttributeId), type, *value, size);
46+
ChipLogValueMEI(attributeId), type, *value, size);
47+
break;
48+
case app::Clusters::OnOff::Id:
49+
ChipLogProgress(Zcl, "OnOff cluster ID: " ChipLogFormatMEI " Type: %u Value: %u, length %u",
50+
ChipLogValueMEI(attributeId), type, *value, size);
51+
ChipLogProgress(Zcl, "OnOff received for endpoint: %d", attributePath.mEndpointId);
52+
OvenManager::GetInstance().OnOffAttributeChangeHandler(attributePath.mEndpointId, attributeId, value, size);
53+
break;
54+
case app::Clusters::TemperatureControl::Id:
55+
ChipLogProgress(Zcl, "TemperatureControl cluster ID: " ChipLogFormatMEI " Type: %u Value: %u, length %u",
56+
ChipLogValueMEI(attributeId), type, *value, size);
57+
OvenManager::GetInstance().TempCtrlAttributeChangeHandler(attributePath.mEndpointId, attributeId, value, size);
4458
break;
4559
default:
4660
break;

0 commit comments

Comments
 (0)