@@ -97,9 +97,14 @@ AirQualityEnum classifyAirQuality(int32_t value)
97
97
}
98
98
}
99
99
100
+ void InitAirQualitySensorManager (intptr_t arg)
101
+ {
102
+ AirQualitySensorManager::InitInstance ();
103
+ }
104
+
100
105
CHIP_ERROR SensorManager::Init ()
101
106
{
102
- DeviceLayer::PlatformMgr ().ScheduleWork (AirQualitySensorManager::InitInstance );
107
+ DeviceLayer::PlatformMgr ().ScheduleWork (InitAirQualitySensorManager );
103
108
// Create cmsisos sw timer for air quality sensor timer.
104
109
mSensorTimer = osTimerNew (SensorTimerEventHandler, osTimerPeriodic, nullptr , nullptr );
105
110
if (mSensorTimer == NULL )
@@ -129,6 +134,14 @@ CHIP_ERROR SensorManager::Init()
129
134
return CHIP_NO_ERROR;
130
135
}
131
136
137
+ void writeAirQualityToAttribute (intptr_t context)
138
+ {
139
+ int32_t *air_quality_ptr = reinterpret_cast <int32_t *>(context);
140
+ AirQualitySensorManager::GetInstance ()->OnAirQualityChangeHandler (classifyAirQuality (*air_quality_ptr));
141
+ ChipLogDetail (AppServer, " RAW AirQuality value: %ld and corresponding Enum value : %d" , *air_quality_ptr,chip::to_underlying (AirQualitySensorManager::GetInstance ()->GetAirQuality ()));
142
+ AppTask::GetAppTask ().UpdateAirQualitySensorUI ();
143
+ }
144
+
132
145
void SensorManager::SensorTimerEventHandler (void * arg)
133
146
{
134
147
int32_t air_quality;
@@ -159,15 +172,8 @@ void SensorManager::SensorTimerEventHandler(void * arg)
159
172
nbOfRepetition = 0 ;
160
173
}
161
174
#endif // USE_AIR_QUALITY_SENSOR
162
-
163
- DeviceLayer::PlatformMgr ().ScheduleWork (AirQualitySensorManager::GetInstance ()->OnAirQualityChangeHandler ,
164
- classifyAirQuality (air_quality));
165
-
166
- PlatformMgr ().LockChipStack ();
167
- ChipLogDetail (AppServer, " RAW AirQuality value: %ld and corresponding Enum value : %d" , air_quality,
168
- chip::to_underlying (AirQualitySensorManager::GetInstance ()->GetAirQuality ()));
169
- PlatformMgr ().UnlockChipStack ();
170
-
171
-
172
- AppTask::GetAppTask ().UpdateAirQualitySensorUI ();
175
+ // create pointer for the int32_t air_quality
176
+ int32_t * air_quality_ptr = new int32_t (air_quality);
177
+ DeviceLayer::PlatformMgr ().ScheduleWork (writeAirQualityToAttribute, reinterpret_cast <intptr_t >(air_quality_ptr));
178
+ ChipLogDetail (AppServer, " writeAirQualityToAttribute success" );
173
179
}
0 commit comments