Skip to content

Commit 2434980

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

File tree

7 files changed

+68
-259
lines changed

7 files changed

+68
-259
lines changed

examples/oven-app/oven-app-common/include/CookSurfaceEndpoint.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ class CookSurfaceEndpoint
4242
/**
4343
* @brief Gets the current On/Off state from server.
4444
* @param state Reference to store the current On/Off state.
45+
*
46+
* Note: This helper reads the OnOff attribute from the CHIP attribute storage and
47+
* therefore must be invoked from the CHIP/DeviceLayer task context or while holding
48+
* the CHIP stack lock (DeviceLayer::PlatformMgr().LockChipStack()). Calling this
49+
* API from an arbitrary thread can cause asserts / crashes in the CHIP stack.
50+
* If you are not in the CHIP task, schedule work onto the CHIP task using
51+
* PlatformMgr().ScheduleWork(...) and call this helper from there.
52+
*
4553
* @return Returns Status::Success on success, or an error code on failure.
4654
*/
4755

@@ -50,6 +58,14 @@ class CookSurfaceEndpoint
5058
/**
5159
* @brief Set On/Off state for the CookSurface.
5260
* @param state Desired On/Off state.
61+
*
62+
* Note: This helper writes the OnOff attribute to the CHIP attribute storage and
63+
* therefore must be invoked from the CHIP/DeviceLayer task context or while holding
64+
* the CHIP stack lock (DeviceLayer::PlatformMgr().LockChipStack()). Calling this
65+
* API from an arbitrary thread can cause asserts / crashes in the CHIP stack.
66+
* If you are not in the CHIP task, schedule work onto the CHIP task using
67+
* PlatformMgr().ScheduleWork(...) and call this helper from there.
68+
*
5369
* @return Returns Status::Success on success, or an error code on failure.
5470
*/
5571
chip::Protocols::InteractionModel::Status SetOnOffState(bool state);

examples/oven-app/oven-app-common/include/CookTopEndpoint.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ class CookTopEndpoint
4141
/**
4242
* @brief Set On/Off state for the CookSurface.
4343
* @param state Desired On/Off state.
44+
*
45+
* Note: This helper writes the OnOff attribute to the CHIP attribute storage and
46+
* therefore must be invoked from the CHIP/DeviceLayer task context or while holding
47+
* the CHIP stack lock (DeviceLayer::PlatformMgr().LockChipStack()). Calling this
48+
* API from an arbitrary thread can cause asserts / crashes in the CHIP stack.
49+
* If you are not in the CHIP task, schedule work onto the CHIP task using
50+
* PlatformMgr().ScheduleWork(...) and call this helper from there.
51+
*
4452
* @return Returns Status::Success on success, or an error code on failure.
4553
*/
4654
chip::Protocols::InteractionModel::Status SetOnOffState(bool state);

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-
}

0 commit comments

Comments
 (0)