@@ -47,9 +47,9 @@ void OvenManager::Init()
4747 DeviceLayer::PlatformMgr ().LockChipStack ();
4848
4949 // Initialize states
50- mCookTopState = kCookTopState_OffCompleted ;
51- mCookSurfaceState1 = kCookSurfaceState_OffCompleted ;
52- mCookSurfaceState2 = kCookSurfaceState_OffCompleted ;
50+ mCookTopState = kCookTopState_Off ;
51+ mCookSurfaceState1 = kCookSurfaceState_Off ;
52+ mCookSurfaceState2 = kCookSurfaceState_Off ;
5353
5454 // Endpoint initializations
5555 VerifyOrReturn (mOvenEndpoint .Init () == CHIP_NO_ERROR, ChipLogError (AppServer, " OvenEndpoint Init failed" ));
@@ -90,10 +90,6 @@ void OvenManager::Init()
9090
9191 VerifyOrReturn (err == CHIP_NO_ERROR, ChipLogError (AppServer, " RegisterSupportedLevels failed for CookSurfaceEndpoint2" ));
9292
93- // Get CookTop On/Off value
94- // OnOffServer::Instance().getOnOffValue(1, ¤tLedState);
95- // mCookTopState = currentLedState ? kState_OnCompleted : kState_OffCompleted;
96-
9793 DeviceLayer::PlatformMgr ().UnlockChipStack ();
9894}
9995
@@ -153,193 +149,56 @@ void OvenManager::OnOffAttributeChangeHandler(EndpointId endpointId, AttributeId
153149 switch (endpointId)
154150 {
155151 case kCookTopEndpoint :
156- InitiateAction (AppEvent::kEventType_CookTop , *value ? OvenManager::ON_ACTION : OvenManager::OFF_ACTION, value,
157- kCookTopEndpoint );
158- // Update CookSurface states accordingly
152+ mCookTopState = (*value != 0 ) ? kCookTopState_On : kCookTopState_Off ;
153+ // Turn on/off the associated cook surfaces.
159154 mCookSurfaceEndpoint1 .SetOnOffState (*value);
160155 mCookSurfaceEndpoint2 .SetOnOffState (*value);
161156 break ;
162157 case kCookSurfaceEndpoint1 :
163158 case kCookSurfaceEndpoint2 :
164- // Handle On/Off attribute changes for the cook surface endpoints
165- InitiateAction (AppEvent::kEventType_CookSurface , *value ? OvenManager::ON_ACTION : OvenManager::OFF_ACTION, value,
166- endpointId);
159+ if (endpointId == kCookSurfaceEndpoint1 )
160+ mCookSurfaceState1 = (*value != 0 ) ? kCookSurfaceState_On : kCookSurfaceState_Off ;
161+ else
162+ mCookSurfaceState2 = (*value != 0 ) ? kCookSurfaceState_On : kCookSurfaceState_Off ;
163+
164+ bool cookSurfaceEndpoint1State;
165+ bool cookSurfaceEndpoint2State;
166+ mCookSurfaceEndpoint1 .GetOnOffState (cookSurfaceEndpoint1State);
167+ mCookSurfaceEndpoint2 .GetOnOffState (cookSurfaceEndpoint2State);
168+ // Turn off CookTop if both the CookSurfaces are off.
169+ if (!cookSurfaceEndpoint1State && !cookSurfaceEndpoint2State)
167170 {
168- bool cookSurfaceEndpoint1State;
169- bool cookSurfaceEndpoint2State;
170- mCookSurfaceEndpoint1 .GetOnOffState (cookSurfaceEndpoint1State);
171- mCookSurfaceEndpoint2 .GetOnOffState (cookSurfaceEndpoint2State);
172- // Check if both cooksurfaces are off. If yes, turn off the cooktop (call cooktop.TurnOffCookTop)
173- if (cookSurfaceEndpoint1State == false && cookSurfaceEndpoint2State == false )
174- {
175- mCookTopEndpoint .SetOnOffState (false );
176- }
171+ mCookTopEndpoint .SetOnOffState (false );
172+ mCookTopState = kCookTopState_Off ;
177173 }
178174 break ;
179175 default :
180176 break ;
181177 }
178+
179+ // Post an event to AppTask for the hardware actions (like LCD and LED update).
180+ AppEvent event = {};
181+ event.Type = AppEvent::kEventType_UIUpdate ;
182+ event.Handler = OvenActionHandler;
183+ AppTask::GetAppTask ().PostEvent (&event);
182184}
183185
184186void OvenManager::OvenModeAttributeChangeHandler (chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value,
185187 uint16_t size)
186188{
187189 VerifyOrReturn (endpointId == kTemperatureControlledCabinetEndpoint ,
188190 ChipLogError (AppServer, " Command received over Unsupported Endpoint" ));
189- // TODO: Update the LCD with the new Oven Mode
191+ // Post an event to AppTask for the hardware actions (like LCD and LED update).
192+ AppEvent event = {};
193+ event.Type = AppEvent::kEventType_UIUpdate ;
194+ event.Handler = OvenActionHandler;
195+ AppTask::GetAppTask ().PostEvent (&event);
190196 return ;
191197}
192198
193- void OvenManager::SetCallbacks (Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB )
199+ void OvenManager::OvenActionHandler (AppEvent * aEvent )
194200{
195- mActionInitiated_CB = aActionInitiated_CB;
196- mActionCompleted_CB = aActionCompleted_CB;
197- }
198-
199- bool OvenManager::InitiateAction (int32_t aActor, Action_t aAction, uint8_t * aValue, chip::EndpointId endpointId)
200- {
201- bool action_initiated = false ;
202- State_t new_state;
203- State_t * currentState = nullptr ;
204- uint8_t eventType;
205-
206- // Determine which state to manage based on endpoint
207- if (endpointId == kCookTopEndpoint )
208- {
209- currentState = &mCookTopState ;
210- eventType = AppEvent::kEventType_CookTop ;
211- }
212- else if (endpointId == kCookSurfaceEndpoint1 )
213- {
214- currentState = &mCookSurfaceState1 ;
215- eventType = AppEvent::kEventType_CookSurface ;
216- }
217- else if (endpointId == kCookSurfaceEndpoint2 )
218- {
219- currentState = &mCookSurfaceState2 ;
220- eventType = AppEvent::kEventType_CookSurface ;
221- }
222- else
223- {
224- return false ; // Invalid endpoint
225- }
226-
227- // Determine the appropriate state transitions based on endpoint type
228- if (endpointId == kCookTopEndpoint )
229- {
230- // CookTop state transitions
231- if (*currentState == kCookTopState_OffCompleted && aAction == ON_ACTION)
232- {
233- action_initiated = true ;
234- new_state = kCookTopState_OnInitiated ;
235- }
236- else if (*currentState == kCookTopState_OnCompleted && aAction == OFF_ACTION)
237- {
238- action_initiated = true ;
239- new_state = kCookTopState_OffInitiated ;
240- }
241- }
242- else
243- {
244- // CookSurface state transitions
245- if (*currentState == kCookSurfaceState_OffCompleted && aAction == ON_ACTION)
246- {
247- action_initiated = true ;
248- new_state = kCookSurfaceState_OnInitiated ;
249- }
250- else if (*currentState == kCookSurfaceState_OnCompleted && aAction == OFF_ACTION)
251- {
252- action_initiated = true ;
253- new_state = kCookSurfaceState_OffInitiated ;
254- }
255- }
256-
257- if (action_initiated && (aAction == ON_ACTION || aAction == OFF_ACTION))
258- {
259- *currentState = new_state;
260-
261- AppEvent event;
262- event.Type = eventType;
263- event.OvenEvent .Context = this ;
264- event.OvenEvent .Action = aAction;
265- event.OvenEvent .Actor = endpointId; // Store endpoint ID in Actor field
266- event.Handler = ActuatorMovementHandler;
267-
268- AppTask::GetAppTask ().PostEvent (&event);
269- }
270-
271- if (action_initiated && mActionInitiated_CB )
272- {
273- mActionInitiated_CB (aAction, aActor, aValue);
274- }
275-
276- return action_initiated;
277- }
278-
279- void OvenManager::ActuatorMovementHandler (AppEvent * aEvent)
280- {
281- Action_t actionCompleted = INVALID_ACTION;
282- OvenManager * oven = static_cast <OvenManager *>(aEvent->OvenEvent .Context );
283-
284- switch (aEvent->Type )
285- {
286- case AppEvent::kEventType_CookTop : {
287- // Handle CookTop state transitions
288- if (oven->mCookTopState == kCookTopState_OffInitiated )
289- {
290- oven->mCookTopState = kCookTopState_OffCompleted ;
291- actionCompleted = OFF_ACTION;
292- }
293- else if (oven->mCookTopState == kCookTopState_OnInitiated )
294- {
295- oven->mCookTopState = kCookTopState_OnCompleted ;
296- actionCompleted = ON_ACTION;
297- }
298- }
299- break ;
300- case AppEvent::kEventType_CookSurface : {
301- // Handle CookSurface state transitions
302- chip::EndpointId endpointId = static_cast <chip::EndpointId>(aEvent->OvenEvent .Actor );
303- State_t * currentState = nullptr ;
304-
305- // Get the appropriate state pointer based on endpoint
306- if (endpointId == kCookSurfaceEndpoint1 )
307- {
308- currentState = &oven->mCookSurfaceState1 ;
309- }
310- else if (endpointId == kCookSurfaceEndpoint2 )
311- {
312- currentState = &oven->mCookSurfaceState2 ;
313- }
314- else
315- {
316- ChipLogError (AppServer, " Invalid CookSurface endpoint ID" );
317- return ; // Invalid endpoint
318- }
319-
320- if (*currentState == kCookSurfaceState_OffInitiated )
321- {
322- *currentState = kCookSurfaceState_OffCompleted ;
323- actionCompleted = OFF_ACTION;
324- }
325- else if (*currentState == kCookSurfaceState_OnInitiated )
326- {
327- *currentState = kCookSurfaceState_OnCompleted ;
328- actionCompleted = ON_ACTION;
329- }
330- }
331- break ;
332- default :
333- break ;
334- }
335-
336- if (actionCompleted != INVALID_ACTION)
337- {
338- if (oven->mActionCompleted_CB )
339- {
340- oven->mActionCompleted_CB (actionCompleted);
341- }
342- }
201+ // TODO: hardware Action : Update the LEDs and LCD of oven-app as required.
343202}
344203
345204bool OvenManager::IsTransitionBlocked (uint8_t fromMode, uint8_t toMode)
0 commit comments