Skip to content

Commit f44bcdd

Browse files
committed
Clean-up the command handling logic
1 parent 0099e9e commit f44bcdd

File tree

7 files changed

+47
-47
lines changed

7 files changed

+47
-47
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ class CookSurfaceEndpoint
4040
CHIP_ERROR Init();
4141

4242
/**
43-
* @brief Returns the cached current On/Off state without querying attributes.
43+
* @brief Returns the current On/Off state.
4444
*/
45-
bool CurrentState() const { return currentOnOffState; }
4645

4746
bool GetOnOffState();
4847

@@ -54,7 +53,6 @@ class CookSurfaceEndpoint
5453
EndpointId GetEndpointId() const { return mEndpointId; }
5554

5655
private:
57-
bool currentOnOffState = false;
5856
EndpointId mEndpointId = kInvalidEndpointId;
5957
};
6058

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ CHIP_ERROR CookSurfaceEndpoint::Init()
2828
{
2929
bool state = false;
3030
OnOffServer::Instance().getOnOffValue(mEndpointId, &state);
31-
currentOnOffState = state;
3231
return CHIP_NO_ERROR;
3332
}
3433

@@ -43,8 +42,8 @@ void CookSurfaceEndpoint::SetOnOffState(bool state)
4342
{
4443
CommandId commandId = state ? OnOff::Commands::On::Id : OnOff::Commands::Off::Id;
4544
auto status = OnOffServer::Instance().setOnOffValue(mEndpointId, commandId, false);
46-
if (status == chip::Protocols::InteractionModel::Status::Success)
45+
if (status != Protocols::InteractionModel::Status::Success)
4746
{
48-
currentOnOffState = state;
47+
ChipLogError(AppServer, "ERR: updating on/off %x", to_underlying(status));
4948
}
5049
}

examples/oven-app/silabs/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ 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
8079
"${example_oven_dir}/oven-app-common/include",
8180
]
8281

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#pragma once
2828

2929
#include "AppSupportedTemperatureLevelsDelegate.h"
30-
// Corrected relative paths (silabs/include -> go up two levels to oven-app root)
3130
#include "OvenEndpoint.h"
3231
#include "CookTopEndpoint.h"
3332
#include "CookSurfaceEndpoint.h"
@@ -79,8 +78,34 @@ class OvenManager
7978
CHIP_ERROR SetCookSurfaceInitialState(chip::EndpointId cookSurfaceEndpoint);
8079

8180
CHIP_ERROR SetTemperatureControlledCabinetInitialState(chip::EndpointId temperatureControlledCabinetEndpoint);
81+
/**
82+
* @brief Handles temperature control attribute changes.
83+
*
84+
* @param endpointId The ID of the endpoint.
85+
* @param attributeId The ID of the attribute.
86+
* @param value Pointer to the new value.
87+
* @param size Size of the new value.
88+
*/
8289
void TempCtrlAttributeChangeHandler(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value, uint16_t size);
90+
91+
/**
92+
* @brief Handles on/off attribute changes.
93+
*
94+
* @param endpointId The ID of the endpoint.
95+
* @param attributeId The ID of the attribute.
96+
* @param value Pointer to the new value.
97+
* @param size Size of the new value.
98+
*/
8399
void OnOffAttributeChangeHandler(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value, uint16_t size);
100+
101+
/**
102+
* @brief Handles oven mode attribute changes.
103+
*
104+
* @param endpointId The ID of the endpoint.
105+
* @param attributeId The ID of the attribute.
106+
* @param value Pointer to the new value.
107+
* @param size Size of the new value.
108+
*/
84109
void OvenModeAttributeChangeHandler(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value, uint16_t size);
85110

