213 d->device_reading = device; |
199 d->device_reading = device; |
214 d->filter_reading = filter; |
200 d->filter_reading = filter; |
215 d->cache_reading = cache; |
201 d->cache_reading = cache; |
216 } |
202 } |
217 |
203 |
|
204 /*! |
|
205 Add a data rate (consisting of \a min and \a max values) for the sensor. |
|
206 |
|
207 Note that this function should be called from the constructor so that the information |
|
208 is available immediately. |
|
209 |
|
210 \sa QSensor::availableDataRates |
|
211 */ |
|
212 void QSensorBackend::addDataRate(qreal min, qreal max) |
|
213 { |
|
214 QSensorPrivate *d = m_sensor->d_func(); |
|
215 d->availableDataRates << qrange(min, max); |
|
216 } |
|
217 |
|
218 /*! |
|
219 Set the data rates for the sensor based on \a otherSensor. |
|
220 |
|
221 This is designed for sensors that are based on other sensors. |
|
222 |
|
223 \code |
|
224 setDataRates(otherSensor); |
|
225 \endcode |
|
226 |
|
227 Note that this function should be called from the constructor so that the information |
|
228 is available immediately. |
|
229 |
|
230 \sa QSensor::availableDataRates, addDataRate() |
|
231 */ |
|
232 void QSensorBackend::setDataRates(const QSensor *otherSensor) |
|
233 { |
|
234 if (!otherSensor) { |
|
235 qWarning() << "ERROR: Cannot call QSensorBackend::setDataRates with 0"; |
|
236 return; |
|
237 } |
|
238 if (otherSensor->identifier().count() == 0) { |
|
239 qWarning() << "ERROR: Cannot call QSensorBackend::setDataRates with an invalid sensor"; |
|
240 return; |
|
241 } |
|
242 QSensorPrivate *d = m_sensor->d_func(); |
|
243 d->availableDataRates = otherSensor->availableDataRates(); |
|
244 d->dataRate = otherSensor->dataRate(); |
|
245 if (d->availableDataRates.count() == 0) { |
|
246 qWarning() << otherSensor->identifier() << "backend does not support any data rates."; |
|
247 } |
|
248 } |
|
249 |
|
250 /*! |
|
251 Add an output range (consisting of \a min, \a max values and \a accuracy) for the sensor. |
|
252 |
|
253 Note that this function should be called from the constructor so that the information |
|
254 is available immediately. |
|
255 |
|
256 \sa QSensor::outputRange, QSensor::outputRanges |
|
257 */ |
|
258 void QSensorBackend::addOutputRange(qreal min, qreal max, qreal accuracy) |
|
259 { |
|
260 QSensorPrivate *d = m_sensor->d_func(); |
|
261 |
|
262 qoutputrange details = {min, max, accuracy}; |
|
263 |
|
264 d->outputRanges << details; |
|
265 |
|
266 // When adding the first range, set outputRage to it |
|
267 if (d->outputRange == -1) { |
|
268 d->outputRange = 0; |
|
269 } |
|
270 } |
|
271 |
|
272 /*! |
|
273 Set the \a description for the sensor. |
|
274 |
|
275 Note that this function should be called from the constructor so that the information |
|
276 is available immediately. |
|
277 */ |
|
278 void QSensorBackend::setDescription(const QString &description) |
|
279 { |
|
280 QSensorPrivate *d = m_sensor->d_func(); |
|
281 d->description = description; |
|
282 } |
|
283 |
|
284 /*! |
|
285 Inform the front end that the sensor has stopped. |
|
286 This can be due to start() failing or for some |
|
287 unexpected reason (eg. hardware failure). |
|
288 |
|
289 Note that the front end must call QSensor::isActive() to see if |
|
290 the sensor has stopped. If the sensor has stopped due to an error |
|
291 the sensorError() function should be called to notify the class |
|
292 of the error condition. |
|
293 */ |
|
294 void QSensorBackend::sensorStopped() |
|
295 { |
|
296 QSensorPrivate *d = m_sensor->d_func(); |
|
297 d->active = false; |
|
298 } |
|
299 |
|
300 /*! |
|
301 Inform the front end that the sensor is busy. |
|
302 This implicitly calls sensorStopped() and |
|
303 is typically called from start(). |
|
304 |
|
305 Note that the front end must call QSensor::isBusy() to see if |
|
306 the sensor is busy. If the sensor has stopped due to an error |
|
307 the sensorError() function should be called to notify the class |
|
308 of the error condition. |
|
309 */ |
|
310 void QSensorBackend::sensorBusy() |
|
311 { |
|
312 QSensorPrivate *d = m_sensor->d_func(); |
|
313 d->active = false; |
|
314 d->busy = true; |
|
315 } |
|
316 |
|
317 /*! |
|
318 Inform the front end that a sensor error occurred. |
|
319 Note that this only reports an \a error code. It does |
|
320 not stop the sensor. |
|
321 |
|
322 \sa sensorStopped() |
|
323 */ |
|
324 void QSensorBackend::sensorError(int error) |
|
325 { |
|
326 QSensorPrivate *d = m_sensor->d_func(); |
|
327 d->error = error; |
|
328 Q_EMIT m_sensor->sensorError(error); |
|
329 } |
|
330 |
218 #include "moc_qsensorbackend.cpp" |
331 #include "moc_qsensorbackend.cpp" |
219 QTM_END_NAMESPACE |
332 QTM_END_NAMESPACE |
220 |
333 |