SensorsScriptInterface Class

The SensorsScriptInterface class enables you to emulate built-in device sensors. More...

Header: #include <SensorsScriptInterface>

Public Types

enum LightLevel { Undefined, Dark, Twilight, Light, Bright, Sunny }

Properties

Public Functions

double accelerometerX() const
double accelerometerY() const
double accelerometerZ() const
SensorsScriptInterface::LightLevel ambientLightLevel() const
double compassAzimuth() const
double compassCalibrationLevel() const
double irProximity() const
double lux() const
double magnetometerCalibrationLevel() const
double magnetometerX() const
double magnetometerY() const
double magnetometerZ() const
bool proximitySensorClose() const
void setAccelerometerX(double x)
void setAccelerometerY(double y)
void setAccelerometerZ(double z)
void setAmbientLightLevel(const SensorsScriptInterface::LightLevel &data)
void setCompassAzimuth(double a)
void setCompassCalibrationLevel(double l)
void setIrProximity(double c)
void setLux(double lux)
void setMagnetometerCalibrationLevel(double l)
void setMagnetometerX(double x)
void setMagnetometerY(double y)
void setMagnetometerZ(double z)
void setProximitySensorClose(bool c)
void setTimestamp(const QDateTime &t)
void setUseCurrentTimestamp(bool t)
QDateTime timestamp() const
bool useCurrentTimestamp() const

Static Public Members

const QMetaObject staticMetaObject

Detailed Description

The SensorsScriptInterface class enables you to emulate built-in device sensors.

If the target devices contain built-in sensors, such as an accelerometer, a compass, or ambient light or proximity sensors, you can create scripts to emulate sensor values.

Many sensors update frequently, and therefore sensor readings done by the client application contain a fresh timestamp by default.

The SensorsScriptInterface class is exposed as sensors.

Ambient Light Sensor

The ambient light state in which the device is being used is defined in units of illuminance (LUX). You can either use predefined values or specify the amount of LUX to emulate.

The following script uses the ambientLightLevel property to set the value of the Ambient light field in the Sensors view to Dark:

sensors.ambientLightLevel = sensors.Dark
print(sensors.ambientLightLevel)

Accelerometer

The accelerometer sensor channel detects movement gestures, such as moving a mobile device up or down. The three-dimensional Cartesian coordinate system is used to illustrate direction of the acceleration. The x and y axes define a plane where z-axis direction is perpendicular to the xy plane. When a device moves along an axis in the positive direction, the acceleration is positive. When the device moves in the negative direction, the acceleration is negative. For example, when a device moves along the x-axis to the direction of -x, the acceleration is negative.

The following script uses the accelerometerX, accelerometerY, and accelerometerZ properties to set the values for the Accelerometer x, Accelerometer y, and Accelerometer z fields in the Sensors view to 1, 2, and 3:

sensors.accelerometerX = 1
sensors.accelerometerY = 2
sensors.accelerometerZ = 3
print(sensors.accelerometerX + ' ' + sensors.accelerometerY + ' ' + sensors.accelerometerZ)

Compass

The compass returns the azimuth of the device as degrees from magnetic north in a clockwise direction based on the top of the device. The calibration status of the device must be accurate for the azimuth to be accurate.

The following script uses the magnetometerX, magnetometerY, and magnetometerZ properties to set the raw magnetic flux density on the x, y, and z axis to 1 tesla.

Also, it uses the compassAzimuth property to set the compass azimuth to 0.42 and the magnetometerCalibrationLevel property to set the compass calibration level to 0.43.

sensors.magnetometerX = 1
sensors.magnetometerY = 1
sensors.magnetometerZ = 1
sensors.magnetometerCalibrationLevel = 1
print(sensors.magnetometerX + ' ' + sensors.magnetometerY + ' ' + sensors.magnetometerZ + ' ' + sensors.magnetometerCalibrationLevel)

sensors.compassAzimuth = 0.42
sensors.compassCalibrationLevel = 0.43
print(sensors.compassAzimuth + ' ' + sensors.compassCalibrationLevel)

Proximity Sensors

Proximity sensors indicate how far away from the user the device is.

The following script uses the irProximity property to set the value of the IR proximity slider in the Sensors view to 0.7:

sensors.irProximity = 0.7

The following script sets the proximitySensorClose() function to true to set the value of the Proximity distance field in the Sensors view to Near:

