Skip to content

Commit 90db04b

Browse files
committed
Posting SensorTimerEventHandler as an event to AppTask.
1 parent c669c0c commit 90db04b

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

examples/thermostat/silabs/include/SensorManager.h

+2-7
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,15 @@ class SensorManager
3131
{
3232
public:
3333
CHIP_ERROR Init();
34-
struct AttributeUpdateInfo
35-
{
36-
int16_t temperature;
37-
uint16_t endPoint;
38-
};
3934

4035
private:
41-
static void UpdateTemperatureAttribute(intptr_t context);
4236
friend SensorManager & SensorMgr();
4337

4438
osTimerId_t mSensorTimer;
4539

46-
// Reads new generated sensor value, stores it, and updates local temperature attribute
4740
static void SensorTimerEventHandler(void * arg);
41+
// Reads new generated sensor value, stores it, and updates local temperature attribute
42+
static void TemperatureUpdateEventHandler(AppEvent * aEvent);
4843

4944
static SensorManager sSensorManager;
5045
};

examples/thermostat/silabs/src/SensorManager.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ CHIP_ERROR SensorManager::Init()
7777
}
7878

7979
void SensorManager::SensorTimerEventHandler(void * arg)
80+
{
81+
AppEvent event;
82+
event.Type = AppEvent::kEventType_Timer;
83+
event.Handler = TemperatureUpdateEventHandler;
84+
85+
AppTask::GetAppTask().PostEvent(&event);
86+
}
87+
88+
void SensorManager::TemperatureUpdateEventHandler(AppEvent * aEvent)
8089
{
8190
int16_t temperature = 0;
8291
static int16_t lastTemperature = 0;
@@ -115,20 +124,11 @@ void SensorManager::SensorTimerEventHandler(void * arg)
115124

116125
if ((temperature >= (lastTemperature + kMinTemperatureDelta)) || temperature <= (lastTemperature - kMinTemperatureDelta))
117126
{
118-
lastTemperature = temperature;
119-
AttributeUpdateInfo * data = chip::Platform::New<AttributeUpdateInfo>();
120-
data->endPoint = kThermostatEndpoint;
121-
data->temperature = temperature;
127+
lastTemperature = temperature;
128+
PlatformMgr().LockChipStack();
122129
// The SensorMagager shouldn't be aware of the Endpoint ID TODO Fix this.
123130
// TODO Per Spec we should also apply the Offset stored in the same cluster before saving the temp
124-
125-
chip::DeviceLayer::PlatformMgr().ScheduleWork(UpdateTemperatureAttribute, reinterpret_cast<intptr_t>(data));
131+
app::Clusters::Thermostat::Attributes::LocalTemperature::Set(kThermostatEndpoint, temperature);
132+
PlatformMgr().UnlockChipStack();
126133
}
127134
}
128-
129-
void SensorManager::UpdateTemperatureAttribute(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)