Skip to content

Commit daebfbd

Browse files
committed
Handle review comments
1 parent 43caebd commit daebfbd

File tree

5 files changed

+44
-259
lines changed

5 files changed

+44
-259
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct AppEvent : public BaseAppEvent
2929
kEventType_CookTop,
3030
kEventType_CookSurface,
3131
kEventType_Install,
32+
kEventType_UIUpdate,
3233
};
3334

3435
union

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,10 @@ class AppTask : public BaseApplication
8282
private:
8383
static AppTask sAppTask;
8484

85-
static void ActionInitiated(OvenManager::Action_t aAction, int32_t aActor, uint8_t * value);
86-
static void ActionCompleted(OvenManager::Action_t aAction);
87-
8885
/**
8986
* @brief Override of BaseApplication::AppInit() virtual method, called by BaseApplication::Init()
9087
*
9188
* @return CHIP_ERROR
9289
*/
9390
CHIP_ERROR AppInit() override;
94-
95-
/**
96-
* @brief PB0 Button event processing function
97-
* Press and hold will trigger a factory reset timer start
98-
* Press and release will restart BLEAdvertising if not commissioned
99-
*
100-
* @param aEvent button event being processed
101-
*/
102-
static void ButtonHandler(AppEvent * aEvent);
10391
};

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

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,35 +43,15 @@
4343

4444
class OvenManager
4545
{
46-
public:
47-
enum Action_t
48-
{
49-
ON_ACTION = 0,
50-
OFF_ACTION,
51-
52-
INVALID_ACTION
53-
} Action;
5446

47+
public:
5548
enum State_t
5649
{
57-
kCookTopState_OffInitiated = 0,
58-
kCookTopState_OffCompleted,
59-
kCookTopState_OnInitiated,
60-
kCookTopState_OnCompleted,
61-
62-
// Cook Surface states
63-
kCookSurfaceState_OffInitiated,
64-
kCookSurfaceState_OffCompleted,
65-
kCookSurfaceState_OnInitiated,
66-
kCookSurfaceState_OnCompleted,
67-
kCookSurfaceState_ActionInProgress,
68-
kCookSurfaceState_NoAction,
69-
} State;
70-
71-
bool InitiateAction(int32_t aActor, Action_t aAction, uint8_t * aValue, chip::EndpointId endpointId = kCookTopEndpoint);
72-
typedef void (*Callback_fn_initiated)(Action_t, int32_t aActor, uint8_t * value);
73-
typedef void (*Callback_fn_completed)(Action_t);
74-
void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB);
50+
kCookTopState_Off = 0,
51+
kCookTopState_On,
52+
kCookSurfaceState_Off,
53+
kCookSurfaceState_On
54+
};
7555

7656
/**
7757
* @brief Initializes the OvenManager and its associated resources.
@@ -152,10 +132,12 @@ class OvenManager
152132
State_t mCookSurfaceState1;
153133
State_t mCookSurfaceState2;
154134

155-
Callback_fn_initiated mActionInitiated_CB;
156-
Callback_fn_completed mActionCompleted_CB;
157-
158-
static void ActuatorMovementHandler(AppEvent * aEvent);
135+
/**
136+
* @brief Updates the oven hardware state and UI (LEDs, LCD) in response to an event.
137+
*
138+
* @param aEvent Pointer to the event structure.
139+
*/
140+
static void OvenActionHandler(AppEvent * aEvent);
159141

160142
// Define the endpoint ID for the Oven
161143
static constexpr chip::EndpointId kOvenEndpoint = 1;

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

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ CHIP_ERROR AppTask::AppInit()
7272

7373
// Initialization of Oven Manager and endpoints of oven.
7474
OvenManager::GetInstance().Init();
75-
OvenManager::GetInstance().SetCallbacks(ActionInitiated, ActionCompleted);
7675
// Update the LCD with the Stored value. Show QR Code if not provisioned
7776
#ifdef DISPLAY_ENABLED
7877
GetLCD().WriteDemoUI(false);
@@ -130,47 +129,3 @@ void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
130129
AppTask::GetAppTask().PostEvent(&button_event);
131130
}
132131

133-
void AppTask::ActionInitiated(OvenManager::Action_t aAction, int32_t aActor, uint8_t * aValue)
134-
{
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-
142-
#ifdef DISPLAY_ENABLED
143-
sAppTask.GetLCD().WriteDemoUI(lightOn);
144-
#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-
}
152-
153-
if (aActor == AppEvent::kEventType_Button)
154-
{
155-
sAppTask.mSyncClusterToButtonAction = true;
156-
}
157-
}
158-
159-
void AppTask::ActionCompleted(OvenManager::Action_t aAction)
160-
{
161-
// Action has been completed on the oven
162-
if (aAction == OvenManager::ON_ACTION)
163-
{
164-
ChipLogProgress(AppServer, "ON action completed");
165-
}
166-
else if (aAction == OvenManager::OFF_ACTION)
167-
{
168-
ChipLogProgress(AppServer, "OFF action completed");
169-
}
170-
171-
if (sAppTask.mSyncClusterToButtonAction)
172-
{
173-
// TODO: Schedule work to Update CookTop and CookSurfaceEndpoints (turn on/off)
174-
sAppTask.mSyncClusterToButtonAction = false;
175-
}
176-
}

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

Lines changed: 31 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -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, &currentLedState);
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

184186
void 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

345204
bool OvenManager::IsTransitionBlocked(uint8_t fromMode, uint8_t toMode)

0 commit comments

Comments
 (0)