Skip to content

Commit 73b2214

Browse files
committed
Add ScheduleWork by removing LockChipStack and UnlockChipStack in SensorTimerEventHandler.
1 parent a99bb07 commit 73b2214

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

examples/thermostat/silabs/include/SensorManager.h

+6
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,14 @@ class SensorManager
3131
{
3232
public:
3333
CHIP_ERROR Init();
34+
struct AttributeUpdateInfo
35+
{
36+
int16_t temperature;
37+
uint16_t endPoint;
38+
};
3439

3540
private:
41+
static void UpdateClusterState(intptr_t context);
3642
friend SensorManager & SensorMgr();
3743

3844
osTimerId_t mSensorTimer;

examples/thermostat/silabs/src/SensorManager.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,19 @@ void SensorManager::SensorTimerEventHandler(void * arg)
116116
if ((temperature >= (lastTemperature + kMinTemperatureDelta)) || temperature <= (lastTemperature - kMinTemperatureDelta))
117117
{
118118
lastTemperature = temperature;
119-
PlatformMgr().LockChipStack();
119+
AttributeUpdateInfo * data = chip::Platform::New<AttributeUpdateInfo>();
120+
data->endPoint = kThermostatEndpoint;
121+
data->temperature = temperature;
120122
// The SensorMagager shouldn't be aware of the Endpoint ID TODO Fix this.
121123
// TODO Per Spec we should also apply the Offset stored in the same cluster before saving the temp
122124

123-
app::Clusters::Thermostat::Attributes::LocalTemperature::Set(kThermostatEndpoint, temperature);
124-
PlatformMgr().UnlockChipStack();
125+
chip::DeviceLayer::PlatformMgr().ScheduleWork(UpdateClusterState, reinterpret_cast<intptr_t>(data));
125126
}
126127
}
128+
129+
void SensorManager::UpdateClusterState(intptr_t context)
130+
{
131+
SensorManager::AttributeUpdateInfo * data = reinterpret_cast<SensorManager::AttributeUpdateInfo *> (context);
132+
app::Clusters::Thermostat::Attributes::LocalTemperature::Set(data->endPoint, data->temperature);
133+
chip::Platform::Delete(data);
134+
}

0 commit comments

Comments
 (0)