Skip to content

Commit

Permalink
Add ScheduleWork by removing LockChipStack and UnlockChipStack in Sen…
Browse files Browse the repository at this point in the history
…sorTimerEventHandler.
  • Loading branch information
arun-silabs committed Sep 23, 2024
1 parent a99bb07 commit b20f54d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions examples/thermostat/silabs/include/SensorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ class SensorManager
{
public:
CHIP_ERROR Init();
struct AttributeUpdateInfo
{
int16_t temperature;
uint16_t endPoint;
};

private:
static void UpdateClusterState(intptr_t context);
friend SensorManager & SensorMgr();

osTimerId_t mSensorTimer;
Expand Down
14 changes: 11 additions & 3 deletions examples/thermostat/silabs/src/SensorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,19 @@ void SensorManager::SensorTimerEventHandler(void * arg)
if ((temperature >= (lastTemperature + kMinTemperatureDelta)) || temperature <= (lastTemperature - kMinTemperatureDelta))
{
lastTemperature = temperature;
PlatformMgr().LockChipStack();
AttributeUpdateInfo * data = chip::Platform::New<AttributeUpdateInfo>();
data->endPoint = kThermostatEndpoint;
data->temperature = temperature;
// The SensorMagager shouldn't be aware of the Endpoint ID TODO Fix this.
// TODO Per Spec we should also apply the Offset stored in the same cluster before saving the temp

app::Clusters::Thermostat::Attributes::LocalTemperature::Set(kThermostatEndpoint, temperature);
PlatformMgr().UnlockChipStack();
chip::DeviceLayer::PlatformMgr().ScheduleWork(UpdateClusterState, reinterpret_cast<intptr_t>(data));
}
}

void SensorManager::UpdateClusterState(intptr_t context)
{
SensorManager::AttributeUpdateInfo * data = reinterpret_cast<SensorManager::AttributeUpdateInfo *> (context);
app::Clusters::Thermostat::Attributes::LocalTemperature::Set(data->endPoint, data->temperature);
chip::Platform::Delete(data);
}

0 comments on commit b20f54d

Please sign in to comment.