openharmony 鸿蒙 sensor-overview

2025-06-06 浏览 (1)

Sensor Overview

Sensor Types

Sensors are an abstraction of underlying sensor hardware. Your application can access the underlying sensor hardware via the sensors. Using the Sensor APIs, you can query sensors on your device, subscribe to sensor data, customize algorithms based on sensor data, and develop various sensor-based applications, such as compass, motion-controlled games, and fitness and health applications.

TypeNameDescriptionUsage
ACCELEROMETERAcceleration sensorMeasures the acceleration (including the gravity acceleration) applied to a device on three physical axes (X, Y, and Z), in the unit of m/s2.Detecting the motion status
ACCELEROMETER_UNCALIBRATEDUncalibrated acceleration sensorMeasures the uncalibrated acceleration (including the gravity acceleration) applied to a device on three physical axes (X, Y, and Z), in the unit of m/s2.Measuring the acceleration bias estimation
LINEAR_ACCELEROMETERLinear acceleration sensorMeasures the linear acceleration (excluding the gravity acceleration) applied to a device on three physical axes (X, Y, and Z), in the unit of m/s2.Detecting the linear acceleration in each axis
GRAVITYGravity sensorMeasures the gravity acceleration applied to a device on three physical axes (X, Y, and Z), in the unit of m/s2.Measuring the gravity
GYROSCOPEGyroscope sensorMeasures the rotation angular velocity of a device on three physical axes (X, Y, and Z), in the unit of rad/s.Measuring the rotation angular velocity
GYROSCOPE_UNCALIBRATEDUncalibrated gyroscope sensorMeasures the uncalibrated rotation angular velocity of a device on three physical axes (X, Y, and Z), in the unit of rad/s.Measuring the bias estimation of the rotation angular velocity
SIGNIFICANT_MOTIONSignificant motion sensorChecks whether a device has a significant motion on three physical axes (X, Y, and Z). The value 0 means that the device does not have a significant motion, and 1 means the opposite.Detecting significant motions of a device
PEDOMETER_DETECTIONPedometer detection sensorDetects whether a user takes a step. The value can be 0 (the user does not take a step) or 1 (the user takes a step).Detecting whether a user takes a step
PEDOMETERPedometer sensorRecords the number of steps a user has walked.Providing the number of steps a user has walked
AMBIENT_TEMPERATUREAmbient temperature sensorMeasures the ambient temperature, in the unit of degree Celsius (°C).Measuring the ambient temperature
MAGNETIC_FIELDMagnetic field sensorMeasures the magnetic field on three physical axes (X, Y, and Z), in the unit of μT.Creating a compass
MAGNETIC_FIELD_UNCALIBRATEDUncalibrated magnetic field sensorMeasures the uncalibrated magnetic field on three physical axes (X, Y, and Z), in the unit of μT.Measuring the magnetic field bias estimation
HUMIDITYHumidity sensorMeasures the ambient relative humidity, in a percentage (%).Monitoring the dew point, absolute humidity, and relative humidity
BAROMETERBarometer sensorMeasures the barometric pressure, in the unit of hPa or mbar.Measuring the barometric pressure
ORIENTATIONOrientation sensorMeasures the rotation angles of a device on three physical axes (Z, X, and Y), in the unit of rad.Measuring the three orientation angles of the screen
ROTATION_VECTORRotation vector sensorMeasures the rotation vector of a device. It is a composite sensor that generates data from the acceleration sensor, magnetic field sensor, and gyroscope sensor.Detecting the orientation of a device in the East, North, Up (ENU) Cartesian coordinate system
PROXIMITYProximity sensorMeasures the distance between a visible object and the device screen.Measuring the distance between a person and the device during a call
AMBIENT_LIGHTAmbient light sensorMeasures the ambient light intensity of a device, in the unit of lux.Automatically adjusting the screen brightness and checking whether the screen is covered on the top
HEART_RATEHeart rate sensorMeasures the heart rate of a user.Providing users' heart rate data
WEAR_DETECTIONWear detection sensorChecks whether a user is wearing a wearable device.Detecting wearables
HALLHall effect sensorDetects a magnetic field around a device.Smart cover mode of the device

Working Principles

The following modules work cooperatively to implement sensors: Sensor API, Sensor Framework, Sensor Service, and HDF layer.

Figure 1 How the sensor works

fad1a124-a90e-460f-84fc-e87d6caebb21

  • Sensor API: provides APIs for performing basic operations on sensors, including querying the sensor list, subscribing to or unsubscribing from sensor data, and executing control commands. This module makes application development simpler.

  • Sensor Framework: manages sensor data subscription, creates and destroys data channels, subscribes to or unsubscribes from sensor data, and implements communication with the Sensor Service module.

  • Sensor Service: interacts with the HD_IDL module to receive, parse, and distribute data, manages foreground and background policies and sensors of a device, and controls sensor permissions.

  • HDF layer: selects proper policies based on the hardware first in first out (FIFO) and frequency, and adapts to different devices.

Constraints

  1. To obtain data of the following sensors, you must request the required permissions.
SensorPermissionSensitivityPermission Description
Acceleration sensor, uncalibrated acceleration sensor, and linear acceleration sensorohos.permission.ACCELEROMETERsystem_grantThe permission allows an application to read data from acceleration sensors, uncalibrated acceleration sensors, and linear acceleration sensors.
Gyroscope sensor and uncalibrated gyroscope sensorohos.permission.GYROSCOPEsystem_grantThe permission allows an application to read data from gyroscope sensors and uncalibrated gyroscope sensors.
Pedometer sensorohos.permission.ACTIVITY_MOTIONuser_grantThe permission allows an application to read an end user's motion status, for example, to determine whether the user is in motion or to record the number of steps that the user has walked.
Heart rate sensorohos.permission.READ_HEALTH_DATAuser_grantThe permission allows an application to obtain an end user's health data, such as heart rate data.
  1. The APIs for subscribing to and unsubscribing from sensor data work in pairs. If you do not need sensor data, call the unsubscription API to stop sensor data reporting.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Sensor Service Kit

harmony 鸿蒙Sensor Development

harmony 鸿蒙Sensor Development (C/C++)

harmony 鸿蒙Sensor Development (ArkTS)

harmony 鸿蒙Sensor Overview

harmony 鸿蒙Introduction to Sensor Service Kit

harmony 鸿蒙Vibrator Development

harmony 鸿蒙Vibrator Development (C/C++)

harmony 鸿蒙Vibrator Development (ArkTS)

harmony 鸿蒙Vibrator Overview

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/qcHXZD