Skip to content

Commit f49ba2f

Browse files
committed
Clean-up the command handling logic
1 parent 4e9f977 commit f49ba2f

File tree

8 files changed

+47
-51
lines changed

8 files changed

+47
-51
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
@@ -38,9 +38,8 @@ class CookSurfaceEndpoint
3838
CHIP_ERROR Init();
3939

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

4544
bool GetOnOffState();
4645

@@ -50,7 +49,6 @@ class CookSurfaceEndpoint
5049
void SetOnOffState(bool state);
5150

5251
private:
53-
bool currentOnOffState = false;
5452
EndpointId mEndpointId = kInvalidEndpointId;
5553
};
5654

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/AppConfig.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,3 @@
2626
#define APP_TASK_NAME "Oven"
2727

2828
#define BLE_DEV_NAME "Silabs-Oven"
29-
30-
// Time it takes in ms for the simulated actuator to move from one
31-
// state to another.
32-
#define ACTUATOR_MOVEMENT_PERIOD_MS 10

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"
@@ -76,8 +75,34 @@ class OvenManager
7675
*/
7776
static OvenManager & GetInstance() { return sOvenMgr; }
7877

78+
/**
79+
* @brief Handles temperature control attribute changes.
80+
*
81+
* @param endpointId The ID of the endpoint.
82+
* @param attributeId The ID of the attribute.
83+
* @param value Pointer to the new value.
84+
* @param size Size of the new value.
85+
*/
7986
void TempCtrlAttributeChangeHandler(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value, uint16_t size);
87+
88+
/**
89+
* @brief Handles on/off attribute changes.
90+
*
91+
* @param endpointId The ID of the endpoint.
92+
* @param attributeId The ID of the attribute.
93+
* @param value Pointer to the new value.
94+
* @param size Size of the new value.
95+
*/
8096
void OnOffAttributeChangeHandler(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value, uint16_t size);
97+
98+
/**
99+
* @brief Handles oven mode attribute changes.
100+
*
101+
* @param endpointId The ID of the endpoint.
102+
* @param attributeId The ID of the attribute.
103+
* @param value Pointer to the new value.
104+
* @param size Size of the new value.
105+
*/
81106
void OvenModeAttributeChangeHandler(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value, uint16_t size);
82107

