QSensor

The QSensor class represents a single hardware sensor. More

Inheritance diagram of PySide2.QtSensors.QSensor

Inherited by: QAccelerometer, QAltimeter, QAmbientLightSensor, QAmbientTemperatureSensor, QCompass, QDistanceSensor, QGyroscope, QHolsterSensor, QHumiditySensor, QIRProximitySensor, QLidSensor, QLightSensor, QMagnetometer, QOrientationSensor, QPressureSensor, QProximitySensor, QRotationSensor, QTapSensor, QTiltSensor

Synopsis

Functions

Slots

Signals

Static functions

Detailed Description

The life cycle of a sensor is typically:

  • Create a sub-class of QSensor on the stack or heap.

  • Setup as required by the application.

  • Start receiving values.

  • Sensor data is used by the application.

  • Stop receiving values.

The sensor data is delivered via QSensorReading and its sub-classes.

Orientation

Some sensors react to screen orientation changes, such as QAccelerometer , QMagnetometer and QRotationSensor . These are so called orientable sensors. For orientable sensors, QSensor supports changing the reporting of the reading values based on the orientation of the screen.

For orientable sensors, the axesOrientationMode property controls how the orientation affects the reading values.

In the default mode, FixedOrientation , the reading values remain unaffected by the orientation. In the AutomaticOrientation mode, the reading values are automatically rotated by taking the current screen orientation into account. And finally, in the UserOrientation mode, the reading values are rotated according to a user-specified orientation.

The functionality of this is only available if it is supported by the backend and if the sensor is orientable, which can be checked by calling isFeatureSupported() with the AxesOrientation flag.

The orientation values here are always of the screen orientation, not the device orientation. The screen orientation is the orientation of the GUI. For example when rotating a device by 90 degrees counter-clockwise, the screen orientation compensates for that by rotating 90 degrees clockwise, to the effect that the GUI is still facing upright after the device has been rotated. Note that applications can lock the screen orientation, for example to force portrait or landscape mode. For locked orientations, orientable sensors will not react with reading changes if the device orientation is changed, as orientable sensors react to screen orientation changes only. This makes sense, as the purpose of orientable sensors is to keep the sensor orientation in sync with the screen orientation.

The orientation values range from 0 to 270 degrees. The orientation is applied in clockwise direction, e.g. an orientation value of 90 degrees means that the screen has been rotated 90 degress to the right from its origin position, to compensate a device rotation of 90 degrees to the left.

See also

QSensorReading

class QSensor(type[, parent=Q_NULLPTR])
param type

QByteArray

param parent

QObject

Construct the type sensor as a child of parent .

Do not use this constructor if a derived class exists for the specific sensor type.

The wrong way is to use the base class constructor:

QSensor *magnetometer = new QSensor(QMagnetometer::type, this);

The right way is to create an instance of the derived class:

QMagnetometer *magnetometer = new QMagnetometer(this);

The derived classes have additional properties and data members which are needed for certain features such as geo value support in QMagnetometer or acceleration mode support in QAccelerometer . These features will only work properly when creating a sensor instance from a QSensor subclass.

Only use this constructor if there is no derived sensor class available. Note that all built-in sensors have a derived class, so using this constructor should only be necessary when implementing custom sensors, like in the Grue sensor example .

PySide2.QtSensors.QSensor.Feature

Lists optional features a backend might support.

The features common to all sensor types are:

Constant

Description

QSensor.Buffering

The backend supports buffering of readings, controlled by the bufferSize property.

QSensor.AlwaysOn

The backend supports changing the policy on whether to suspend when idle, controlled by the alwaysOn property.

QSensor.SkipDuplicates

The backend supports skipping of same or very similar successive readings. This can be enabled by setting the skipDuplicates property to true.

The features of QMagnetometer are:

Constant

Description

QSensor.GeoValues

The backend supports returning geo values, which can be controlled with the returnGeoValues property.