86111
/**

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,10 @@ void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
132132

133133
void AppTask::ActionInitiated(OvenManager::Action_t aAction, int32_t aActor, uint8_t * aValue)
134134
{
135-
// Action initiated
136135
bool lightOn = aAction == OvenManager::ON_ACTION;
137136
SILABS_LOG("Turning light %s", (lightOn) ? "On" : "Off");
138137

139-
//TODO: Update LED state
138+
// TODO: Update LED state
140139

141140
#ifdef DISPLAY_ENABLED
142141
sAppTask.GetLCD().WriteDemoUI(lightOn);
@@ -150,20 +149,19 @@ void AppTask::ActionInitiated(OvenManager::Action_t aAction, int32_t aActor, uin
150149

151150
void AppTask::ActionCompleted(OvenManager::Action_t aAction)
152151
{
153-
// action has been completed on the oven
152+
// Action has been completed on the oven
154153
if (aAction == OvenManager::ON_ACTION)
155154
{
156-
SILABS_LOG("Oven ON")
155+
SILABS_LOG("Oven ON");
157156
}
158157
else if (aAction == OvenManager::OFF_ACTION)
159158
{
160-
SILABS_LOG("Oven OFF")
159+
SILABS_LOG("Oven OFF");
161160
}
162161

163162
if (sAppTask.mSyncClusterToButtonAction)
164163
{
165-
// chip::DeviceLayer::PlatformMgr().ScheduleWork(UpdateClusterState, reinterpret_cast<intptr_t>(nullptr));
166-
// Schedule work to Update CookTop and CookSurfaceEndpoints (turn on/off)
164+
// TODO: Schedule work to Update CookTop and CookSurfaceEndpoints (turn on/off)
167165
sAppTask.mSyncClusterToButtonAction = false;
168166
}
169167
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ void MatterPostAttributeChangeCallback(const app::ConcreteAttributePath & attrib
4848
case app::Clusters::OnOff::Id:
4949
ChipLogProgress(Zcl, "OnOff cluster ID: " ChipLogFormatMEI " Type: %u Value: %u, length %u",
5050
ChipLogValueMEI(attributeId), type, *value, size);
51-
ChipLogProgress(Zcl, "OnOff received for endpoint: %d", attributePath.mEndpointId);
5251
OvenManager::GetInstance().OnOffAttributeChangeHandler(attributePath.mEndpointId, attributeId, value, size);
5352
break;
5453
case app::Clusters::TemperatureControl::Id:

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

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
#include "OvenManager.h"
20-
// Corrected relative paths to shared oven-app-common headers (src/ -> ../../)
2120
#include "CookSurfaceEndpoint.h"
2221
#include "CookTopEndpoint.h"
2322
#include "OvenEndpoint.h"
@@ -145,21 +144,9 @@ CHIP_ERROR OvenManager::SetTemperatureControlledCabinetInitialState(EndpointId t
145144

146145
void OvenManager::TempCtrlAttributeChangeHandler(EndpointId endpointId, AttributeId attributeId, uint8_t * value, uint16_t size)
147146
{
148-
if (endpointId == kCookSurfaceEndpoint4 || endpointId == kCookSurfaceEndpoint5)
147+
if (endpointId == kTemperatureControlledCabinetEndpoint2)
149148
{
150-
// Handle temperature control attribute changes for the cook surface endpoints
151-
if (*value == 0) // low
152-
{
153-
// TODO: Adjust the temperature-setpoint value in TemperatureControl Cluster accordingly
154-
}
155-
else if (*value == 1) // medium
156-
{
157-
// TODO: Adjust the temperature-setpoint value in TemperatureControl Cluster accordingly
158-
}
159-
else if (*value == 2) // high
160-
{
161-
// TODO: Adjust the temperature-setpoint value in TemperatureControl Cluster accordingly
162-
}
149+
// TODO: Update the LCD with the new Temperature Control attribute value
163150
}
164151
return;
165152
}
@@ -168,7 +155,6 @@ void OvenManager::OnOffAttributeChangeHandler(EndpointId endpointId, AttributeId
168155
{
169156
if (endpointId == kCookTopEndpoint3)
170157
{
171-
// Handle LCD and LED Actions
172158
InitiateAction(AppEvent::kEventType_Oven, *value ? OvenManager::ON_ACTION : OvenManager::OFF_ACTION, value);
173159

174160
// Update CookSurface states accordingly
@@ -209,27 +195,24 @@ bool OvenManager::InitiateAction(int32_t aActor, Action_t aAction, uint8_t * aVa
209195
State_t new_state;
210196

211197
// Initiate Turn On/Off Action only when the previous one is complete.
212-
// if (((mState == kState_OffCompleted) || mOffEffectArmed) && aAction == ON_ACTION)
213198
if (mState == kState_OffCompleted && aAction == ON_ACTION)
214199
{
215200
action_initiated = true;
216-
217-
new_state = kState_OnInitiated;
201+
new_state = kState_OnInitiated;
218202
}
219203
else if (mState == kState_OnCompleted && aAction == OFF_ACTION)
220204
{
221205
action_initiated = true;
222-
223-
new_state = kState_OffInitiated;
206+
new_state = kState_OffInitiated;
224207
}
225208

226209
if (action_initiated && (aAction == ON_ACTION || aAction == OFF_ACTION))
227210
{
228211
mState = new_state;
229212

230213
AppEvent event;
231-
event.Type = AppEvent::kEventType_Oven; // Assuming a distinct action type exists; fallback to Timer if not.
232-
event.OvenEvent.Context = this; // Reuse Context field; adjust if a specific union member exists for action.
214+
event.Type = AppEvent::kEventType_Oven;
215+
event.OvenEvent.Context = this;
233216
event.Handler = ActuatorMovementHandler;
234217
AppTask::GetAppTask().PostEvent(&event);
235218
}
@@ -246,17 +229,16 @@ void OvenManager::ActuatorMovementHandler(AppEvent * aEvent)
246229
{
247230
Action_t actionCompleted = INVALID_ACTION;
248231

249-
// Correct union member: event posted stored context in OvenEvent.Context, not TimerEvent.Context.
250232
OvenManager * oven = static_cast<OvenManager *>(aEvent->OvenEvent.Context);
251233

252234
if (oven->mState == kState_OffInitiated)
253235
{
254-
oven->mState = kState_OffCompleted;
236+
oven->mState = kState_OffCompleted;
255237
actionCompleted = OFF_ACTION;
256238
}
257239
else if (oven->mState == kState_OnInitiated)
258240
{
259-
oven->mState = kState_OnCompleted;
241+
oven->mState = kState_OnCompleted;
260242
actionCompleted = ON_ACTION;
261243
}
262244

@@ -305,15 +287,15 @@ void OvenManager::ProcessOvenModeChange(chip::EndpointId endpointId, uint8_t new
305287
using chip::Protocols::InteractionModel::Status;
306288
ChipLogProgress(AppServer, "OvenManager::ProcessOvenModeChange ep=%u newMode=%u", endpointId, newMode);
307289

308-
// 1. Verify newMode is among supported modes
290+
// Verify newMode is among supported modes
309291
bool supported = TemperatureControlledCabinet::OvenModeDelegate::IsSupportedMode(newMode);
310292
if (!supported)
311293
{
312294
response.status = to_underlying(ModeBase::StatusCode::kUnsupportedMode);
313295
return;
314296
}
315297

316-
// 2. Read current mode
298+
// Read Current Oven Mode
317299
uint8_t currentMode;
318300
Status attrStatus = OvenMode::Attributes::CurrentMode::Get(endpointId, &currentMode);
319301
if (attrStatus != Status::Success)
@@ -324,14 +306,14 @@ void OvenManager::ProcessOvenModeChange(chip::EndpointId endpointId, uint8_t new
324306
return;
325307
}
326308

327-
// 3. No-op
309+
// No action needed if current mode is the same as new mode
328310
if (currentMode == newMode)
329311
{
330312
response.status = to_underlying(ModeBase::StatusCode::kSuccess);
331313
return;
332314
}
333315

334-
// 4. Policy check
316+
// Check if the mode transition is possible
335317
if (IsTransitionBlocked(currentMode, newMode))
336318
{
337319
ChipLogProgress(AppServer, "OvenManager: Blocked transition %u -> %u", currentMode, newMode);
@@ -340,7 +322,7 @@ void OvenManager::ProcessOvenModeChange(chip::EndpointId endpointId, uint8_t new
340322
return;
341323
}
342324

343-
// 5. Write new mode
325+
// Write new mode
344326
Status writeStatus = OvenMode::Attributes::CurrentMode::Set(endpointId, newMode);
345327
if (writeStatus != Status::Success)
346328
{

0 commit comments

Comments
 (0)