83108
/**

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"
@@ -110,21 +109,9 @@ void OvenManager::Init()
110109

111110
void OvenManager::TempCtrlAttributeChangeHandler(EndpointId endpointId, AttributeId attributeId, uint8_t * value, uint16_t size)
112111
{
113-
if (endpointId == kCookSurfaceEndpoint4 || endpointId == kCookSurfaceEndpoint5)
112+
if (endpointId == kTemperatureControlledCabinetEndpoint2)
114113
{
115-
// Handle temperature control attribute changes for the cook surface endpoints
116-
if (*value == 0) // low
117-
{
118-
// TODO: Adjust the temperature-setpoint value in TemperatureControl Cluster accordingly
119-
}
120-
else if (*value == 1) // medium
121-
{
122-
// TODO: Adjust the temperature-setpoint value in TemperatureControl Cluster accordingly
123-
}
124-
else if (*value == 2) // high
125-
{
126-
// TODO: Adjust the temperature-setpoint value in TemperatureControl Cluster accordingly
127-
}
114+
// TODO: Update the LCD with the new Temperature Control attribute value
128115
}
129116
return;
130117
}
@@ -133,7 +120,6 @@ void OvenManager::OnOffAttributeChangeHandler(EndpointId endpointId, AttributeId
133120
{
134121
if (endpointId == kCookTopEndpoint3)
135122
{
136-
// Handle LCD and LED Actions
137123
InitiateAction(AppEvent::kEventType_Oven, *value ? OvenManager::ON_ACTION : OvenManager::OFF_ACTION, value);
138124

139125
// Update CookSurface states accordingly
@@ -174,27 +160,24 @@ bool OvenManager::InitiateAction(int32_t aActor, Action_t aAction, uint8_t * aVa
174160
State_t new_state;
175161

176162
// Initiate Turn On/Off Action only when the previous one is complete.
177-
// if (((mState == kState_OffCompleted) || mOffEffectArmed) && aAction == ON_ACTION)
178163
if (mState == kState_OffCompleted && aAction == ON_ACTION)
179164
{
180165
action_initiated = true;
181-
182-
new_state = kState_OnInitiated;
166+
new_state = kState_OnInitiated;
183167
}
184168
else if (mState == kState_OnCompleted && aAction == OFF_ACTION)
185169
{
186170
action_initiated = true;
187-
188-
new_state = kState_OffInitiated;
171+
new_state = kState_OffInitiated;
189172
}
190173

191174
if (action_initiated && (aAction == ON_ACTION || aAction == OFF_ACTION))
192175
{
193176
mState = new_state;
194177

195178
AppEvent event;
196-
event.Type = AppEvent::kEventType_Oven; // Assuming a distinct action type exists; fallback to Timer if not.
197-
event.OvenEvent.Context = this; // Reuse Context field; adjust if a specific union member exists for action.
179+
event.Type = AppEvent::kEventType_Oven;
180+
event.OvenEvent.Context = this;
198181
event.Handler = ActuatorMovementHandler;
199182
AppTask::GetAppTask().PostEvent(&event);
200183
}
@@ -211,17 +194,16 @@ void OvenManager::ActuatorMovementHandler(AppEvent * aEvent)
211194
{
212195
Action_t actionCompleted = INVALID_ACTION;
213196

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

217199
if (oven->mState == kState_OffInitiated)
218200
{
219-
oven->mState = kState_OffCompleted;
201+
oven->mState = kState_OffCompleted;
220202
actionCompleted = OFF_ACTION;
221203
}
222204
else if (oven->mState == kState_OnInitiated)
223205
{
224-
oven->mState = kState_OnCompleted;
206+
oven->mState = kState_OnCompleted;
225207
actionCompleted = ON_ACTION;
226208
}
227209

@@ -270,15 +252,15 @@ void OvenManager::ProcessOvenModeChange(chip::EndpointId endpointId, uint8_t new
270252
using chip::Protocols::InteractionModel::Status;
271253
ChipLogProgress(AppServer, "OvenManager::ProcessOvenModeChange ep=%u newMode=%u", endpointId, newMode);
272254

273-
// 1. Verify newMode is among supported modes
255+
// Verify newMode is among supported modes
274256
bool supported = TemperatureControlledCabinet::OvenModeDelegate::IsSupportedMode(newMode);
275257
if (!supported)
276258
{
277259
response.status = to_underlying(ModeBase::StatusCode::kUnsupportedMode);
278260
return;
279261
}
280262

281-
// 2. Read current mode
263+
// Read Current Oven Mode
282264
uint8_t currentMode;
283265
Status attrStatus = OvenMode::Attributes::CurrentMode::Get(endpointId, &currentMode);
284266
if (attrStatus != Status::Success)
@@ -289,14 +271,14 @@ void OvenManager::ProcessOvenModeChange(chip::EndpointId endpointId, uint8_t new
289271
return;
290272
}
291273

292-
// 3. No-op
274+
// No action needed if current mode is the same as new mode
293275
if (currentMode == newMode)
294276
{
295277
response.status = to_underlying(ModeBase::StatusCode::kSuccess);
296278
return;
297279
}
298280

299-
// 4. Policy check
281+
// Check if the mode transition is possible
300282
if (IsTransitionBlocked(currentMode, newMode))
301283
{
302284
ChipLogProgress(AppServer, "OvenManager: Blocked transition %u -> %u", currentMode, newMode);
@@ -305,7 +287,7 @@ void OvenManager::ProcessOvenModeChange(chip::EndpointId endpointId, uint8_t new
305287
return;
306288
}
307289

308-
// 5. Write new mode
290+
// Write new mode
309291
Status writeStatus = OvenMode::Attributes::CurrentMode::Set(endpointId, newMode);
310292
if (writeStatus != Status::Success)
311293
{

0 commit comments

Comments
 (0)