@@ -45,6 +45,12 @@ OvenManager OvenManager::sOvenMgr;
4545void 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
193202void 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.
280384static 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
286390static 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