sensors.proximitySensorClose = true
print(sensors.proximitySensorClose)

Timestamp

The following script first sets the useCurrentTimestamp() function to true to select the Current radio button in the Timestamp group in the Sensors view and uses the timestamp() function to display the current timestamp in the field below. Second, it sets the useCurrentTimestamp() function to false to enable you to set your own timestamp:

sensors.useCurrentTimestamp = true
sensors.useCurrentTimestamp = false
sensors.timestamp = new Date

Member Type Documentation

enum SensorsScriptInterface::LightLevel

This enum type describes the ambient light conditions in which the device is being used. The enum values correspond to predefined amounts of units of illuminance (LUX):

ConstantValueDescription
SensorsScriptInterface::Undefined0The light level is unknown.
SensorsScriptInterface::Dark1It is dark.
SensorsScriptInterface::Twilight2It is moderately dark.
SensorsScriptInterface::Light3It is light. For example, the lights are on indoors.
SensorsScriptInterface::Bright4It is bright, but the device is in a shade.
SensorsScriptInterface::Sunny5There is direct sunlight.

Property Documentation

accelerometerX : double

This property holds the acceleration on the x axis.

Access functions:

double accelerometerX() const
void setAccelerometerX(double x)

accelerometerY : double

This property holds the acceleration on the y axis.

Access functions:

double accelerometerY() const
void setAccelerometerY(double y)

accelerometerZ : double

This property holds the acceleration on the z axis.

Access functions:

double accelerometerZ() const
void setAccelerometerZ(double z)

ambientLightLevel : LightLevel

This property holds the ambient light state using predefined LUX values.

Access functions:

SensorsScriptInterface::LightLevel ambientLightLevel() const
void setAmbientLightLevel(const SensorsScriptInterface::LightLevel &data)

compassAzimuth : double

This property holds the azimuth of the device.

Measured in degrees from magnetic north in a clockwise direction based on the top of the UI.

Access functions:

double compassAzimuth() const
void setCompassAzimuth(double a)

compassCalibrationLevel : double

This property holds the calibration level of the reading.

Measured as a value from 0 to 1 with higher values being better.

Access functions:

double compassCalibrationLevel() const
void setCompassCalibrationLevel(double l)

irProximity : double

readings from the infra-red (IR) proximity sensor.

The IR proximity sensor detects proximity by beaming out infra-red light and detecting how much of the light returns.

The biggest limitation of this technology is that there is no reliable way to turn the reflectance values into distances unless both the item being detected and the ambient conditions are known.

Access functions:

double irProximity() const
void setIrProximity(double c)

lux : double

This property holds the ambient light state in LUX.

Access functions:

double lux() const
void setLux(double lux)

magnetometerCalibrationLevel : double

This property holds the accuracy of the magnetometer reading.

Measured as a value from 0 to 1 with higher values being better.

Note: This value only changes when measuring geomagnetic flux density. Raw magnetic flux readings always have a value of 1.

Access functions:

double magnetometerCalibrationLevel() const
void setMagnetometerCalibrationLevel(double l)

magnetometerX : double

This property holds the raw magnetic flux density on the x axis in teslas.

Access functions:

double magnetometerX() const
void setMagnetometerX(double x)

magnetometerY : double

This property holds the raw magnetic flux density on the y axis in teslas.

Access functions:

double magnetometerY() const
void setMagnetometerY(double y)

magnetometerZ : double

This property holds the raw magnetic flux density on the z axis in teslas.

Access functions:

double magnetometerZ() const
void setMagnetometerZ(double z)

proximitySensorClose : bool

This property holds whether the device is close to the user.

Set to true if the device is close; otherwise, set to false.

Access functions:

bool proximitySensorClose() const
void setProximitySensorClose(bool c)

timestamp : QDateTime

This property holds the timestamp of the reading.

Access functions:

QDateTime timestamp() const
void setTimestamp(const QDateTime &t)

useCurrentTimestamp : bool

This property holds whether the current timestamp or a user-defined fixed timestamp is set to the reading.

Set to true if the current timestamp is used; otherwise, set to false.

Access functions:

bool useCurrentTimestamp() const
void setUseCurrentTimestamp(bool t)

Member Function Documentation

Member Variable Documentation

Related Non-Members

Macro Documentation

© 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.