diff --git a/examples/thermostat/silabs/include/SensorManager.h b/examples/thermostat/silabs/include/SensorManager.h index f1a6a18e2a2c19..8a88d775207fa1 100644 --- a/examples/thermostat/silabs/include/SensorManager.h +++ b/examples/thermostat/silabs/include/SensorManager.h @@ -31,20 +31,15 @@ class SensorManager { public: CHIP_ERROR Init(); - struct AttributeUpdateInfo - { - int16_t temperature; - uint16_t endPoint; - }; private: - static void UpdateTemperatureAttribute(intptr_t context); friend SensorManager & SensorMgr(); osTimerId_t mSensorTimer; - // Reads new generated sensor value, stores it, and updates local temperature attribute static void SensorTimerEventHandler(void * arg); + // Reads new generated sensor value, stores it, and updates local temperature attribute + static void TemperatureUpdateEventHandler(AppEvent * aEvent); static SensorManager sSensorManager; }; diff --git a/examples/thermostat/silabs/src/SensorManager.cpp b/examples/thermostat/silabs/src/SensorManager.cpp index d9aed702d88ec4..b6eec3b90e4342 100644 --- a/examples/thermostat/silabs/src/SensorManager.cpp +++ b/examples/thermostat/silabs/src/SensorManager.cpp @@ -77,6 +77,15 @@ CHIP_ERROR SensorManager::Init() } void SensorManager::SensorTimerEventHandler(void * arg) +{ + AppEvent event; + event.Type = AppEvent::kEventType_Timer; + event.Handler = TemperatureUpdateEventHandler; + + AppTask::GetAppTask().PostEvent(&event); +} + +void SensorManager::TemperatureUpdateEventHandler(AppEvent * aEvent) { int16_t temperature = 0; static int16_t lastTemperature = 0; @@ -115,20 +124,11 @@ void SensorManager::SensorTimerEventHandler(void * arg) if ((temperature >= (lastTemperature + kMinTemperatureDelta)) || temperature <= (lastTemperature - kMinTemperatureDelta)) { - lastTemperature = temperature; - AttributeUpdateInfo * data = chip::Platform::New(); - data->endPoint = kThermostatEndpoint; - data->temperature = temperature; + lastTemperature = temperature; + PlatformMgr().LockChipStack(); // 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 - - chip::DeviceLayer::PlatformMgr().ScheduleWork(UpdateTemperatureAttribute, reinterpret_cast(data)); + app::Clusters::Thermostat::Attributes::LocalTemperature::Set(kThermostatEndpoint, temperature); + PlatformMgr().UnlockChipStack(); } } - -void SensorManager::UpdateTemperatureAttribute(intptr_t context) -{ - SensorManager::AttributeUpdateInfo * data = reinterpret_cast(context); - app::Clusters::Thermostat::Attributes::LocalTemperature::Set(data->endPoint, data->temperature); - chip::Platform::Delete(data); -}