Skip to content

Commit d3ee7de

Browse files
committed
Address review comments
1 parent 5b3de4b commit d3ee7de

File tree

5 files changed

+173
-45
lines changed

5 files changed

+173
-45
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
@@ -51,15 +51,22 @@ class OvenManager
5151

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

6268
bool InitiateAction(int32_t aActor, Action_t aAction, uint8_t * aValue);
69+
bool InitiateCookSurfaceAction(int32_t aActor, Action_t aAction, uint8_t * aValue, chip::EndpointId endpointId);
6370
typedef void (*Callback_fn_initiated)(Action_t, int32_t aActor, uint8_t * value);
6471
typedef void (*Callback_fn_completed)(Action_t);
6572
void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB);
@@ -121,7 +128,9 @@ class OvenManager
121128
static OvenManager sOvenMgr;
122129
chip::app::Clusters::AppSupportedTemperatureLevelsDelegate mTemperatureControlDelegate;
123130

124-
State_t mState;
131+
State_t mCookTopState;
132+
State_t mCookSurfaceState1;
133+
State_t mCookSurfaceState2;
125134

126135
Callback_fn_initiated mActionInitiated_CB;
127136
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: 130 additions & 26 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

@@ -86,7 +92,7 @@ void OvenManager::Init()
8692

8793
// Get CookTop On/Off value
8894
// OnOffServer::Instance().getOnOffValue(1, &currentLedState);
89-
// mState = currentLedState ? kState_OnCompleted : kState_OffCompleted;
95+
// mCookTopState = currentLedState ? kState_OnCompleted : kState_OffCompleted;
9096

