Skip to content

Commit c9545d8

Browse files
committed
Address review comments
1 parent caad0fb commit c9545d8

File tree

5 files changed

+172
-44
lines changed

5 files changed

+172
-44
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,18 @@ class TemperatureControlledCabinetEndpoint
8989
{}
9090

9191
/**
92-
* @brief Initialize the temperature controlled cabinet endpoint. Sets the oven mode cluster instance with the appropriate
93-
* delegate.
94-
*
92+
* @brief Initialize the temperature controlled cabinet endpoint. Sets the oven mode cluster instance with the appropriate delegate.
93+
*
9594
* @return returns CHIP_NO_ERROR on success, or an error code on failure.
9695
*/
9796
CHIP_ERROR Init();
9897

99-
private:
98+
/**
99+
* @brief Get the oven mode delegate instance.
100+
*
101+
* @return Reference to the oven mode delegate.
102+
*/
103+
OvenModeDelegate & GetOvenModeDelegate() { return mOvenModeDelegate; }private:
100104
EndpointId mEndpointId = kInvalidEndpointId;
101105
OvenModeDelegate mOvenModeDelegate;
102106
ModeBase::Instance mOvenModeInstance;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ struct AppEvent : public BaseAppEvent
2626
enum AppEventTypes
2727
{
2828
kEventType_Oven = BaseAppEvent::kEventType_Max + 1,
29+
kEventType_CookTop,
30+
kEventType_CookSurface,
2931
kEventType_Install,
3032
};
3133

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,22 @@ class OvenManager
5252

5353
enum State_t
5454
{
55-
kState_OffInitiated = 0,
56-
kState_OffCompleted,
57-
kState_OnInitiated,
58-
kState_OnCompleted,
59-
kState_ActionInProgress,
60-
kState_NoAction,
55+
kCookTopState_OffInitiated = 0,
56+
kCookTopState_OffCompleted,
57+
kCookTopState_OnInitiated,
58+
kCookTopState_OnCompleted,
59+
60+
// Cook Surface states
61+
kCookSurfaceState_OffInitiated,
62+
kCookSurfaceState_OffCompleted,
63+
kCookSurfaceState_OnInitiated,
64+
kCookSurfaceState_OnCompleted,
65+
kCookSurfaceState_ActionInProgress,
66+
kCookSurfaceState_NoAction,
6167
} State;
6268

6369
bool InitiateAction(int32_t aActor, Action_t aAction, uint8_t * aValue);
70+
bool InitiateCookSurfaceAction(int32_t aActor, Action_t aAction, uint8_t * aValue, chip::EndpointId endpointId);
6471
typedef void (*Callback_fn_initiated)(Action_t, int32_t aActor, uint8_t * value);
6572
typedef void (*Callback_fn_completed)(Action_t);
6673
void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB);
@@ -122,7 +129,9 @@ class OvenManager
122129
static OvenManager sOvenMgr;
123130
chip::app::Clusters::AppSupportedTemperatureLevelsDelegate mTemperatureControlDelegate;
124131

125-
State_t mState;
132+
State_t mCookTopState;
133+
State_t mCookSurfaceState1;
134+
State_t mCookSurfaceState2;
126135

127136
Callback_fn_initiated mActionInitiated_CB;
128137
Callback_fn_completed mActionCompleted_CB;

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,23 @@ 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-
bool lightOn = aAction == OvenManager::ON_ACTION;
136-
SILABS_LOG("Turning light %s", (lightOn) ? "On" : "Off");
137-
138-
// TODO: Update LED state
139-
135+
if (aActor == AppEvent::kEventType_CookTop)
136+
{
137+
bool lightOn = aAction == OvenManager::ON_ACTION;
138+
ChipLogProgress(AppServer, "Turning CookTop %s", (lightOn) ? "On" : "Off");
139+
140+
// TODO: Update LED state
141+
140142
#ifdef DISPLAY_ENABLED
141-
sAppTask.GetLCD().WriteDemoUI(lightOn);
143+
sAppTask.GetLCD().WriteDemoUI(lightOn);
142144
#endif
145+
}
146+
147+
if (aActor == AppEvent::kEventType_CookSurface)
148+
{
149+
bool lightOn = aAction == OvenManager::ON_ACTION;
150+
ChipLogProgress(AppServer, "Turning CookSurface %s", (lightOn) ? "On" : "Off");
151+
}
143152

