@@ -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
@@ -86,7 +92,7 @@ void OvenManager::Init()
8692
8793 // Get CookTop On/Off value
8894 // OnOffServer::Instance().getOnOffValue(1, ¤tLedState);
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
173182void 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.
260364static 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
266370static 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