QSensorBackend
#include <QtSensors/QSensorBackend>
QtSensors
1.0
Sensors on a device will be represented by sub-classes of QSensorBackend.
Public Functions Index
| QSensorBackend (QSensor *sensor) | |
| virtual | ~QSensorBackend () |
| void | start ()=0 |
| void | stop ()=0 |
| void | addDataRate (qreal min, qreal max) |
| void | setDataRates (const QSensor *otherSensor) |
| void | addOutputRange (qreal min, qreal max, qreal accuracy) |
| void | setDescription (const QString &description) |
| T * | setReading (T *reading) |
| QSensorReading * | reading () const |
| QSensor * | sensor () const |
| void | newReadingAvailable () |
| void | sensorStopped () |
| void | sensorBusy () |
| void | sensorError (int error) |
Public Functions
virtual
Destructor.
void
Start reporting values.
1.0
void
Stop reporting values.
1.0
void
Add a data rate (consisting of min and max values) for the sensor.
Note that this function should be called from the constructor so that the information is available immediately.
1.0
void
Set the data rates for the sensor based on otherSensor.
This is designed for sensors that are based on other sensors.
setDataRates(otherSensor);
Note that this function should be called from the constructor so that the information is available immediately.
1.0
void
Add an output range (consisting of min, max values and accuracy) for the sensor.
Note that this function should be called from the constructor so that the information is available immediately.
1.0
void
Set the description for the sensor.
1.0
T *
This function is called to initialize the reading classes used for a sensor.
If your backend has already allocated a reading you should pass the address of this to the function. Otherwise you should pass 0 and the function will return the address of the reading your backend should use when it wants to notify the sensor API of new readings.
Note that this is a template function so it should be called with the appropriate type.
class MyBackend : public QSensorBackend
{
QAccelerometerReading m_reading;
public:
MyBackend(QSensor *sensor)
: QSensorBackend(sensor)
{
setReading<QAccelerometerReading>(&m_reading);
}
...
Note that this function must be called or you will not be able to send readings to the front end.
If you do not wish to store the address of the reading you may use the reading() method to get it again later.
class MyBackend : public QSensorBackend
{
public:
MyBackend(QSensor *sensor)
: QSensorBackend(sensor)
{
setReading<QAccelerometerReading>(0);
}
void poll()
{
qtimestamp timestamp;
qreal x, y, z;
...
QAccelerometerReading *reading = static_cast<QAccelerometerReading*>(reading());
reading->setTimestamp(timestamp);
reading->setX(x);
reading->setY(y);
reading->setZ(z);
}
...
1.0
QSensorReading *
If the backend has lost its reference to the reading it can call this method to get the address.
Note that you will need to down-cast to the appropriate type.
1.0
void
Inform the front end that the sensor has stopped.
This can be due to start() failing or for some unexpected reason (eg. hardware failure).
1.0
void
Inform the front end that the sensor is busy.
This implicitly calls sensorStopped() and is typically called from start().
1.0
void
Inform the front end that a sensor error occurred.
Note that this only reports an error code. It does not stop the sensor.
1.0
© 2008-2011 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. Privacy Policy
Licensees holding valid Qt Commercial licenses may use this document in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia. Alternatively, this document may be used under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.