The QML Sensors Plugin provides an easy to use interface to the Sensors API. It enables us to receive sensor events and to read current values from sensors.
The plugin contains many sensor types and access functions to read values from them. As an example consider the orientation sensor. The orientation example simply displays text on-screen to show the current orientation.
The QML code that reads the value is quite simple. Here we see a QML component orientation declared which is an OrientationSensor element. First the sensor is started by setting the active property to true. The element receives a signal when the reading changes and it is picked up by the onReadingChanged slot. Now the reading property of this element can be used to extract the current orientation so that it can be compared against the defined values of various orientations in the OrientationReading element.
OrientationSensor { id: orientation active: true onReadingChanged: { if (reading.orientation == OrientationReading.FaceUp) content.state = "FaceUp"; // ... more tests for different orientations ... } }
Other sensors can be treated in a similar manner. For example, the Compass sensor could have almost identical coding
Compass { id: compass active: true onReadingChanged: { compassHeading.text = reading.azimuth; // ... } }
The Accelerometer element reports on linear acceleration along the X, Y and Z axes. | |
The Altimeter element reports on altitude. | |
The AmbientLightSensor element repors on ambient lighting conditions. | |
The AmbientTemperatureSensor element reports on the ambient temperature. | |
The Compass element reports on heading using magnetic north as a reference. | |
The Gyroscope element reports on rotational acceleration around the X, Y and Z axes. | |
The HolsterSensor type detects if a device is holstered or not. | |
The IRProximitySensor type reports on infra-red reflectance values. | |
The LightSensor element reports on light levels using LUX. | |
The Magnetometer element reports on magnetic field strength along the Z, Y and Z axes. | |
The OrientationSensor element reports device orientation. | |
The PressureSensor type reports on atmospheric pressure values. | |
The ProximitySensor element reports on object proximity. | |
The RotationSensor element reports on device rotation around the X, Y and Z axes. | |
The Sensor element serves as a base type for sensors. | |
The TapSensor element reports tap and double tap events along the X, Y and Z axes. |
The AccelerometerReading element holds the most recent Accelerometer reading. | |
The AltimeterReading element holds the most recent Altimeter reading. | |
The AmbientLightReading element holds the most AmbientLightSensor reading. | |
The CompassReading element holds the most recent Compass reading. | |
The GyroscopeReading element holds the most recent Gyroscope reading. | |
The HolsterReading type holds the most recent HolsterSensor reading. | |
The IRProximityReading type holds the most recent IR proximity reading. | |
The LightReading element holds the most recent LightSensor reading. | |
The MagnetometerReading element holds the most recent Magnetometer reading. | |
The OrientationReading element holds the most recent OrientationSensor reading. | |
The PressureReading type holds the most recent pressure reading. | |
The ProximityReading element holds the most recent ProximitySensor reading. | |
The RotationReading element holds the most recent RotationSensor reading. | |
The SensorReading element serves as a base type for sensor readings. | |
The TapReading element holds the most recent TapSensor reading. |