QRotationSensor
#include <QtSensors/QRotationSensor>
QtSensors
The QRotationSensor class is a convenience wrapper around QSensor.
The only behavioural difference is that this class sets the type properly.
This class also features a reading() function that returns a QRotationReading instead of a QSensorReading.
For details about how the sensor works, see QRotationReading.
1.0
Inheritance
| QOrientableSensorBase | ||
| QRotationSensor | ||
Public Types Index
Only has inherited public types
enum AxesOrientationMode |
Properties Index
| AxesOrientationMode | axesOrientationMode |
| int | currentOrientation [read-only] |
| int | userOrientation |
| bool | active |
| bool | alwaysOn |
| QtMobility::qrangelist | availableDataRates [read-only] |
| bool | busy [read-only] |
| bool | connectedToBackend [read-only] |
| int | dataRate |
| QString | description [read-only] |
| int | error [read-only] |
| int | outputRange |
| QtMobility::qoutputrangelist | outputRanges [read-only] |
| QSensorReading | reading [read-only] |
| QByteArray | sensorid |
| bool | skipDuplicates |
Public Static Attributes Index
| char const *const | type |
Public Functions Index
| QRotationSensor (QObject *parent=0) | |
| virtual | ~QRotationSensor () |
| QRotationReading * | reading () const |
| void | addFilter (QSensorFilter *filter) |
| qrangelist | availableDataRates () const |
| AxesOrientationMode | axesOrientationMode () const |
| Q_INVOKABLE bool | connectToBackend () |
| int | currentOrientation () const |
| int | dataRate () const |
| QString | description () const |
| int | error () const |
| QList< QSensorFilter * > | filters () const |
| QByteArray | identifier () const |
| bool | isActive () const |
| bool | isAlwaysOn () const |
| bool | isBusy () const |
| bool | isConnectedToBackend () const |
| int | outputRange () const |
| qoutputrangelist | outputRanges () const |
| QOrientableSensorBase () | |
| QSensor (const QByteArray &type, QObject *parent=0) | |
| void | removeFilter (QSensorFilter *filter) |
| void | setActive (bool active) |
| void | setAlwaysOn (bool alwaysOn) |
| void | setAxesOrientationMode (AxesOrientationMode axesOrientationMode) |
| void | setCurrentOrientation (int currentOrientation) |
| void | setDataRate (int rate) |
| void | setIdentifier (const QByteArray &identifier) |
| void | setOutputRange (int index) |
| void | setSkipDuplicates (bool skipDuplicates) |
| void | setUserOrientation (int userOrientation) |
| bool | skipDuplicates () const |
| QByteArray | type () const |
| int | userOrientation () const |
Static Public Functions Index
Only has inherited static public functions
| QByteArray | defaultSensorForType (const QByteArray &type) |
| QList< QByteArray > | sensorsForType (const QByteArray &type) |
| QList< QByteArray > | sensorTypes () |
Protected Functions Index
Signals Index
| void | axesOrientationModeChanged (AxesOrientationMode axesOrientationMode) |
| void | currentOrientationChanged (int currentOrientation) |
| void | userOrientationChanged (int userOrientation) |
| void | activeChanged () |
| void | alwaysOnChanged () |
| void | availableSensorsChanged () |
| void | busyChanged () |
| void | dataRateChanged () |
| void | readingChanged () |
| void | sensorError (int error) |
| void | skipDuplicatesChanged (bool skipDuplicates) |
Public Types
(Only has inherited public types)
Describes how reading values are affected by the screen orientation.
FixedOrientation No automatic rotation is applied to the reading values.
AutomaticOrientation The reading values are automatically rotated based on the screen orientation.
UserOrientation The reading values are rotated based on the angle of the userOrientation property.
- FixedOrientation
- AutomaticOrientation
- UserOrientation
Properties
int
int
bool
a value to indicate if the sensor is active.
This is true if the sensor is active (returning values). This is false otherwise.
1.1
bool
a value to indicate if the sensor should remain running when the screen is off.
Some platforms have a policy of suspending sensors when the screen turns off. Setting this property to true will ensure the sensor continues to run.
QtMobility::qrangelist
the data rates that the sensor supports.
This is a list of the data rates that the sensor supports. Measured in Hertz.
Entries in the list can represent discrete rates or a continuous range of rates. A discrete rate is noted by having both values the same.
See the sensor_explorer example for an example of how to interpret and use this information.
Note that this information is not mandatory as not all sensors have a rate at which they run. In such cases, the list will be empty.
1.0
bool
a value to indicate if the sensor is busy.
Some sensors may be on the system but unavailable for use. This function will return true if the sensor is busy. You will not be able to start() the sensor.
Note that this function does not return true if you are using the sensor, only if another process is using the sensor.
1.0
bool
a value indicating if the sensor has connected to a backend.
A sensor that has not been connected to a backend cannot do anything useful.
1.0
int
the data rate that the sensor should be run at.
Measured in Hertz.
The data rate is the maximum frequency at which the sensor can detect changes.
Setting this property is not portable and can cause conflicts with other applications. Check with the sensor backend and platform documentation for any policy regarding multiple applications requesting a data rate.
The default value (0) means that the app does not care what the data rate is. Applications should consider using a timer-based poll of the current value or ensure that the code that processes values can run very quickly as the platform may provide updates hundreds of times each second.
This should be set before calling start() because the sensor may not notice changes to this value while it is running.
Note that there is no mechanism to determine the current data rate in use by the platform.
1.0
int
the last error code set on the sensor.
1.0
int
the output range in use by the sensor.
This value represents the index in the QSensor::outputRanges list to use.
Setting this property is not portable and can cause conflicts with other applications. Check with the sensor backend and platform documentation for any policy regarding multiple applications requesting an output range.
The default value (-1) means that the app does not care what the output range is.
Note that there is no mechanism to determine the current output range in use by the platform.
1.0
QtMobility::qoutputrangelist
a list of output ranges the sensor supports.
A sensor may have more than one output range. Typically this is done to give a greater measurement range at the cost of lowering accuracy.
Note that this information is not mandatory. This information is typically only available for sensors that have selectable output ranges (such as typical accelerometers).
1.0
QSensorReading
the reading class.
The reading class provides access to sensor readings. The reading object is a volatile cache of the most recent sensor reading that has been received so the application should process readings immediately or save the values somewhere for later processing.
Note that this will return 0 until a sensor backend is connected to a backend.
Also note that readings are not immediately available after start() is called. Applications must wait for the readingChanged() signal to be emitted.
isConnectedToBackend(), start()
1.0
QByteArray
the backend identifier for the sensor.
1.0
bool
Indicates whether duplicate reading values should be omitted.
When duplicate skipping is enabled, successive readings with the same or very similar values are omitted and skipped. This helps reducing the amount of processing done, as less sensor readings are made available. As a consequence, readings arrive at an irregular interval.
Duplicate skipping is not just enabled for readings that are exactly the same, but also for readings that are quite similar, as each sensor has a bit of jitter even if the device is not moved.
Support for this property depends on the backend. It is disabled by default.
Duplicate skipping can only be changed while the sensor is not active.
Public Static Attributes
char const *const
Public Functions
Construct the sensor as a child of parent.
1.0
virtual
Destructor.
1.0
void 
Add a filter to the sensor.
The sensor does not take ownership of the filter. QSensorFilter will inform the sensor if it is destroyed.
1.0
AxesOrientationMode 
The mode that affects how the screen orientation changes reading values.
When set to FixedOrientation, which is the default mode, no automatic rotation is applied to the reading. This is the only mode available for backends that do not support the QSensor::AxesOrientation feature.
When set to AutomaticOrientation, the reading values are automatically rotated when the screen orientation changes. In effect, the screen orientation is canceled out.
As an example, assume the device is rotated by 180 degrees and therefore the screen orientation also is rotated by 180 degrees from the native orientation. Without automatic axes orientation, the reading values would now be changed: Both the X and the Y values would be negated, forcing an application developer to manually cancel out the negation in application code. Automatic axes orientation does this automatically, in this mode the X and Y values would be the same as with the default screen orientation.
This automatic rotation of the axes is handy is some usecases, for example in a bubble level application that measures how level a surface is by looking at the X axis value of an accelerometer. When the device and screen orientation change by 90 degrees, an application developer does not need to change anything, he can continue using the X axis value even though the device is rotated. Without automatic axes orientation, the application developer would need to look at the Y values instead, thereby adding code to the application that reads from a different axis depending on the screen orientation.
The UserOrientation mode is quite similar to AutomaticOrientation, only that the screen orientation is manually controlled instead of automatically determined. The angle of the userOrientation property is then used for rotating the reading values.
Since the rotation of the reading values is based on the screen orientation, Z values will never change, as the Z axis is perpendicular to the screen. As screen orientation changes in 90 degree steps, rotating the reading values is also done in steps of 90 degrees.
Q_INVOKABLE bool 
Try to connect to a sensor backend.
Returns true if a suitable backend could be found, false otherwise.
The type must be set before calling this method if you are using QSensor directly.
isConnectedToBackend()
1.0
int 
The current orientation that is used for rotating the reading values.
This might not be the same as the screen orientation. For example, in the FixedOrientation mode, the reading values are not rotated, and therefore the property is 0.
In the UserOrientation mode, the readings are rotated based on the userOrientation property, and therefore this property is equal to the userOrientation property.
In the AutomaticOrientation mode, the readings are rotated based on the screen orientation, and therefore this property will be equal to the current screen orientation.
This property is set by the backend.
int 
int 
bool 
bool 
bool 
bool 
int 
Constructs a QOrientableSensorBase.
Construct the type sensor as a child of parent.
1.0
void 
void 
void 
void 
Sets the current screen orientation to currentOrientation.
This is to be called from the backend whenever the screen orientation or the userOrientation property changes.
void 
void 
void 
void 
Sets the duplicate skipping to skipDuplicates.
void 
bool 
int 
The angle used for rotating the reading values in the UserOrientation mode.
When the axesOrientationMode property is set to UserOrientation, the angle for rotating the reading values is taken from this property. In other modes, the property has no effect.
The default is 0. The only valid values are 0, 90, 180 and 270, as those are the only possible screen orientations.
Static Public Functions
(Only has inherited static public functions)
QByteArray 
Returns the default sensor identifier for type.
This is set in a config file and can be overridden if required. If no default is available the system will return the first registered sensor for type.
Note that there is special case logic to prevent the generic plugin's backends from becoming the default when another backend is registered for the same type. This logic means that a backend identifier starting with {generic.} will only be the default if no other backends have been registered for that type or if it is specified in {Sensors.conf}.
{Determining the default sensor for a type}
1.0
QList< QByteArray > 
Returns a list of ids for each of the sensors for type.
1.0
Protected Functions
(Only has inherited protected functions)
QSensorPrivate * 
Public Slots
(Only has inherited public slots)
bool 
Start retrieving values from the sensor.
Returns true if the sensor was started, false otherwise.
The sensor may fail to start for several reasons.
Once an application has started a sensor it must wait until the sensor receives a new value before it can query the sensor's values. This is due to how the sensor receives values from the system. Sensors do not (in general) poll for new values, rather new values are pushed to the sensors as they happen.
For example, this code will not work as intended.
sensor->start(); sensor->reading()->x(); // no data available
To work correctly, the code that accesses the reading should ensure the readingChanged() signal has been emitted.
connect(sensor, SIGNAL(readingChanged()), this, SLOT(checkReading()));
sensor->start();
}
void MyClass::checkReading() {
sensor->reading()->x();
1.0
void 
Stop retrieving values from the sensor.
This releases the sensor so that other processes can use it.
1.0
Signals
void
void
void
void 
This signal is emitted when the alwaysOn property changes.
void 
This signal is emitted when the list of available sensors has changed.
The sensors available to a program will not generally change over time however some of the avilable sensors may represent hardware that is not permanently connected. For example, a game controller that is connected via bluetooth would become available when it was on and would become unavailable when it was off.
1.2
void 
This signal is emitted when the sensor is no longer busy.
This can be used to grab a sensor when it becomes available.
sensor.start();
if (sensor.isBusy()) {
// need to wait for busyChanged signal and try again
}
1.0
void 
void 
This signal is emitted when a new sensor reading is received.
The sensor reading can be found in the QSensor::reading property. Note that the reading object is a volatile cache of the most recent sensor reading that has been received so the application should process the reading immediately or save the values somewhere for later processing.
Before this signal has been emitted for the first time, the reading object will have uninitialized data.
1.0
void 
This signal is emitted when an error code is set on the sensor.
1.0
void 
© 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.