144153
if (aActor == AppEvent::kEventType_Button)
145154
{
@@ -152,11 +161,11 @@ void AppTask::ActionCompleted(OvenManager::Action_t aAction)
152161
// Action has been completed on the oven
153162
if (aAction == OvenManager::ON_ACTION)
154163
{
155-
SILABS_LOG("Oven ON");
164+
ChipLogProgress(AppServer, "ON action completed");
156165
}
157166
else if (aAction == OvenManager::OFF_ACTION)
158167
{
159-
SILABS_LOG("Oven OFF");
168+
ChipLogProgress(AppServer, "OFF action completed");
160169
}
161170

162171
if (sAppTask.mSyncClusterToButtonAction)

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

Lines changed: 129 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ OvenManager OvenManager::sOvenMgr;
4545
void OvenManager::Init()
4646
{
4747
DeviceLayer::PlatformMgr().LockChipStack();
48+
49+
// Initialize states
50+
mCookTopState = kCookTopState_OffCompleted;
51+
mCookSurfaceState1 = kCookSurfaceState_OffCompleted;
52+
mCookSurfaceState2 = kCookSurfaceState_OffCompleted;
53+
4854
// Endpoint initializations
4955
VerifyOrReturn(mOvenEndpoint.Init() == CHIP_NO_ERROR, ChipLogError(AppServer, "OvenEndpoint Init failed"));
5056

@@ -166,22 +172,25 @@ void OvenManager::OnOffAttributeChangeHandler(EndpointId endpointId, AttributeId
166172
{
167173
switch (endpointId)
168174
{
169-
case kCookTopEndpoint3:
170-
InitiateAction(AppEvent::kEventType_Oven, *value ? OvenManager::ON_ACTION : OvenManager::OFF_ACTION, value);
175+
case kCookTopEndpoint:
176+
InitiateAction(AppEvent::kEventType_CookTop, *value ? OvenManager::ON_ACTION : OvenManager::OFF_ACTION, value);
171177
// Update CookSurface states accordingly
172178
mCookSurfaceEndpoint1.SetOnOffState(*value);
173179
mCookSurfaceEndpoint2.SetOnOffState(*value);
174180
break;
175181
case kCookSurfaceEndpoint1:
176182
case kCookSurfaceEndpoint2:
177183
// Handle On/Off attribute changes for the cook surface endpoints
184+
InitiateCookSurfaceAction(AppEvent::kEventType_CookSurface, *value ? OvenManager::ON_ACTION : OvenManager::OFF_ACTION, value, endpointId);
178185
{
179-
bool cookSurfaceEndpoint1State = mCookSurfaceEndpoint1.GetOnOffState();
180-
bool cookSurfaceEndpoint2State = mCookSurfaceEndpoint2.GetOnOffState();
186+
bool cookSurfaceEndpoint1State;
187+
bool cookSurfaceEndpoint2State;
188+
mCookSurfaceEndpoint1.GetOnOffState(cookSurfaceEndpoint1State);
189+
mCookSurfaceEndpoint2.GetOnOffState(cookSurfaceEndpoint2State);
181190
// Check if both cooksurfaces are off. If yes, turn off the cooktop (call cooktop.TurnOffCookTop)
182191
if (cookSurfaceEndpoint1State == false && cookSurfaceEndpoint2State == false)
183192
{
184-
mCookTopEndpoint3.SetOnOffState(false);
193+
mCookTopEndpoint.SetOnOffState(false);
185194
}
186195
}
187196
break;
@@ -193,7 +202,7 @@ void OvenManager::OnOffAttributeChangeHandler(EndpointId endpointId, AttributeId
193202
void OvenManager::OvenModeAttributeChangeHandler(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value,
194203
uint16_t size)
195204
{
196-
VerifyOrReturn(endpointId == kTemperatureControlledCabinetEndpoint2,
205+
VerifyOrReturn(endpointId == kTemperatureControlledCabinetEndpoint,
197206
ChipLogError(AppServer, "Command received over Unsupported Endpoint"));
198207
// TODO: Update the LCD with the new Oven Mode
199208
return;
@@ -211,23 +220,23 @@ bool OvenManager::InitiateAction(int32_t aActor, Action_t aAction, uint8_t * aVa
211220
State_t new_state;
212221

213222
// Initiate Turn On/Off Action only when the previous one is complete.
214-
if (mState == kState_OffCompleted && aAction == ON_ACTION)
223+
if (mCookTopState == kCookTopState_OffCompleted && aAction == ON_ACTION)
215224
{
216225
action_initiated = true;
217-
new_state = kState_OnInitiated;
226+
new_state = kCookTopState_OnInitiated;
218227
}
219-
else if (mState == kState_OnCompleted && aAction == OFF_ACTION)
228+
else if (mCookTopState == kCookTopState_OnCompleted && aAction == OFF_ACTION)
220229
{
221230
action_initiated = true;
222-
new_state = kState_OffInitiated;
231+
new_state = kCookTopState_OffInitiated;
223232
}
224233

225234
if (action_initiated && (aAction == ON_ACTION || aAction == OFF_ACTION))
226235
{
227-
mState = new_state;
236+
mCookTopState = new_state;
228237

229238
AppEvent event;
230-
event.Type = AppEvent::kEventType_Oven;
239+
event.Type = AppEvent::kEventType_CookTop;
231240
event.OvenEvent.Context = this;
232241
event.Handler = ActuatorMovementHandler;
233242
AppTask::GetAppTask().PostEvent(&event);
@@ -241,21 +250,116 @@ bool OvenManager::InitiateAction(int32_t aActor, Action_t aAction, uint8_t * aVa
241250
return action_initiated;
242251
}
243252

244-
void OvenManager::ActuatorMovementHandler(AppEvent * aEvent)
253+
bool OvenManager::InitiateCookSurfaceAction(int32_t aActor, Action_t aAction, uint8_t * aValue, chip::EndpointId endpointId)
245254
{
246-
Action_t actionCompleted = INVALID_ACTION;
255+
bool action_initiated = false;
256+
State_t new_state;
257+
State_t * currentState = nullptr;
247258

248-
OvenManager * oven = static_cast<OvenManager *>(aEvent->OvenEvent.Context);
259+
// Get the appropriate state pointer based on endpoint
260+
if (endpointId == kCookSurfaceEndpoint1)
261+
{
262+
currentState = &mCookSurfaceState1;
263+
}
264+
else if (endpointId == kCookSurfaceEndpoint2)
265+
{
266+
currentState = &mCookSurfaceState2;
267+
}
268+
else
269+
{
270+
return false; // Invalid endpoint
271+
}
249272

250-
if (oven->mState == kState_OffInitiated)
273+
// Initiate Turn On/Off Action only when the previous one is complete.
274+
if (*currentState == kCookSurfaceState_OffCompleted && aAction == ON_ACTION)
251275
{
252-
oven->mState = kState_OffCompleted;
253-
actionCompleted = OFF_ACTION;
276+
action_initiated = true;
277+
new_state = kCookSurfaceState_OnInitiated;
254278
}
255-
else if (oven->mState == kState_OnInitiated)
279+
else if (*currentState == kCookSurfaceState_OnCompleted && aAction == OFF_ACTION)
256280
{
257-
oven->mState = kState_OnCompleted;
258-
actionCompleted = ON_ACTION;
281+
action_initiated = true;
282+
new_state = kCookSurfaceState_OffInitiated;
283+
}
284+
285+
if (action_initiated && (aAction == ON_ACTION || aAction == OFF_ACTION))
286+
{
287+
*currentState = new_state;
288+
289+
AppEvent event;
290+
event.Type = AppEvent::kEventType_CookSurface;
291+
event.OvenEvent.Context = this;
292+
event.OvenEvent.Action = aAction;
293+
event.OvenEvent.Actor = endpointId; // Store endpoint ID in Actor field
294+
event.Handler = ActuatorMovementHandler;
295+
AppTask::GetAppTask().PostEvent(&event);
296+
}
297+
298+
if (action_initiated && mActionInitiated_CB)
299+
{
300+
mActionInitiated_CB(aAction, aActor, aValue);
301+
}
302+
303+
return action_initiated;
304+
}
305+
306+
void OvenManager::ActuatorMovementHandler(AppEvent * aEvent)
307+
{
308+
Action_t actionCompleted = INVALID_ACTION;
309+
OvenManager * oven = static_cast<OvenManager *>(aEvent->OvenEvent.Context);
310+
311+
switch (aEvent->Type)
312+
{
313+
case AppEvent::kEventType_CookTop:
314+
{
315+
// Handle CookTop state transitions
316+
if (oven->mCookTopState == kCookTopState_OffInitiated)
317+
{
318+
oven->mCookTopState = kCookTopState_OffCompleted;
319+
actionCompleted = OFF_ACTION;
320+
}
321+
else if (oven->mCookTopState == kCookTopState_OnInitiated)
322+
{
323+
oven->mCookTopState = kCookTopState_OnCompleted;
324+
actionCompleted = ON_ACTION;
325+
}
326+
}
327+
break;
328+
case AppEvent::kEventType_CookSurface:
329+
{
330+
// Handle CookSurface state transitions
331+
chip::EndpointId endpointId = static_cast<chip::EndpointId>(aEvent->OvenEvent.Actor);
332+
State_t * currentState = nullptr;
333+
334+
// Get the appropriate state pointer based on endpoint
335+
if (endpointId == kCookSurfaceEndpoint1)
336+
{
337+
currentState = &oven->mCookSurfaceState1;
338+
}
339+
else if (endpointId == kCookSurfaceEndpoint2)
340+
{
341+
currentState = &oven->mCookSurfaceState2;
342+
}
343+
else
344+
{
345+
ChipLogError(AppServer, "Invalid CookSurface endpoint ID");
346+
return; // Invalid endpoint
347+
}
348+
349+
if (*currentState == kCookSurfaceState_OffInitiated)
350+
{
351+
*currentState = kCookSurfaceState_OffCompleted;
352+
actionCompleted = OFF_ACTION;
353+
}
354+
else if (*currentState == kCookSurfaceState_OnInitiated)
355+
{
356+
*currentState = kCookSurfaceState_OnCompleted;
357+
actionCompleted = ON_ACTION;
358+
}
359+
}
360+
break;
361+
default:
362+
break;
259363
}
260364

261365
if (actionCompleted != INVALID_ACTION)
@@ -278,9 +382,9 @@ struct BlockedTransition
278382

279383
// Disallowed OvenMode Transitions.
280384
static constexpr BlockedTransition kBlockedTransitions[] = {
281-
{ TemperatureControlledCabinet::OvenModeDelegate::kModeGrill, TemperatureControlledCabinet::OvenModeDelegate::kModeProofing },
282-
{ TemperatureControlledCabinet::OvenModeDelegate::kModeProofing, TemperatureControlledCabinet::OvenModeDelegate::kModeClean },
283-
{ TemperatureControlledCabinet::OvenModeDelegate::kModeClean, TemperatureControlledCabinet::OvenModeDelegate::kModeBake },
385+
{ to_underlying(TemperatureControlledCabinet::OvenModeDelegate::OvenModes::kModeGrill), to_underlying(TemperatureControlledCabinet::OvenModeDelegate::OvenModes::kModeProofing) },
386+
{ to_underlying(TemperatureControlledCabinet::OvenModeDelegate::OvenModes::kModeProofing), to_underlying(TemperatureControlledCabinet::OvenModeDelegate::OvenModes::kModeClean) },
387+
{ to_underlying(TemperatureControlledCabinet::OvenModeDelegate::OvenModes::kModeClean), to_underlying(TemperatureControlledCabinet::OvenModeDelegate::OvenModes::kModeBake) },
284388
};
285389

286390
static bool IsTransitionBlocked(uint8_t fromMode, uint8_t toMode)
@@ -304,7 +408,7 @@ void OvenManager::ProcessOvenModeChange(chip::EndpointId endpointId, uint8_t new
304408
ChipLogProgress(AppServer, "OvenManager::ProcessOvenModeChange ep=%u newMode=%u", endpointId, newMode);
305409

306410
// Verify newMode is among supported modes
307-
bool supported = TemperatureControlledCabinet::OvenModeDelegate::IsSupportedMode(newMode);
411+
bool supported = mTemperatureControlledCabinetEndpoint.GetOvenModeDelegate().IsSupportedMode(newMode);
308412
if (!supported)
309413
{
310414
response.status = to_underlying(ModeBase::StatusCode::kUnsupportedMode);

0 commit comments

Comments
 (0)