From 73b221449b09723e796e936c9d63970364659e50 Mon Sep 17 00:00:00 2001 From: Arun Padakanti Date: Mon, 23 Sep 2024 20:54:26 +0530 Subject: [PATCH] Add ScheduleWork by removing LockChipStack and UnlockChipStack in SensorTimerEventHandler. --- examples/thermostat/silabs/include/SensorManager.h | 6 ++++++ examples/thermostat/silabs/src/SensorManager.cpp | 14 +++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/examples/thermostat/silabs/include/SensorManager.h b/examples/thermostat/silabs/include/SensorManager.h index 03b916de699d2b..8f7e13e8d50778 100644 --- a/examples/thermostat/silabs/include/SensorManager.h +++ b/examples/thermostat/silabs/include/SensorManager.h @@ -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; diff --git a/examples/thermostat/silabs/src/SensorManager.cpp b/examples/thermostat/silabs/src/SensorManager.cpp index abecd899d5370f..f667fbcdd95b8c 100644 --- a/examples/thermostat/silabs/src/SensorManager.cpp +++ b/examples/thermostat/silabs/src/SensorManager.cpp @@ -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(); + 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(data)); } } + +void SensorManager::UpdateClusterState(intptr_t context) +{ + SensorManager::AttributeUpdateInfo * data = reinterpret_cast (context); + app::Clusters::Thermostat::Attributes::LocalTemperature::Set(data->endPoint, data->temperature); + chip::Platform::Delete(data); +}