The features of QLightSensor are:

Constant

Description

QSensor.FieldOfView

The backend specifies its field of view, which can be read from the fieldOfView property.

The features of QAccelerometer are:

Constant

Description

QSensor.AccelerationMode

The backend supports switching the acceleration mode of the acceleromter with the accelerationMode property.

The features of QPressureSensor are:

Constant

Description

QSensor.PressureSensorTemperature

The backend provides the pressure sensor’s die temperature

The features of all orientable sensors are:

Constant

Description

QSensor.AxesOrientation

The backend supports changing the axes orientation from the default of FixedOrientation to something else.

PySide2.QtSensors.QSensor.AxesOrientationMode

Describes how reading values are affected by the screen orientation.

Constant

Description

QSensor.FixedOrientation

No automatic rotation is applied to the reading values.

QSensor.AutomaticOrientation

The reading values are automatically rotated based on the screen orientation.

QSensor.UserOrientation

The reading values are rotated based on the angle of the userOrientation property.

PySide2.QtSensors.QSensor.activeChanged()
PySide2.QtSensors.QSensor.addFilter(filter)
Parameters

filterQSensorFilter

Add a filter to the sensor.

The sensor does not take ownership of the filter. QSensorFilter will inform the sensor if it is destroyed.

See also

QSensorFilter

PySide2.QtSensors.QSensor.alwaysOnChanged()
PySide2.QtSensors.QSensor.availableDataRates()
Return type

PySide2.QtSensors.QSensor.availableSensorsChanged()
PySide2.QtSensors.QSensor.axesOrientationMode()
Return type

AxesOrientationMode

PySide2.QtSensors.QSensor.axesOrientationModeChanged(axesOrientationMode)
Parameters

axesOrientationModeAxesOrientationMode

PySide2.QtSensors.QSensor.backend()
Return type

QSensorBackend

PySide2.QtSensors.QSensor.bufferSize()
Return type

int

See also

setBufferSize()

PySide2.QtSensors.QSensor.bufferSizeChanged(bufferSize)
Parameters

bufferSizeint

PySide2.QtSensors.QSensor.busyChanged()
PySide2.QtSensors.QSensor.connectToBackend()
Return type

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.

PySide2.QtSensors.QSensor.currentOrientation()
Return type

int

PySide2.QtSensors.QSensor.currentOrientationChanged(currentOrientation)
Parameters

currentOrientationint

PySide2.QtSensors.QSensor.dataRate()
Return type

int

See also

setDataRate()

PySide2.QtSensors.QSensor.dataRateChanged()
static PySide2.QtSensors.QSensor.defaultSensorForType(type)
Parameters

typeQByteArray

Return type

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 .

PySide2.QtSensors.QSensor.description()
Return type

unicode

PySide2.QtSensors.QSensor.efficientBufferSize()
Return type

int

PySide2.QtSensors.QSensor.efficientBufferSizeChanged(efficientBufferSize)
Parameters

efficientBufferSizeint

PySide2.QtSensors.QSensor.error()
Return type

int

PySide2.QtSensors.QSensor.filters()
Return type

Returns the filters currently attached to the sensor.

See also

QSensorFilter

PySide2.QtSensors.QSensor.identifier()
Return type

QByteArray

See also

setIdentifier()

PySide2.QtSensors.QSensor.isActive()
Return type

bool

PySide2.QtSensors.QSensor.isAlwaysOn()
Return type

bool

PySide2.QtSensors.QSensor.isBusy()
Return type

bool

PySide2.QtSensors.QSensor.isConnectedToBackend()
Return type

bool

PySide2.QtSensors.QSensor.isFeatureSupported(feature)
Parameters

featureFeature

Return type

bool

Checks if a specific feature is supported by the backend.

QtSensors supports a rich API for controlling and providing information about sensors. Naturally, not all of this functionality can be supported by all of the backends.

To check if the current backend supports the feature feature , call this function.