9197
DeviceLayer::PlatformMgr().UnlockChipStack();
9298
}
@@ -146,22 +152,25 @@ void OvenManager::OnOffAttributeChangeHandler(EndpointId endpointId, AttributeId
146152
{
147153
switch (endpointId)
148154
{
149-
case kCookTopEndpoint3:
150-
InitiateAction(AppEvent::kEventType_Oven, *value ? OvenManager::ON_ACTION : OvenManager::OFF_ACTION, value);
155+
case kCookTopEndpoint:
156+
InitiateAction(AppEvent::kEventType_CookTop, *value ? OvenManager::ON_ACTION : OvenManager::OFF_ACTION, value);
151157
// Update CookSurface states accordingly
152158
mCookSurfaceEndpoint1.SetOnOffState(*value);
153159
mCookSurfaceEndpoint2.SetOnOffState(*value);
154160
break;
155161
case kCookSurfaceEndpoint1:
156162
case kCookSurfaceEndpoint2:
157163
// Handle On/Off attribute changes for the cook surface endpoints
164+
InitiateCookSurfaceAction(AppEvent::kEventType_CookSurface, *value ? OvenManager::ON_ACTION : OvenManager::OFF_ACTION, value, endpointId);
158165
{
159-
bool cookSurfaceEndpoint1State = mCookSurfaceEndpoint1.GetOnOffState();
160-
bool cookSurfaceEndpoint2State = mCookSurfaceEndpoint2.GetOnOffState();
166+
bool cookSurfaceEndpoint1State;
167+
bool cookSurfaceEndpoint2State;
168+
mCookSurfaceEndpoint1.GetOnOffState(cookSurfaceEndpoint1State);
169+
mCookSurfaceEndpoint2.GetOnOffState(cookSurfaceEndpoint2State);
161170
// Check if both cooksurfaces are off. If yes, turn off the cooktop (call cooktop.TurnOffCookTop)
162171
if (cookSurfaceEndpoint1State == false && cookSurfaceEndpoint2State == false)
163172
{
164-
mCookTopEndpoint3.SetOnOffState(false);
173+
mCookTopEndpoint.SetOnOffState(false);
165174
}
166175
}
167176
break;
@@ -173,7 +182,7 @@ void OvenManager::OnOffAttributeChangeHandler(EndpointId endpointId, AttributeId
173182
void OvenManager::OvenModeAttributeChangeHandler(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value,
174183
uint16_t size)
175184
{
176-
VerifyOrReturn(endpointId == kTemperatureControlledCabinetEndpoint2,
185+
VerifyOrReturn(endpointId == kTemperatureControlledCabinetEndpoint,
177186
ChipLogError(AppServer, "Command received over Unsupported Endpoint"));
178187
// TODO: Update the LCD with the new Oven Mode
179188
return;
@@ -191,23 +200,23 @@ bool OvenManager::InitiateAction(int32_t aActor, Action_t aAction, uint8_t * aVa
191200
State_t new_state;
192201

193202
// Initiate Turn On/Off Action only when the previous one is complete.
194-
if (mState == kState_OffCompleted && aAction == ON_ACTION)
203+
if (mCookTopState == kCookTopState_OffCompleted && aAction == ON_ACTION)
195204
{
196205
action_initiated = true;
197-
new_state = kState_OnInitiated;
206+
new_state = kCookTopState_OnInitiated;
198207
}
199-
else if (mState == kState_OnCompleted && aAction == OFF_ACTION)
208+
else if (mCookTopState == kCookTopState_OnCompleted && aAction == OFF_ACTION)
200209
{
201210
action_initiated = true;
202-
new_state = kState_OffInitiated;
211+
new_state = kCookTopState_OffInitiated;
203212
}
204213

205214
if (action_initiated && (aAction == ON_ACTION || aAction == OFF_ACTION))
206215
{
207-
mState = new_state;
216+
mCookTopState = new_state;
208217

209218
AppEvent event;
210-
event.Type = AppEvent::kEventType_Oven;
219+
event.Type = AppEvent::kEventType_CookTop;
211220
event.OvenEvent.Context = this;
212221
event.Handler = ActuatorMovementHandler;
213222
AppTask::GetAppTask().PostEvent(&event);
@@ -221,21 +230,116 @@ bool OvenManager::InitiateAction(int32_t aActor, Action_t aAction, uint8_t * aVa
221230
return action_initiated;
222231
}
223232

224-
void OvenManager::ActuatorMovementHandler(AppEvent * aEvent)
233+
bool OvenManager::InitiateCookSurfaceAction(int32_t aActor, Action_t aAction, uint8_t * aValue, chip::EndpointId endpointId)
225234
{
226-
Action_t actionCompleted = INVALID_ACTION;
235+
bool action_initiated = false;
236+
State_t new_state;
237+
State_t * currentState = nullptr;
227238

228-
OvenManager * oven = static_cast<OvenManager *>(aEvent->OvenEvent.Context);
239+
// Get the appropriate state pointer based on endpoint
240+
if (endpointId == kCookSurfaceEndpoint1)
241+
{
242+
currentState = &mCookSurfaceState1;
243+
}
244+
else if (endpointId == kCookSurfaceEndpoint2)
245+
{
246+
currentState = &mCookSurfaceState2;
247+
}
248+
else
249+
{
250+
return false; // Invalid endpoint
251+
}
229252

230-
if (oven->mState == kState_OffInitiated)
253+
// Initiate Turn On/Off Action only when the previous one is complete.
254+
if (*currentState == kCookSurfaceState_OffCompleted && aAction == ON_ACTION)
231255
{
232-
oven->mState = kState_OffCompleted;
233-
actionCompleted = OFF_ACTION;
256+
action_initiated = true;
257+
new_state = kCookSurfaceState_OnInitiated;
234258
}
235-
else if (oven->mState == kState_OnInitiated)
259+
else if (*currentState == kCookSurfaceState_OnCompleted && aAction == OFF_ACTION)
236260
{
237-
oven->mState = kState_OnCompleted;
238-
actionCompleted = ON_ACTION;
261+
action_initiated = true;
262+
new_state = kCookSurfaceState_OffInitiated;
263+
}
264+
265+
if (action_initiated && (aAction == ON_ACTION || aAction == OFF_ACTION))
266+
{
267+
*currentState = new_state;
268+
269+
AppEvent event;
270+
event.Type = AppEvent::kEventType_CookSurface;
271+
event.OvenEvent.Context = this;
272+
event.OvenEvent.Action = aAction;
273+
event.OvenEvent.Actor = endpointId; // Store endpoint ID in Actor field
274+
event.Handler = ActuatorMovementHandler;
275+
AppTask::GetAppTask().PostEvent(&event);
276+
}
277+
278+
if (action_initiated && mActionInitiated_CB)
279+
{
280+
mActionInitiated_CB(aAction, aActor, aValue);
281+
}
282+
283+
return action_initiated;
284+
}
285+
286+
void OvenManager::ActuatorMovementHandler(AppEvent * aEvent)
287+
{
288+
Action_t actionCompleted = INVALID_ACTION;
289+
OvenManager * oven = static_cast<OvenManager *>(aEvent->OvenEvent.Context);
290+
291+
switch (aEvent->Type)
292+
{
293+
case AppEvent::kEventType_CookTop:
294+
{
295+
// Handle CookTop state transitions
296+
if (oven->mCookTopState == kCookTopState_OffInitiated)
297+
{
298+
oven->mCookTopState = kCookTopState_OffCompleted;
299+
actionCompleted = OFF_ACTION;
300+
}
301+
else if (oven->mCookTopState == kCookTopState_OnInitiated)
302+
{
303+
oven->mCookTopState = kCookTopState_OnCompleted;
304+
actionCompleted = ON_ACTION;
305+
}
306+
}
307+
break;
308+
case AppEvent::kEventType_CookSurface:
309+
{
310+
// Handle CookSurface state transitions
311+
chip::EndpointId endpointId = static_cast<chip::EndpointId>(aEvent->OvenEvent.Actor);
312+
State_t * currentState = nullptr;
313+
314+
// Get the appropriate state pointer based on endpoint
315+
if (endpointId == kCookSurfaceEndpoint1)
316+
{
317+
currentState = &oven->mCookSurfaceState1;
318+
}
319+
else if (endpointId == kCookSurfaceEndpoint2)
320+
{
321+
currentState = &oven->mCookSurfaceState2;
322+
}
323+
else
324+
{
325+
ChipLogError(AppServer, "Invalid CookSurface endpoint ID");
326+
return; // Invalid endpoint
327+
}
328+
329+
if (*currentState == kCookSurfaceState_OffInitiated)
330+
{
331+
*currentState = kCookSurfaceState_OffCompleted;
332+
actionCompleted = OFF_ACTION;
333+
}
334+
else if (*currentState == kCookSurfaceState_OnInitiated)
335+
{
336+
*currentState = kCookSurfaceState_OnCompleted;
337+
actionCompleted = ON_ACTION;
338+
}
339+
}
340+
break;
341+
default:
342+
break;
239343
}
240344

241345
if (actionCompleted != INVALID_ACTION)
@@ -258,9 +362,9 @@ struct BlockedTransition
258362

259363
// Disallowed OvenMode Transitions.
260364
static constexpr BlockedTransition kBlockedTransitions[] = {
261-
{ TemperatureControlledCabinet::OvenModeDelegate::kModeGrill, TemperatureControlledCabinet::OvenModeDelegate::kModeProofing },
262-
{ TemperatureControlledCabinet::OvenModeDelegate::kModeProofing, TemperatureControlledCabinet::OvenModeDelegate::kModeClean },
263-
{ TemperatureControlledCabinet::OvenModeDelegate::kModeClean, TemperatureControlledCabinet::OvenModeDelegate::kModeBake },
365+
{ to_underlying(TemperatureControlledCabinet::OvenModeDelegate::OvenModes::kModeGrill), to_underlying(TemperatureControlledCabinet::OvenModeDelegate::OvenModes::kModeProofing) },
366+
{ to_underlying(TemperatureControlledCabinet::OvenModeDelegate::OvenModes::kModeProofing), to_underlying(TemperatureControlledCabinet::OvenModeDelegate::OvenModes::kModeClean) },
367+
{ to_underlying(TemperatureControlledCabinet::OvenModeDelegate::OvenModes::kModeClean), to_underlying(TemperatureControlledCabinet::OvenModeDelegate::OvenModes::kModeBake) },
264368
};
265369

266370
static bool IsTransitionBlocked(uint8_t fromMode, uint8_t toMode)
@@ -284,7 +388,7 @@ void OvenManager::ProcessOvenModeChange(chip::EndpointId endpointId, uint8_t new
284388
ChipLogProgress(AppServer, "OvenManager::ProcessOvenModeChange ep=%u newMode=%u", endpointId, newMode);
285389

286390
// Verify newMode is among supported modes
287-
bool supported = TemperatureControlledCabinet::OvenModeDelegate::IsSupportedMode(newMode);
391+
bool supported = mTemperatureControlledCabinetEndpoint.GetOvenModeDelegate().IsSupportedMode(newMode);
288392
if (!supported)
289393
{
290394
response.status = to_underlying(ModeBase::StatusCode::kUnsupportedMode);

0 commit comments

Comments
 (0)