The backend needs to be connected, otherwise false will be returned. Calling connectToBackend() or start() will create a connection to the backend.

Backends have to implement isFeatureSupported() to make this work.

Returns whether or not the feature is supported if the backend is connected, or false if the backend is not connected.

PySide2.QtSensors.QSensor.maxBufferSize()
Return type

int

PySide2.QtSensors.QSensor.maxBufferSizeChanged(maxBufferSize)
Parameters

maxBufferSizeint

PySide2.QtSensors.QSensor.outputRange()
Return type

int

See also

setOutputRange()

PySide2.QtSensors.QSensor.outputRanges()
Return type

PySide2.QtSensors.QSensor.reading()
Return type

QSensorReading

PySide2.QtSensors.QSensor.readingChanged()
PySide2.QtSensors.QSensor.removeFilter(filter)
Parameters

filterQSensorFilter

Remove filter from the sensor.

See also

QSensorFilter

PySide2.QtSensors.QSensor.sensorError(error)
Parameters

errorint

static PySide2.QtSensors.QSensor.sensorTypes()
Return type

Returns a list of all sensor types.

static PySide2.QtSensors.QSensor.sensorsForType(type)
Parameters

typeQByteArray

Return type

Returns a list of ids for each of the sensors for type . If there are no sensors of that type available the list will be empty.

PySide2.QtSensors.QSensor.setActive(active)
Parameters

activebool

See also

isActive()

PySide2.QtSensors.QSensor.setAlwaysOn(alwaysOn)
Parameters

alwaysOnbool

See also

isAlwaysOn()

PySide2.QtSensors.QSensor.setAxesOrientationMode(axesOrientationMode)
Parameters

axesOrientationModeAxesOrientationMode

PySide2.QtSensors.QSensor.setBufferSize(bufferSize)
Parameters

bufferSizeint

See also

bufferSize()

PySide2.QtSensors.QSensor.setCurrentOrientation(currentOrientation)
Parameters

currentOrientationint

Sets the current screen orientation to currentOrientation . This is to be called from the backend whenever the screen orientation or the userOrientation property changes.

PySide2.QtSensors.QSensor.setDataRate(rate)
Parameters

rateint

See also

dataRate()

PySide2.QtSensors.QSensor.setEfficientBufferSize(efficientBufferSize)
Parameters

efficientBufferSizeint

Sets the efficient buffer size to efficientBufferSize . This is to be called from the backend.

PySide2.QtSensors.QSensor.setIdentifier(identifier)
Parameters

identifierQByteArray

See also

identifier()

PySide2.QtSensors.QSensor.setMaxBufferSize(maxBufferSize)
Parameters

maxBufferSizeint

Sets the maximum buffer size to maxBufferSize . This is to be called from the backend.

See also

maxBufferSize()

PySide2.QtSensors.QSensor.setOutputRange(index)
Parameters

indexint

See also

outputRange()

PySide2.QtSensors.QSensor.setSkipDuplicates(skipDuplicates)
Parameters

skipDuplicatesbool

Sets the duplicate skipping to skipDuplicates .

See also

skipDuplicates()

PySide2.QtSensors.QSensor.setUserOrientation(userOrientation)
Parameters

userOrientationint

PySide2.QtSensors.QSensor.skipDuplicates()
Return type

bool

PySide2.QtSensors.QSensor.skipDuplicatesChanged(skipDuplicates)
Parameters

skipDuplicatesbool

PySide2.QtSensors.QSensor.start()
Return type

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();

See also

busy

PySide2.QtSensors.QSensor.stop()

Stop retrieving values from the sensor.

This releases the sensor so that other processes can use it.

See also

busy

PySide2.QtSensors.QSensor.type()
Return type

QByteArray

PySide2.QtSensors.QSensor.userOrientation()
Return type

int

PySide2.QtSensors.QSensor.userOrientationChanged(userOrientation)
Parameters

userOrientationint