1e41f4b71Sopenharmony_ci# Sensor
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci## 概述
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci提供API来使用常见的传感器特性。例如,调用API来获取传感器和订阅或取消订阅传感器数据。
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ci提供标准的开放api,定义常用传感器属性。
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci**起始版本:** 11
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## 汇总
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci### 文件
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci| 名称 | 描述 |
19e41f4b71Sopenharmony_ci| -------- | -------- |
20e41f4b71Sopenharmony_ci| [oh_sensor.h](oh_sensor_8h.md) | 声明操作传感器的API,包括获取传感器信息和订阅取消订阅传感器数据。  |
21e41f4b71Sopenharmony_ci| [oh_sensor_type.h](oh_sensor_type_8h.md) | 定义常用传感器属性。  |
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci### 类型定义
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci| 名称 | 描述 |
27e41f4b71Sopenharmony_ci| -------- | -------- |
28e41f4b71Sopenharmony_ci| [Sensor_Type](#sensor_type) | 枚举传感器类型。  |
29e41f4b71Sopenharmony_ci| [Sensor_Result](#sensor_result) | 定义传感器错误码。  |
30e41f4b71Sopenharmony_ci| [Sensor_Accuracy](#sensor_accuracy) | 枚举传感器上报的数据的精度级别。 |
31e41f4b71Sopenharmony_ci| [Sensor_Info](#sensor_info) | 定义传感器信息。  |
32e41f4b71Sopenharmony_ci| [Sensor_Event](#sensor_event) | 定义传感器数据信息。  |
33e41f4b71Sopenharmony_ci| [Sensor_SubscriptionId](#sensor_subscriptionid) | 定义传感器订阅ID,唯一标识传感器。  |
34e41f4b71Sopenharmony_ci| [Sensor_SubscriptionAttribute](#sensor_subscriptionattribute) | 定义传感器订阅属性。 |
35e41f4b71Sopenharmony_ci| void ([*Sensor_EventCallback](#sensor_eventcallback)) ([Sensor_Event](#sensor_event) \*event) | 定义用于传感器数据的回调函数。 |
36e41f4b71Sopenharmony_ci| [Sensor_Subscriber](#sensor_subscriber) | 定义传感器订阅者信息。  |
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci### 枚举
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci| 名称 | 描述 |
42e41f4b71Sopenharmony_ci| -------- | -------- |
43e41f4b71Sopenharmony_ci| [Sensor_Type](#sensor_type) {<br/>SENSOR_TYPE_ACCELEROMETER = 1, <br/>SENSOR_TYPE_GYROSCOPE = 2,<br/> SENSOR_TYPE_AMBIENT_LIGHT = 5, <br/>SENSOR_TYPE_MAGNETIC_FIELD = 6,<br/>SENSOR_TYPE_BAROMETER = 8,<br/> SENSOR_TYPE_HALL = 10, <br/>SENSOR_TYPE_PROXIMITY = 12,<br/> SENSOR_TYPE_ORIENTATION = 256,<br/>SENSOR_TYPE_GRAVITY = 257, <br/>SENSOR_TYPE_LINEAR_ACCELERATION = 258,<br/>SENSOR_TYPE_ROTATION_VECTOR = 259,<br/>SENSOR_TYPE_GAME_ROTATION_VECTOR = 262,<br/>SENSOR_TYPE_PEDOMETER_DETECTION = 265,<br/> SENSOR_TYPE_PEDOMETER = 266,<br/>SENSOR_TYPE_HEART_RATE = 278<br/>} | 枚举传感器类型。  |
44e41f4b71Sopenharmony_ci| [Sensor_Result](#sensor_result) { <br/>SENSOR_SUCCESS = 0,<br/> SENSOR_PERMISSION_DENIED = 201, <br/>SENSOR_PARAMETER_ERROR = 401,<br/> SENSOR_SERVICE_EXCEPTION = 14500101<br/> } | 定义传感器错误码。  |
45e41f4b71Sopenharmony_ci| [Sensor_Accuracy](#sensor_accuracy) { <br/>SENSOR_ACCURACY_UNRELIABLE = 0, <br/>SENSOR_ACCURACY_LOW = 1,<br/> SENSOR_ACCURACY_MEDIUM = 2, <br/>SENSOR_ACCURACY_HIGH = 3 <br/>} | 枚举传感器上报数据的精度级别。 |
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci### 函数
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci| 名称 | 描述 |
51e41f4b71Sopenharmony_ci| -------- | -------- |
52e41f4b71Sopenharmony_ci| [OH_Sensor_GetInfos](#oh_sensor_getinfos)([Sensor_Info](#sensor_info) **infos, uint32_t *count) | 获取设备上所有传感器的信息。                                 |
53e41f4b71Sopenharmony_ci| [OH_Sensor_Subscribe](#oh_sensor_subscribe)(const [Sensor_SubscriptionId](#sensor_subscriptionid) *id, const [Sensor_SubscriptionAttribute](#sensor_subscriptionattribute) *attribute, const [Sensor_Subscriber](#sensor_subscriber) *subscriber) | 订阅传感器数据。系统将以指定的频率向用户上报传感器数据。<br/>订阅加速度传感器,需要申请ohos.permission.ACCELEROMETER权限;<br/>订阅陀螺仪传感器,需要申请ohos.permission.GYROSCOPE权限;<br/>订阅计步器相关传感器时,需要申请ohos.permission.ACTIVITY_MOTION权限;<br/>订阅与健康相关的传感器时,比如心率传感器需要申请ohos.permission.READ_HEALTH_DATA权限,否则订阅失败;<br/>订阅其余传感器不需要申请权限。 |
54e41f4b71Sopenharmony_ci| [OH_Sensor_Unsubscribe](#oh_sensor_unsubscribe)(const [Sensor_SubscriptionId](#sensor_subscriptionid) *id, const [Sensor_Subscriber](#sensor_subscriber) *subscriber) | 取消订阅传感器数据。<br/>取消订阅加速度计传感器,需要申请ohos.permission.ACCELEROMETER权限; <br/>取消订阅陀螺仪传感器,需要申请ohos.permission.GYROSCOPE权限; <br/>取消订阅计步器相关传感器时,需要申请ohos.permission.ACTIVITY_MOTION权限;<br/>取消订阅与健康相关的传感器时,需要申请ohos.permission.READ_HEALTH_DATA权限,否则取消订阅失败。 <br/>取消订阅其余传感器不需要申请权限。 |
55e41f4b71Sopenharmony_ci| [OH_Sensor_CreateInfos](#oh_sensor_createinfos)(uint32_t count) | 用给定的数字创建一个实例数组,请参考Sensor_Info](#sensor_info)。 |
56e41f4b71Sopenharmony_ci| [OH_Sensor_DestroyInfos](#oh_sensor_destroyinfos)([Sensor_Info](#sensor_info) **sensors, uint32_t count) | 销毁实例数组并回收内存,请参考[Sensor_Info](#sensor_info)。 |
57e41f4b71Sopenharmony_ci| [OH_SensorInfo_GetName](#oh_sensorinfo_getname)([Sensor_Info](#sensor_info) *sensor, char *sensorName, uint32_t *length) | 获取传感器名称。  |
58e41f4b71Sopenharmony_ci| [OH_SensorInfo_GetVendorName](#oh_sensorinfo_getvendorname)([Sensor_Info](#sensor_info)* sensor, char *vendorName, uint32_t *length) | 获取传感器的厂商名称。  |
59e41f4b71Sopenharmony_ci| [OH_SensorInfo_GetType](#oh_sensorinfo_gettype)([Sensor_Info](#sensor_info)* sensor, [Sensor_Type](#sensor_type) *sensorType) | 获取传感器类型。  |
60e41f4b71Sopenharmony_ci| [OH_SensorInfo_GetResolution](#oh_sensorinfo_getresolution)([Sensor_Info](#sensor_info)* sensor, float *resolution) | 获取传感器分辨率。                                           |
61e41f4b71Sopenharmony_ci| [OH_SensorInfo_GetMinSamplingInterval](#oh_sensorinfo_getminsamplinginterval)([Sensor_Info](#sensor_info)* sensor, int64_t *minSamplingInterval) | 获取传感器的最小数据上报间隔。  |
62e41f4b71Sopenharmony_ci| [OH_SensorInfo_GetMaxSamplingInterval](#oh_sensorinfo_getmaxsamplinginterval)([Sensor_Info](#sensor_info)* sensor, int64_t *maxSamplingInterval) | 获取传感器的最大数据上报间隔时间。  |
63e41f4b71Sopenharmony_ci| [OH_SensorEvent_GetType](#oh_sensorevent_gettype)([Sensor_Event](#sensor_event)* sensorEvent, [Sensor_Type](#sensor_type) *sensorType) | 获取传感器类型。  |
64e41f4b71Sopenharmony_ci| [OH_SensorEvent_GetTimestamp](#oh_sensorevent_gettimestamp)([Sensor_Event](#sensor_event)* sensorEvent, int64_t *timestamp) | 获取传感器数据的时间戳。                                     |
65e41f4b71Sopenharmony_ci| [OH_SensorEvent_GetAccuracy](#oh_sensorevent_getaccuracy)([Sensor_Event](#sensor_event)* sensorEvent, Sensor_Accuracy *accuracy) | 获取传感器数据的精度。                                       |
66e41f4b71Sopenharmony_ci| [OH_SensorEvent_GetData](#oh_sensorevent_getdata)([Sensor_Event](#sensor_event)* sensorEvent, float **data, uint32_t *length) | 获取传感器数据。<br/>数据的长度和内容依赖于监听的传感器类型,传感器上报的数据格式如下:<br/>1.SENSOR_TYPE_ACCELEROMETER:data[0]、data[1]、data[2]分别表示设备x、y、z轴的加速度分量,单位m/s²;<br/>2.SENSOR_TYPE_GYROSCOPE:data[0]、data[1]、data[2]分别表示设备x、y、z轴的旋转角速度,单位弧度/s;<br/>3.SENSOR_TYPE_AMBIENT_LIGHT:data[0]表示环境光强度,单位lux;从API Version 12开始,将返回两个额外的数据,其中data[1]表示色温,单位kelvin;data[2]表示红外亮度,单位cd/m²;<br/>4. SENSOR_TYPE_MAGNETIC_FIELD:data[0]、data[1]、data[2]分别表示设备x、y、z轴的地磁分量,单位微特斯拉; <br/>5.SENSOR_TYPE_BAROMETER:data[0]表示气压值,单位hPa;<br/>6.SENSOR_TYPE_HALL:data[0]表示皮套吸合状态,0表示打开,大于0表示吸附;<br/>7.SENSOR_TYPE_PROXIMITY:data[0]表示接近状态,0表示接近,大于0表示远离;<br/>8.SENSOR_TYPE_ORIENTATION:data[0]、data[1]、data[2]分别表示设备绕z、x、y轴的角度,单位度;<br/>9.SENSOR_TYPE_GRAVITY:data[0]、data[1]、data[2]分别表示设备x、y、z轴的重力加速度分量,单位m/s²;<br/>10.SENSOR_TYPE_ROTATION_VECTOR:data[0]、data[1]、data[2]分别表示设备x、y、z轴的旋转角度,单位度,data[3]表示旋转向量元素;<br/>11.SENSOR_TYPE_PEDOMETER_DETECTION:data[0]表示计步检测状态,1表示检测到了步数变化;<br/>12.SENSOR_TYPE_PEDOMETER:data[0]表示步数;<br/>13.SENSOR_TYPE_HEART_RATE:data[0]表示心率数值;<br/>14.SENSOR_TYPE_LINEAR_ACCELERATION:从API Version 13开始支持,data[0]、data[1]、data[2]分别表示绕设备的x、y、z的线性加速度,单位m/s²;<br/>15.SENSOR_TYPE_GAME_ROTATION_VECTOR:从API Version 13开始支持,data[0]、data[1]、data[2]分别表示设备分别围绕x、y、z的旋转角度,单位为度,data[3]表示旋转向量。 |
67e41f4b71Sopenharmony_ci| [OH_Sensor_CreateSubscriptionId](#oh_sensor_createsubscriptionid)(void) | 创建一个[Sensor_SubscriptionId](#sensor_subscriptionid)实例。 |
68e41f4b71Sopenharmony_ci| [OH_Sensor_DestroySubscriptionId](#oh_sensor_destroysubscriptionid)([Sensor_SubscriptionId](#sensor_subscriptionid) *id) | 销毁[Sensor_SubscriptionId](#sensor_subscriptionid)实例并回收内存。 |
69e41f4b71Sopenharmony_ci| [OH_SensorSubscriptionId_GetType](#oh_sensorsubscriptionid_gettype)([Sensor_SubscriptionId](#sensor_subscriptionid) *id, [Sensor_Type](#sensor_type) *sensorType) | 获取传感器类型。  |
70e41f4b71Sopenharmony_ci| [OH_SensorSubscriptionId_SetType](#oh_sensorsubscriptionid_settype)([Sensor_SubscriptionId](#sensor_subscriptionid)* id, const [Sensor_Type](#sensor_type) sensorType) | 设置传感器类型。  |
71e41f4b71Sopenharmony_ci| [OH_Sensor_CreateSubscriptionAttribute](#oh_sensor_createsubscriptionattribute)(void) | 创建[Sensor_SubscriptionAttribute](#sensor_subscriptionattribute)实例。 |
72e41f4b71Sopenharmony_ci| [OH_Sensor_DestroySubscriptionAttribute](#oh_sensor_destroysubscriptionattribute)([Sensor_SubscriptionAttribute](#sensor_subscriptionattribute) *attribute) | 销毁[Sensor_SubscriptionAttribute](#sensor_subscriptionattribute)实例并回收内存。 |
73e41f4b71Sopenharmony_ci| [OH_SensorSubscriptionAttribute_SetSamplingInterval](#oh_sensorsubscriptionattribute_setsamplinginterval)([Sensor_SubscriptionAttribute](#sensor_subscriptionattribute)* attribute, const int64_t samplingInterval) | 设置传感器数据上报间隔。                                  |
74e41f4b71Sopenharmony_ci| [OH_SensorSubscriptionAttribute_GetSamplingInterval](#oh_sensorsubscriptionattribute_getsamplinginterval) ([Sensor_SubscriptionAttribute](#sensor_subscriptionattribute)* attribute, int64_t *samplingInterval) | 获取传感器数据上报间隔。                                   |
75e41f4b71Sopenharmony_ci| [OH_Sensor_CreateSubscriber](#oh_sensor_createsubscriber)(void) | 创建一个[Sensor_Subscriber](#sensor_subscriber)实例。      |
76e41f4b71Sopenharmony_ci| [OH_Sensor_DestroySubscriber](#oh_sensor_destroysubscriber)([Sensor_Subscriber](#sensor_subscriber) *subscriber) | 销毁[Sensor_Subscriber](#sensor_subscriber)实例并回收内存。 |
77e41f4b71Sopenharmony_ci| [OH_SensorSubscriber_SetCallback](#oh_sensorsubscriber_setcallback)([Sensor_Subscriber](#sensor_subscriber)* subscriber, const [Sensor_EventCallback](#sensor_eventcallback) callback) | 设置一个回调函数来上报传感器数据。 |
78e41f4b71Sopenharmony_ci| [OH_SensorSubscriber_GetCallback](#oh_sensorsubscriber_getcallback)([Sensor_Subscriber](#sensor_subscriber)* subscriber, [Sensor_EventCallback](#sensor_eventcallback) *callback) | 获取用于上报传感器数据的回调函数。 |
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci## 类型定义说明
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci### Sensor_Accuracy
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci```
87e41f4b71Sopenharmony_citypedef enum Sensor_Accuracy Sensor_Accuracy
88e41f4b71Sopenharmony_ci```
89e41f4b71Sopenharmony_ci**描述:**
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci枚举传感器上报的数据的精度级别。
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci**起始版本:** 11
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci### Sensor_Event
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci```
99e41f4b71Sopenharmony_citypedef struct Sensor_Event Sensor_Event
100e41f4b71Sopenharmony_ci```
101e41f4b71Sopenharmony_ci**描述:**
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci定义传感器数据信息。
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci**起始版本:** 11
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci### Sensor_EventCallback
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci```
111e41f4b71Sopenharmony_citypedef void(*Sensor_EventCallback)(Sensor_Event *event)
112e41f4b71Sopenharmony_ci```
113e41f4b71Sopenharmony_ci**描述:**
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci定义用于上报传感器数据的回调函数。
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci**起始版本:** 11
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci### Sensor_Info
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci```
123e41f4b71Sopenharmony_citypedef struct Sensor_Info Sensor_Info
124e41f4b71Sopenharmony_ci```
125e41f4b71Sopenharmony_ci**描述:**
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci定义传感器信息。
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci**起始版本:** 11
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci### Sensor_Result
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci```
135e41f4b71Sopenharmony_citypedef enum Sensor_Result Sensor_Result
136e41f4b71Sopenharmony_ci```
137e41f4b71Sopenharmony_ci**描述:**
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci定义传感器错误码。
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci**起始版本:** 11
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci### Sensor_Subscriber
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ci```
147e41f4b71Sopenharmony_citypedef struct Sensor_Subscriber Sensor_Subscriber
148e41f4b71Sopenharmony_ci```
149e41f4b71Sopenharmony_ci**描述:**
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_ci定义传感器订阅者信息。
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci**起始版本:** 11
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci### Sensor_SubscriptionAttribute
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_ci```
159e41f4b71Sopenharmony_citypedef struct Sensor_SubscriptionAttribute Sensor_SubscriptionAttribute
160e41f4b71Sopenharmony_ci```
161e41f4b71Sopenharmony_ci**描述:**
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci定义传感器订阅属性。
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_ci**起始版本:** 11
166e41f4b71Sopenharmony_ci
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci### Sensor_SubscriptionId
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci```
171e41f4b71Sopenharmony_citypedef struct Sensor_SubscriptionId Sensor_SubscriptionId
172e41f4b71Sopenharmony_ci```
173e41f4b71Sopenharmony_ci**描述:**
174e41f4b71Sopenharmony_ci
175e41f4b71Sopenharmony_ci定义传感器订阅ID,唯一标识传感器。
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_ci**起始版本:** 11
178e41f4b71Sopenharmony_ci
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci### Sensor_Type
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ci```
183e41f4b71Sopenharmony_citypedef enum Sensor_Type Sensor_Type
184e41f4b71Sopenharmony_ci```
185e41f4b71Sopenharmony_ci**描述:**
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci枚举传感器类型。
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ci**起始版本:** 11
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci## 枚举类型说明
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci
195e41f4b71Sopenharmony_ci### Sensor_Accuracy
196e41f4b71Sopenharmony_ci
197e41f4b71Sopenharmony_ci```
198e41f4b71Sopenharmony_cienum Sensor_Accuracy
199e41f4b71Sopenharmony_ci```
200e41f4b71Sopenharmony_ci**描述:**
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_ci枚举传感器上报的数据的精度级别。
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci**起始版本:** 11
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_ci| 枚举值 | 描述 |
207e41f4b71Sopenharmony_ci| -------- | -------- |
208e41f4b71Sopenharmony_ci| SENSOR_ACCURACY_UNRELIABLE  | 传感器数据不可靠。有可能传感器不与设备接触而进行测量。 |
209e41f4b71Sopenharmony_ci| SENSOR_ACCURACY_LOW  | 传感器数据精度较低。数据在使用前必须根据环境进行校准。 |
210e41f4b71Sopenharmony_ci| SENSOR_ACCURACY_MEDIUM  | 传感器数据处于中等精度水平。建议用户在使用前根据实际环境进行数据校准。 |
211e41f4b71Sopenharmony_ci| SENSOR_ACCURACY_HIGH  | 传感器数据具有很高的精度。数据可以直接使用。 |
212e41f4b71Sopenharmony_ci
213e41f4b71Sopenharmony_ci
214e41f4b71Sopenharmony_ci### Sensor_Result
215e41f4b71Sopenharmony_ci
216e41f4b71Sopenharmony_ci```
217e41f4b71Sopenharmony_cienum Sensor_Result
218e41f4b71Sopenharmony_ci```
219e41f4b71Sopenharmony_ci**描述:**
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci定义传感器错误码。
222e41f4b71Sopenharmony_ci
223e41f4b71Sopenharmony_ci**起始版本:** 11
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_ci| 枚举值 | 描述 |
226e41f4b71Sopenharmony_ci| -------- | -------- |
227e41f4b71Sopenharmony_ci| SENSOR_SUCCESS  | 操作成功。 |
228e41f4b71Sopenharmony_ci| SENSOR_PERMISSION_DENIED  | 权限验证失败。 |
229e41f4b71Sopenharmony_ci| SENSOR_PARAMETER_ERROR  | 参数检查失败。例如,没有传入强制参数,或者传入的参数类型不正确。 |
230e41f4b71Sopenharmony_ci| SENSOR_SERVICE_EXCEPTION  | 传感器服务异常。 |
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ci
233e41f4b71Sopenharmony_ci### Sensor_Type
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_ci```
236e41f4b71Sopenharmony_cienum Sensor_Type
237e41f4b71Sopenharmony_ci```
238e41f4b71Sopenharmony_ci**描述:**
239e41f4b71Sopenharmony_ci
240e41f4b71Sopenharmony_ci枚举传感器类型。
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci**起始版本:** 11
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_ci| 枚举值 | 描述 |
245e41f4b71Sopenharmony_ci| -------- | -------- |
246e41f4b71Sopenharmony_ci| SENSOR_TYPE_ACCELEROMETER  | 加速度传感器。 |
247e41f4b71Sopenharmony_ci| SENSOR_TYPE_GYROSCOPE  | 陀螺仪传感器。 |
248e41f4b71Sopenharmony_ci| SENSOR_TYPE_AMBIENT_LIGHT  | 环境光传感器。 |
249e41f4b71Sopenharmony_ci| SENSOR_TYPE_MAGNETIC_FIELD  | 地磁传感器。 |
250e41f4b71Sopenharmony_ci| SENSOR_TYPE_BAROMETER  | 气压传感器。 |
251e41f4b71Sopenharmony_ci| SENSOR_TYPE_HALL  | 霍尔传感器。 |
252e41f4b71Sopenharmony_ci| SENSOR_TYPE_PROXIMITY  | 接近光传感器。 |
253e41f4b71Sopenharmony_ci| SENSOR_TYPE_ORIENTATION  | 方向传感器。 |
254e41f4b71Sopenharmony_ci| SENSOR_TYPE_GRAVITY  | 重力传感器。 |
255e41f4b71Sopenharmony_ci| SENSOR_TYPE_ROTATION_VECTOR  | 旋转矢量传感器。 |
256e41f4b71Sopenharmony_ci| SENSOR_TYPE_PEDOMETER_DETECTION  | 计步器检测传感器。 |
257e41f4b71Sopenharmony_ci| SENSOR_TYPE_PEDOMETER  | 计步器传感器。 |
258e41f4b71Sopenharmony_ci| SENSOR_TYPE_HEART_RATE  | 心率传感器。 |
259e41f4b71Sopenharmony_ci
260e41f4b71Sopenharmony_ci
261e41f4b71Sopenharmony_ci## 函数说明
262e41f4b71Sopenharmony_ci
263e41f4b71Sopenharmony_ci
264e41f4b71Sopenharmony_ci### OH_Sensor_CreateInfos()
265e41f4b71Sopenharmony_ci
266e41f4b71Sopenharmony_ci```
267e41f4b71Sopenharmony_ciSensor_Info **OH_Sensor_CreateInfos(uint32_t count)
268e41f4b71Sopenharmony_ci```
269e41f4b71Sopenharmony_ci**描述:**
270e41f4b71Sopenharmony_ci
271e41f4b71Sopenharmony_ci用给定的数字创建一个实例数组,请参考 [Sensor_Info](#sensor_info)。
272e41f4b71Sopenharmony_ci
273e41f4b71Sopenharmony_ci**起始版本:** 11
274e41f4b71Sopenharmony_ci
275e41f4b71Sopenharmony_ci**参数:**
276e41f4b71Sopenharmony_ci
277e41f4b71Sopenharmony_ci| 名称 | 描述 |
278e41f4b71Sopenharmony_ci| -------- | -------- |
279e41f4b71Sopenharmony_ci| count | 要创建的实例的数量,请参考 [Sensor_Info](#sensor_info)。 |
280e41f4b71Sopenharmony_ci
281e41f4b71Sopenharmony_ci**返回:**
282e41f4b71Sopenharmony_ci
283e41f4b71Sopenharmony_ci如果操作成功,返回指向 [Sensor_Info](#sensor_info) 实例数组的双指针;否则返回**NULL**。
284e41f4b71Sopenharmony_ci
285e41f4b71Sopenharmony_ci
286e41f4b71Sopenharmony_ci### OH_Sensor_CreateSubscriber()
287e41f4b71Sopenharmony_ci
288e41f4b71Sopenharmony_ci```
289e41f4b71Sopenharmony_ciSensor_Subscriber *OH_Sensor_CreateSubscriber(void)
290e41f4b71Sopenharmony_ci```
291e41f4b71Sopenharmony_ci**描述:**
292e41f4b71Sopenharmony_ci
293e41f4b71Sopenharmony_ci创建一个 [Sensor_Subscriber ](#sensor_subscriber)实例。
294e41f4b71Sopenharmony_ci
295e41f4b71Sopenharmony_ci**起始版本:** 11
296e41f4b71Sopenharmony_ci
297e41f4b71Sopenharmony_ci**返回:**
298e41f4b71Sopenharmony_ci
299e41f4b71Sopenharmony_ci如果操作成功,返回指向 [Sensor_Subscriber](#sensor_subscriber) 实例的指针;否则返回**NULL**。
300e41f4b71Sopenharmony_ci
301e41f4b71Sopenharmony_ci
302e41f4b71Sopenharmony_ci### OH_Sensor_CreateSubscriptionAttribute()
303e41f4b71Sopenharmony_ci
304e41f4b71Sopenharmony_ci```
305e41f4b71Sopenharmony_ciSensor_SubscriptionAttribute *OH_Sensor_CreateSubscriptionAttribute(void)
306e41f4b71Sopenharmony_ci```
307e41f4b71Sopenharmony_ci**描述:**
308e41f4b71Sopenharmony_ci
309e41f4b71Sopenharmony_ci创建 [Sensor_SubscriptionAttribute ](#sensor_subscriptionattribute)实例。
310e41f4b71Sopenharmony_ci
311e41f4b71Sopenharmony_ci**起始版本:** 11
312e41f4b71Sopenharmony_ci
313e41f4b71Sopenharmony_ci**返回:**
314e41f4b71Sopenharmony_ci
315e41f4b71Sopenharmony_ci如果操作成功,返回指向 [Sensor_SubscriptionAttribute](#sensor_subscriptionattribute) 实例的指针;否则返回**NULL**。
316e41f4b71Sopenharmony_ci
317e41f4b71Sopenharmony_ci
318e41f4b71Sopenharmony_ci### OH_Sensor_CreateSubscriptionId()
319e41f4b71Sopenharmony_ci
320e41f4b71Sopenharmony_ci```
321e41f4b71Sopenharmony_ciSensor_SubscriptionId *OH_Sensor_CreateSubscriptionId(void)
322e41f4b71Sopenharmony_ci```
323e41f4b71Sopenharmony_ci**描述:**
324e41f4b71Sopenharmony_ci
325e41f4b71Sopenharmony_ci创建一个 [Sensor_SubscriptionId](#sensor_subscriptionid) 实例。
326e41f4b71Sopenharmony_ci
327e41f4b71Sopenharmony_ci**起始版本:** 11
328e41f4b71Sopenharmony_ci
329e41f4b71Sopenharmony_ci**返回:**
330e41f4b71Sopenharmony_ci
331e41f4b71Sopenharmony_ci如果操作成功,返回指向 [Sensor_SubscriptionId](#sensor_subscriptionid) 实例的指针;否则返回**NULL**。
332e41f4b71Sopenharmony_ci
333e41f4b71Sopenharmony_ci
334e41f4b71Sopenharmony_ci### OH_Sensor_DestroyInfos()
335e41f4b71Sopenharmony_ci
336e41f4b71Sopenharmony_ci```
337e41f4b71Sopenharmony_ciint32_t OH_Sensor_DestroyInfos(Sensor_Info **sensors, uint32_t count)
338e41f4b71Sopenharmony_ci```
339e41f4b71Sopenharmony_ci**描述:**
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_ci销毁实例数组并回收内存,请参考 [Sensor_Info](#sensor_info)。
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_ci**起始版本:** 11
344e41f4b71Sopenharmony_ci
345e41f4b71Sopenharmony_ci**参数:**
346e41f4b71Sopenharmony_ci
347e41f4b71Sopenharmony_ci| 名称 | 描述 |
348e41f4b71Sopenharmony_ci| -------- | -------- |
349e41f4b71Sopenharmony_ci| sensors | 指向 [Sensor_Info](#sensor_info) 实例数组的双指针。 |
350e41f4b71Sopenharmony_ci| count | 要销毁的 [Sensor_Info](#sensor_info) 实例的数量。 |
351e41f4b71Sopenharmony_ci
352e41f4b71Sopenharmony_ci**返回:**
353e41f4b71Sopenharmony_ci
354e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
355e41f4b71Sopenharmony_ci
356e41f4b71Sopenharmony_ci
357e41f4b71Sopenharmony_ci### OH_Sensor_DestroySubscriber()
358e41f4b71Sopenharmony_ci
359e41f4b71Sopenharmony_ci```
360e41f4b71Sopenharmony_ciint32_t OH_Sensor_DestroySubscriber(Sensor_Subscriber *subscriber)
361e41f4b71Sopenharmony_ci```
362e41f4b71Sopenharmony_ci**描述:**
363e41f4b71Sopenharmony_ci
364e41f4b71Sopenharmony_ci销毁 [Sensor_Subscriber ](#sensor_subscriber)实例并回收内存。
365e41f4b71Sopenharmony_ci
366e41f4b71Sopenharmony_ci**起始版本:** 11
367e41f4b71Sopenharmony_ci
368e41f4b71Sopenharmony_ci**参数:**
369e41f4b71Sopenharmony_ci
370e41f4b71Sopenharmony_ci| 名称 | 描述 |
371e41f4b71Sopenharmony_ci| -------- | -------- |
372e41f4b71Sopenharmony_ci| subscriber | 指向 [Sensor_Subscriber](#sensor_subscriber) 实例的指针。 |
373e41f4b71Sopenharmony_ci
374e41f4b71Sopenharmony_ci**返回:**
375e41f4b71Sopenharmony_ci
376e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
377e41f4b71Sopenharmony_ci
378e41f4b71Sopenharmony_ci
379e41f4b71Sopenharmony_ci### OH_Sensor_DestroySubscriptionAttribute()
380e41f4b71Sopenharmony_ci
381e41f4b71Sopenharmony_ci```
382e41f4b71Sopenharmony_ciint32_t OH_Sensor_DestroySubscriptionAttribute(Sensor_SubscriptionAttribute *attribute)
383e41f4b71Sopenharmony_ci```
384e41f4b71Sopenharmony_ci**描述:**
385e41f4b71Sopenharmony_ci
386e41f4b71Sopenharmony_ci销毁 [Sensor_SubscriptionAttribute](#sensor_subscriptionattribute) 实例并回收内存。
387e41f4b71Sopenharmony_ci
388e41f4b71Sopenharmony_ci**起始版本:** 11
389e41f4b71Sopenharmony_ci
390e41f4b71Sopenharmony_ci**参数:**
391e41f4b71Sopenharmony_ci
392e41f4b71Sopenharmony_ci| 名称 | 描述 |
393e41f4b71Sopenharmony_ci| -------- | -------- |
394e41f4b71Sopenharmony_ci| attribute | 指向 [Sensor_SubscriptionAttribute](#sensor_subscriptionattribute) 实例的指针。 |
395e41f4b71Sopenharmony_ci
396e41f4b71Sopenharmony_ci**返回:**
397e41f4b71Sopenharmony_ci
398e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
399e41f4b71Sopenharmony_ci
400e41f4b71Sopenharmony_ci
401e41f4b71Sopenharmony_ci### OH_Sensor_DestroySubscriptionId()
402e41f4b71Sopenharmony_ci
403e41f4b71Sopenharmony_ci```
404e41f4b71Sopenharmony_ciint32_t OH_Sensor_DestroySubscriptionId(Sensor_SubscriptionId *id)
405e41f4b71Sopenharmony_ci```
406e41f4b71Sopenharmony_ci**描述:**
407e41f4b71Sopenharmony_ci
408e41f4b71Sopenharmony_ci销毁 [Sensor_SubscriptionId](#sensor_subscriptionid) 实例并回收内存。
409e41f4b71Sopenharmony_ci
410e41f4b71Sopenharmony_ci**起始版本:** 11
411e41f4b71Sopenharmony_ci
412e41f4b71Sopenharmony_ci**参数:**
413e41f4b71Sopenharmony_ci
414e41f4b71Sopenharmony_ci| 名称 | 描述 |
415e41f4b71Sopenharmony_ci| -------- | -------- |
416e41f4b71Sopenharmony_ci| id | 指向 [Sensor_SubscriptionId](#sensor_subscriptionid) 实例的指针。 |
417e41f4b71Sopenharmony_ci
418e41f4b71Sopenharmony_ci**返回:**
419e41f4b71Sopenharmony_ci
420e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
421e41f4b71Sopenharmony_ci
422e41f4b71Sopenharmony_ci
423e41f4b71Sopenharmony_ci### OH_Sensor_GetInfos()
424e41f4b71Sopenharmony_ci
425e41f4b71Sopenharmony_ci```
426e41f4b71Sopenharmony_ciSensor_Result OH_Sensor_GetInfos(Sensor_Info **infos, uint32_t *count)
427e41f4b71Sopenharmony_ci```
428e41f4b71Sopenharmony_ci**描述:**
429e41f4b71Sopenharmony_ci
430e41f4b71Sopenharmony_ci获取设备上所有传感器的信息。
431e41f4b71Sopenharmony_ci
432e41f4b71Sopenharmony_ci**起始版本:** 11
433e41f4b71Sopenharmony_ci
434e41f4b71Sopenharmony_ci**参数:**
435e41f4b71Sopenharmony_ci
436e41f4b71Sopenharmony_ci| 名称 | 描述 |
437e41f4b71Sopenharmony_ci| -------- | -------- |
438e41f4b71Sopenharmony_ci| infos | 双指针指向设备上所有传感器的信息。请参考 [Sensor_Info](#sensor_info)。 |
439e41f4b71Sopenharmony_ci| count | 指向设备上传感器数量的指针。  |
440e41f4b71Sopenharmony_ci
441e41f4b71Sopenharmony_ci**返回:**
442e41f4b71Sopenharmony_ci
443e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
444e41f4b71Sopenharmony_ci
445e41f4b71Sopenharmony_ci
446e41f4b71Sopenharmony_ci### OH_Sensor_Subscribe()
447e41f4b71Sopenharmony_ci
448e41f4b71Sopenharmony_ci```
449e41f4b71Sopenharmony_ciSensor_Result OH_Sensor_Subscribe(const Sensor_SubscriptionId *id, const Sensor_SubscriptionAttribute *attribute, const Sensor_Subscriber *subscriber)
450e41f4b71Sopenharmony_ci```
451e41f4b71Sopenharmony_ci**描述:**
452e41f4b71Sopenharmony_ci
453e41f4b71Sopenharmony_ci订阅传感器数据。系统将以指定的频率向用户上报传感器数据。 订阅加速度传感器,需要申请ohos.permission.ACCELEROMETER权限; 订阅陀螺仪传感器,需要申请ohos.permission.GYROSCOPE权限; 订阅计步器相关传感器时,需要申请ohos.permission.ACTIVITY_MOTION权限; 订阅与健康相关的传感器时,比如心率传感器,需要申请ohos.permission.READ_HEALTH_DATA权限,否则订阅失败。 订阅其余传感器不需要申请权限。
454e41f4b71Sopenharmony_ci
455e41f4b71Sopenharmony_ci**起始版本:** 11
456e41f4b71Sopenharmony_ci
457e41f4b71Sopenharmony_ci**参数:**
458e41f4b71Sopenharmony_ci
459e41f4b71Sopenharmony_ci| 名称 | 描述 |
460e41f4b71Sopenharmony_ci| -------- | -------- |
461e41f4b71Sopenharmony_ci| id | 指向传感器订阅ID的指针。请参考 [Sensor_SubscriptionId](#sensor_subscriptionid)。 |
462e41f4b71Sopenharmony_ci| attribute | 指向订阅属性的指针,该属性用于指定数据报告频率。请参考 [Sensor_SubscriptionAttribute](#sensor_subscriptionattribute)。 |
463e41f4b71Sopenharmony_ci| subscriber | 指向订阅者信息的指针,该信息用于指定的回调函数报告传感器数据。请参考 [Sensor_Subscriber](#sensor_subscriber)。 |
464e41f4b71Sopenharmony_ci
465e41f4b71Sopenharmony_ci**返回:**
466e41f4b71Sopenharmony_ci
467e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
468e41f4b71Sopenharmony_ci
469e41f4b71Sopenharmony_ci**Permission:**
470e41f4b71Sopenharmony_ci
471e41f4b71Sopenharmony_ciohos.permission.ACCELEROMETER or ohos.permission.GYROSCOPE or ohos.permission.ACTIVITY_MOTION or ohos.permission.READ_HEALTH_DATA
472e41f4b71Sopenharmony_ci
473e41f4b71Sopenharmony_ci
474e41f4b71Sopenharmony_ci### OH_Sensor_Unsubscribe()
475e41f4b71Sopenharmony_ci
476e41f4b71Sopenharmony_ci```
477e41f4b71Sopenharmony_ciSensor_Result OH_Sensor_Unsubscribe(const Sensor_SubscriptionId *id, const Sensor_Subscriber *subscriber)
478e41f4b71Sopenharmony_ci```
479e41f4b71Sopenharmony_ci**描述:**
480e41f4b71Sopenharmony_ci
481e41f4b71Sopenharmony_ci取消订阅传感器数据。 取消订阅加速度计传感器,需要申请ohos.permission.ACCELEROMETER权限; 取消订阅陀螺仪传感器,需要申请ohos.permission.GYROSCOPE权限; 取消订阅计步器相关传感器时,需要申请ohos.permission.ACTIVITY_MOTION权限; 取消订阅与健康相关的传感器时,需要申请ohos.permission.READ_HEALTH_DATA权限,否则取消订阅失败。 取消订阅其余传感器不需要申请权限。
482e41f4b71Sopenharmony_ci
483e41f4b71Sopenharmony_ci**起始版本:** 11
484e41f4b71Sopenharmony_ci
485e41f4b71Sopenharmony_ci**参数:**
486e41f4b71Sopenharmony_ci
487e41f4b71Sopenharmony_ci| 名称 | 描述 |
488e41f4b71Sopenharmony_ci| -------- | -------- |
489e41f4b71Sopenharmony_ci| id | 指向传感器订阅ID的指针。请参考 [Sensor_SubscriptionId](#sensor_subscriptionid)。 |
490e41f4b71Sopenharmony_ci| subscriber | 指向订阅者信息的指针,该信息用于指定的回调函数报告传感器数据。请参考 [Sensor_Subscriber](#sensor_subscriber)。 |
491e41f4b71Sopenharmony_ci
492e41f4b71Sopenharmony_ci**返回:**
493e41f4b71Sopenharmony_ci
494e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
495e41f4b71Sopenharmony_ci
496e41f4b71Sopenharmony_ci**Permission:**
497e41f4b71Sopenharmony_ci
498e41f4b71Sopenharmony_ciohos.permission.ACCELEROMETER or ohos.permission.GYROSCOPE or ohos.permission.ACTIVITY_MOTION or ohos.permission.READ_HEALTH_DATA
499e41f4b71Sopenharmony_ci
500e41f4b71Sopenharmony_ci
501e41f4b71Sopenharmony_ci### OH_SensorEvent_GetAccuracy()
502e41f4b71Sopenharmony_ci
503e41f4b71Sopenharmony_ci```
504e41f4b71Sopenharmony_ciint32_t OH_SensorEvent_GetAccuracy(Sensor_Event* sensorEvent, Sensor_Accuracy *accuracy)
505e41f4b71Sopenharmony_ci```
506e41f4b71Sopenharmony_ci**描述:**
507e41f4b71Sopenharmony_ci
508e41f4b71Sopenharmony_ci获取传感器数据的精度。
509e41f4b71Sopenharmony_ci
510e41f4b71Sopenharmony_ci**起始版本:** 11
511e41f4b71Sopenharmony_ci
512e41f4b71Sopenharmony_ci**参数:**
513e41f4b71Sopenharmony_ci
514e41f4b71Sopenharmony_ci| 名称 | 描述 |
515e41f4b71Sopenharmony_ci| -------- | -------- |
516e41f4b71Sopenharmony_ci| sensorEvent | 指向传感器数据信息的指针。  |
517e41f4b71Sopenharmony_ci| accuracy | 指向精度的指针。  |
518e41f4b71Sopenharmony_ci
519e41f4b71Sopenharmony_ci**返回:**
520e41f4b71Sopenharmony_ci
521e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
522e41f4b71Sopenharmony_ci
523e41f4b71Sopenharmony_ci
524e41f4b71Sopenharmony_ci### OH_SensorEvent_GetData()
525e41f4b71Sopenharmony_ci
526e41f4b71Sopenharmony_ci```
527e41f4b71Sopenharmony_ciint32_t OH_SensorEvent_GetData(Sensor_Event* sensorEvent, float **data, uint32_t *length)
528e41f4b71Sopenharmony_ci```
529e41f4b71Sopenharmony_ci**描述:**
530e41f4b71Sopenharmony_ci
531e41f4b71Sopenharmony_ci获取传感器数据。数据的长度和内容依赖于监听的传感器类型,传感器上报的数据格式如下:
532e41f4b71Sopenharmony_ci
533e41f4b71Sopenharmony_ciSENSOR_TYPE_ACCELEROMETER:data[0]、data[1]、data[2]分别表示设备x、y、z轴的加速度分量,单位m/s²;
534e41f4b71Sopenharmony_ci
535e41f4b71Sopenharmony_ciSENSOR_TYPE_GYROSCOPE:data[0]、data[1]、data[2]分别表示设备x、y、z轴的旋转角速度,单位弧度/s;
536e41f4b71Sopenharmony_ci
537e41f4b71Sopenharmony_ciSENSOR_TYPE_AMBIENT_LIGHT:data[0]表示环境光强度,in lux;
538e41f4b71Sopenharmony_ci
539e41f4b71Sopenharmony_ciSENSOR_TYPE_MAGNETIC_FIELD:data[0]、data[1]、data[2]分别表示设备x、y、z轴的地磁分量,单位微特斯拉; 
540e41f4b71Sopenharmony_ci
541e41f4b71Sopenharmony_ciSENSOR_TYPE_BAROMETER:data[0]表示气压值,单位hPa;
542e41f4b71Sopenharmony_ci
543e41f4b71Sopenharmony_ciSENSOR_TYPE_HALL:data[0]表示皮套吸合状态,0表示打开,大于0表示吸附;
544e41f4b71Sopenharmony_ci
545e41f4b71Sopenharmony_ciSENSOR_TYPE_PROXIMITY:data[0]表示接近状态,0表示接近,大于0表示远离;
546e41f4b71Sopenharmony_ci
547e41f4b71Sopenharmony_ciSENSOR_TYPE_ORIENTATION:data[0]、data[1]、data[2]分别表示设备绕z、x、y轴的角度,单位度;
548e41f4b71Sopenharmony_ci
549e41f4b71Sopenharmony_ciSENSOR_TYPE_GRAVITY:data[0]、data[1]、data[2]分别表示设备x、y、z轴的重力加速度分量,单位m/s²;
550e41f4b71Sopenharmony_ci
551e41f4b71Sopenharmony_ciSENSOR_TYPE_ROTATION_VECTOR:data[0]、data[1]、data[2]分别表示设备x、y、z轴的旋转角度,单位度,data[3]表示旋转向量元素;
552e41f4b71Sopenharmony_ci
553e41f4b71Sopenharmony_ciSENSOR_TYPE_PEDOMETER_DETECTION:data[0]表示计步检测状态,1表示检测到了步数变化;
554e41f4b71Sopenharmony_ci
555e41f4b71Sopenharmony_ciSENSOR_TYPE_PEDOMETER:data[0]表示步数;
556e41f4b71Sopenharmony_ci
557e41f4b71Sopenharmony_ciSENSOR_TYPE_HEART_RATE:data[0]表示心率数值;
558e41f4b71Sopenharmony_ci
559e41f4b71Sopenharmony_ciSENSOR_TYPE_LINEAR_ACCELERATION:从API Version 13开始支持,data[0]、data[1]、data[2]分别表示绕设备的x、y、z的线性加速度,单位m/s²;
560e41f4b71Sopenharmony_ci
561e41f4b71Sopenharmony_ciSENSOR_TYPE_GAME_ROTATION_VECTOR:从API Version 13开始支持,data[0]、data[1]、data[2]分别表示设备分别围绕x、y、z的旋转角度,单位为度,data[3]表示旋转向量。
562e41f4b71Sopenharmony_ci
563e41f4b71Sopenharmony_ci**起始版本:** 11
564e41f4b71Sopenharmony_ci
565e41f4b71Sopenharmony_ci**参数:**
566e41f4b71Sopenharmony_ci
567e41f4b71Sopenharmony_ci| 名称 | 描述 |
568e41f4b71Sopenharmony_ci| -------- | -------- |
569e41f4b71Sopenharmony_ci| sensorEvent | 传感器数据信息。  |
570e41f4b71Sopenharmony_ci| data | 出参,传感器数据。  |
571e41f4b71Sopenharmony_ci| length | 出参,数组长度。  |
572e41f4b71Sopenharmony_ci
573e41f4b71Sopenharmony_ci**返回:**
574e41f4b71Sopenharmony_ci
575e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
576e41f4b71Sopenharmony_ci
577e41f4b71Sopenharmony_ci
578e41f4b71Sopenharmony_ci### OH_SensorEvent_GetTimestamp()
579e41f4b71Sopenharmony_ci
580e41f4b71Sopenharmony_ci```
581e41f4b71Sopenharmony_ciint32_t OH_SensorEvent_GetTimestamp(Sensor_Event* sensorEvent, int64_t *timestamp)
582e41f4b71Sopenharmony_ci```
583e41f4b71Sopenharmony_ci**描述:**
584e41f4b71Sopenharmony_ci
585e41f4b71Sopenharmony_ci获取传感器数据的时间戳。
586e41f4b71Sopenharmony_ci
587e41f4b71Sopenharmony_ci**起始版本:** 11
588e41f4b71Sopenharmony_ci
589e41f4b71Sopenharmony_ci**参数:**
590e41f4b71Sopenharmony_ci
591e41f4b71Sopenharmony_ci| 名称 | 描述 |
592e41f4b71Sopenharmony_ci| -------- | -------- |
593e41f4b71Sopenharmony_ci| sensorEvent | 指向传感器数据信息的指针。  |
594e41f4b71Sopenharmony_ci| timestamp | 时间戳指针。  |
595e41f4b71Sopenharmony_ci
596e41f4b71Sopenharmony_ci**返回:**
597e41f4b71Sopenharmony_ci
598e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
599e41f4b71Sopenharmony_ci
600e41f4b71Sopenharmony_ci
601e41f4b71Sopenharmony_ci### OH_SensorEvent_GetType()
602e41f4b71Sopenharmony_ci
603e41f4b71Sopenharmony_ci```
604e41f4b71Sopenharmony_ciint32_t OH_SensorEvent_GetType(Sensor_Event* sensorEvent, Sensor_Type *sensorType)
605e41f4b71Sopenharmony_ci```
606e41f4b71Sopenharmony_ci**描述:**
607e41f4b71Sopenharmony_ci
608e41f4b71Sopenharmony_ci获取传感器类型。
609e41f4b71Sopenharmony_ci
610e41f4b71Sopenharmony_ci**起始版本:** 11
611e41f4b71Sopenharmony_ci
612e41f4b71Sopenharmony_ci**参数:**
613e41f4b71Sopenharmony_ci
614e41f4b71Sopenharmony_ci| 名称 | 描述 |
615e41f4b71Sopenharmony_ci| -------- | -------- |
616e41f4b71Sopenharmony_ci| sensorEvent | 指向传感器数据信息的指针。  |
617e41f4b71Sopenharmony_ci| sensorType | 指向传感器类型的指针。  |
618e41f4b71Sopenharmony_ci
619e41f4b71Sopenharmony_ci**返回:**
620e41f4b71Sopenharmony_ci
621e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
622e41f4b71Sopenharmony_ci
623e41f4b71Sopenharmony_ci
624e41f4b71Sopenharmony_ci### OH_SensorInfo_GetMaxSamplingInterval()
625e41f4b71Sopenharmony_ci
626e41f4b71Sopenharmony_ci```
627e41f4b71Sopenharmony_ciint32_t OH_SensorInfo_GetMaxSamplingInterval(Sensor_Info* sensor, int64_t *maxSamplingInterval)
628e41f4b71Sopenharmony_ci```
629e41f4b71Sopenharmony_ci**描述:**
630e41f4b71Sopenharmony_ci
631e41f4b71Sopenharmony_ci获取传感器的最大数据上报间隔时间。
632e41f4b71Sopenharmony_ci
633e41f4b71Sopenharmony_ci**起始版本:** 11
634e41f4b71Sopenharmony_ci
635e41f4b71Sopenharmony_ci**参数:**
636e41f4b71Sopenharmony_ci
637e41f4b71Sopenharmony_ci| 名称 | 描述 |
638e41f4b71Sopenharmony_ci| -------- | -------- |
639e41f4b71Sopenharmony_ci| sensor | 指向传感器信息的指针。  |
640e41f4b71Sopenharmony_ci| maxSamplingInterval | 指向最大数据报告间隔的指针,单位为纳秒。  |
641e41f4b71Sopenharmony_ci
642e41f4b71Sopenharmony_ci**返回:**
643e41f4b71Sopenharmony_ci
644e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
645e41f4b71Sopenharmony_ci
646e41f4b71Sopenharmony_ci
647e41f4b71Sopenharmony_ci### OH_SensorInfo_GetMinSamplingInterval()
648e41f4b71Sopenharmony_ci
649e41f4b71Sopenharmony_ci```
650e41f4b71Sopenharmony_ciint32_t OH_SensorInfo_GetMinSamplingInterval(Sensor_Info* sensor, int64_t *minSamplingInterval)
651e41f4b71Sopenharmony_ci```
652e41f4b71Sopenharmony_ci**描述:**
653e41f4b71Sopenharmony_ci
654e41f4b71Sopenharmony_ci获取传感器的最小数据上报间隔。
655e41f4b71Sopenharmony_ci
656e41f4b71Sopenharmony_ci**起始版本:** 11
657e41f4b71Sopenharmony_ci
658e41f4b71Sopenharmony_ci**参数:**
659e41f4b71Sopenharmony_ci
660e41f4b71Sopenharmony_ci| 名称 | 描述 |
661e41f4b71Sopenharmony_ci| -------- | -------- |
662e41f4b71Sopenharmony_ci| sensor | 指向传感器信息的指针。  |
663e41f4b71Sopenharmony_ci| minSamplingInterval | 指向最小数据报告间隔的指针,以纳秒为单位。  |
664e41f4b71Sopenharmony_ci
665e41f4b71Sopenharmony_ci**返回:**
666e41f4b71Sopenharmony_ci
667e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
668e41f4b71Sopenharmony_ci
669e41f4b71Sopenharmony_ci
670e41f4b71Sopenharmony_ci### OH_SensorInfo_GetName()
671e41f4b71Sopenharmony_ci
672e41f4b71Sopenharmony_ci```
673e41f4b71Sopenharmony_ciint32_t OH_SensorInfo_GetName (Sensor_Info* sensor, char *sensorName, uint32_t *length)
674e41f4b71Sopenharmony_ci```
675e41f4b71Sopenharmony_ci**描述:**
676e41f4b71Sopenharmony_ci
677e41f4b71Sopenharmony_ci获取传感器名称。
678e41f4b71Sopenharmony_ci
679e41f4b71Sopenharmony_ci**起始版本:** 11
680e41f4b71Sopenharmony_ci
681e41f4b71Sopenharmony_ci**参数:**
682e41f4b71Sopenharmony_ci
683e41f4b71Sopenharmony_ci| 名称 | 描述 |
684e41f4b71Sopenharmony_ci| -------- | -------- |
685e41f4b71Sopenharmony_ci| sensor | 指向传感器信息的指针。  |
686e41f4b71Sopenharmony_ci| sensorName | 指向传感器名称的指针。  |
687e41f4b71Sopenharmony_ci| length | 指向长度的指针,以字节为单位。  |
688e41f4b71Sopenharmony_ci
689e41f4b71Sopenharmony_ci**返回:**
690e41f4b71Sopenharmony_ci
691e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
692e41f4b71Sopenharmony_ci
693e41f4b71Sopenharmony_ci
694e41f4b71Sopenharmony_ci### OH_SensorInfo_GetResolution()
695e41f4b71Sopenharmony_ci
696e41f4b71Sopenharmony_ci```
697e41f4b71Sopenharmony_ciint32_t OH_SensorInfo_GetResolution(Sensor_Info* sensor, float *resolution)
698e41f4b71Sopenharmony_ci```
699e41f4b71Sopenharmony_ci**描述:**
700e41f4b71Sopenharmony_ci
701e41f4b71Sopenharmony_ci获取传感器分辨率。
702e41f4b71Sopenharmony_ci
703e41f4b71Sopenharmony_ci**起始版本:** 11
704e41f4b71Sopenharmony_ci
705e41f4b71Sopenharmony_ci**参数:**
706e41f4b71Sopenharmony_ci
707e41f4b71Sopenharmony_ci| 名称 | 描述 |
708e41f4b71Sopenharmony_ci| -------- | -------- |
709e41f4b71Sopenharmony_ci| sensor | 指向传感器信息的指针。  |
710e41f4b71Sopenharmony_ci| resolution | 指向传感器分辨率的指针。  |
711e41f4b71Sopenharmony_ci
712e41f4b71Sopenharmony_ci**返回:**
713e41f4b71Sopenharmony_ci
714e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
715e41f4b71Sopenharmony_ci
716e41f4b71Sopenharmony_ci
717e41f4b71Sopenharmony_ci### OH_SensorInfo_GetType()
718e41f4b71Sopenharmony_ci
719e41f4b71Sopenharmony_ci```
720e41f4b71Sopenharmony_ciint32_t OH_SensorInfo_GetType(Sensor_Info* sensor, Sensor_Type *sensorType)
721e41f4b71Sopenharmony_ci```
722e41f4b71Sopenharmony_ci**描述:**
723e41f4b71Sopenharmony_ci
724e41f4b71Sopenharmony_ci获取传感器类型。
725e41f4b71Sopenharmony_ci
726e41f4b71Sopenharmony_ci**起始版本:** 11
727e41f4b71Sopenharmony_ci
728e41f4b71Sopenharmony_ci**参数:**
729e41f4b71Sopenharmony_ci
730e41f4b71Sopenharmony_ci| 名称 | 描述 |
731e41f4b71Sopenharmony_ci| -------- | -------- |
732e41f4b71Sopenharmony_ci| sensor | 指向传感器信息的指针。  |
733e41f4b71Sopenharmony_ci| sensorType | 指向传感器类型的指针。  |
734e41f4b71Sopenharmony_ci
735e41f4b71Sopenharmony_ci**返回:**
736e41f4b71Sopenharmony_ci
737e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
738e41f4b71Sopenharmony_ci
739e41f4b71Sopenharmony_ci
740e41f4b71Sopenharmony_ci### OH_SensorInfo_GetVendorName()
741e41f4b71Sopenharmony_ci
742e41f4b71Sopenharmony_ci```
743e41f4b71Sopenharmony_ciint32_t OH_SensorInfo_GetVendorName(Sensor_Info* sensor, char *vendorName, uint32_t *length)
744e41f4b71Sopenharmony_ci```
745e41f4b71Sopenharmony_ci**描述:**
746e41f4b71Sopenharmony_ci
747e41f4b71Sopenharmony_ci获取传感器的厂商名称。
748e41f4b71Sopenharmony_ci
749e41f4b71Sopenharmony_ci**起始版本:** 11
750e41f4b71Sopenharmony_ci
751e41f4b71Sopenharmony_ci**参数:**
752e41f4b71Sopenharmony_ci
753e41f4b71Sopenharmony_ci| 名称 | 描述 |
754e41f4b71Sopenharmony_ci| -------- | -------- |
755e41f4b71Sopenharmony_ci| sensor | 指向传感器信息的指针。  |
756e41f4b71Sopenharmony_ci| vendorName | 指向供应商名称的指针。  |
757e41f4b71Sopenharmony_ci| length | 指向长度的指针,以字节为单位。  |
758e41f4b71Sopenharmony_ci
759e41f4b71Sopenharmony_ci**返回:**
760e41f4b71Sopenharmony_ci
761e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
762e41f4b71Sopenharmony_ci
763e41f4b71Sopenharmony_ci
764e41f4b71Sopenharmony_ci### OH_SensorSubscriber_GetCallback()
765e41f4b71Sopenharmony_ci
766e41f4b71Sopenharmony_ci```
767e41f4b71Sopenharmony_ciint32_t OH_SensorSubscriber_GetCallback(Sensor_Subscriber* subscriber, Sensor_EventCallback *callback)
768e41f4b71Sopenharmony_ci```
769e41f4b71Sopenharmony_ci**描述:**
770e41f4b71Sopenharmony_ci
771e41f4b71Sopenharmony_ci获取用于上报传感器数据的回调函数。
772e41f4b71Sopenharmony_ci
773e41f4b71Sopenharmony_ci**起始版本:** 11
774e41f4b71Sopenharmony_ci
775e41f4b71Sopenharmony_ci**参数:**
776e41f4b71Sopenharmony_ci
777e41f4b71Sopenharmony_ci| 名称 | 描述 |
778e41f4b71Sopenharmony_ci| -------- | -------- |
779e41f4b71Sopenharmony_ci| subscriber | 指向传感器订阅者信息的指针。  |
780e41f4b71Sopenharmony_ci| callback | 指向回调函数的指针。  |
781e41f4b71Sopenharmony_ci
782e41f4b71Sopenharmony_ci**返回:**
783e41f4b71Sopenharmony_ci
784e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
785e41f4b71Sopenharmony_ci
786e41f4b71Sopenharmony_ci
787e41f4b71Sopenharmony_ci### OH_SensorSubscriber_SetCallback()
788e41f4b71Sopenharmony_ci
789e41f4b71Sopenharmony_ci```
790e41f4b71Sopenharmony_ciint32_t OH_SensorSubscriber_SetCallback (Sensor_Subscriber* subscriber, const Sensor_EventCallback callback )
791e41f4b71Sopenharmony_ci```
792e41f4b71Sopenharmony_ci**描述:**
793e41f4b71Sopenharmony_ci
794e41f4b71Sopenharmony_ci设置一个回调函数来上报传感器数据。
795e41f4b71Sopenharmony_ci
796e41f4b71Sopenharmony_ci**起始版本:** 11
797e41f4b71Sopenharmony_ci
798e41f4b71Sopenharmony_ci**参数:**
799e41f4b71Sopenharmony_ci
800e41f4b71Sopenharmony_ci| 名称 | 描述 |
801e41f4b71Sopenharmony_ci| -------- | -------- |
802e41f4b71Sopenharmony_ci| subscriber | 指向传感器订阅者信息的指针。  |
803e41f4b71Sopenharmony_ci| callback | 设置回调函数。  |
804e41f4b71Sopenharmony_ci
805e41f4b71Sopenharmony_ci**返回:**
806e41f4b71Sopenharmony_ci
807e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
808e41f4b71Sopenharmony_ci
809e41f4b71Sopenharmony_ci
810e41f4b71Sopenharmony_ci### OH_SensorSubscriptionAttribute_GetSamplingInterval()
811e41f4b71Sopenharmony_ci
812e41f4b71Sopenharmony_ci```
813e41f4b71Sopenharmony_ciint32_t OH_SensorSubscriptionAttribute_GetSamplingInterval (Sensor_SubscriptionAttribute * attribute, int64_t * samplingInterval )
814e41f4b71Sopenharmony_ci```
815e41f4b71Sopenharmony_ci**描述:**
816e41f4b71Sopenharmony_ci
817e41f4b71Sopenharmony_ci获取传感器数据上报间隔。
818e41f4b71Sopenharmony_ci
819e41f4b71Sopenharmony_ci**起始版本:** 11
820e41f4b71Sopenharmony_ci
821e41f4b71Sopenharmony_ci**参数:**
822e41f4b71Sopenharmony_ci
823e41f4b71Sopenharmony_ci| 名称 | 描述 |
824e41f4b71Sopenharmony_ci| -------- | -------- |
825e41f4b71Sopenharmony_ci| attribute | 指向传感器订阅属性的指针。  |
826e41f4b71Sopenharmony_ci| samplingInterval | 指向数据报告间隔的指针,以纳秒为单位。  |
827e41f4b71Sopenharmony_ci
828e41f4b71Sopenharmony_ci**返回:**
829e41f4b71Sopenharmony_ci
830e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
831e41f4b71Sopenharmony_ci
832e41f4b71Sopenharmony_ci
833e41f4b71Sopenharmony_ci### OH_SensorSubscriptionAttribute_SetSamplingInterval()
834e41f4b71Sopenharmony_ci
835e41f4b71Sopenharmony_ci```
836e41f4b71Sopenharmony_ciint32_t OH_SensorSubscriptionAttribute_SetSamplingInterval(Sensor_SubscriptionAttribute* attribute, const int64_t samplingInterval)
837e41f4b71Sopenharmony_ci```
838e41f4b71Sopenharmony_ci**描述:**
839e41f4b71Sopenharmony_ci
840e41f4b71Sopenharmony_ci设置传感器数据上报间隔。
841e41f4b71Sopenharmony_ci
842e41f4b71Sopenharmony_ci**起始版本:** 11
843e41f4b71Sopenharmony_ci
844e41f4b71Sopenharmony_ci**参数:**
845e41f4b71Sopenharmony_ci
846e41f4b71Sopenharmony_ci| 名称 | 描述 |
847e41f4b71Sopenharmony_ci| -------- | -------- |
848e41f4b71Sopenharmony_ci| attribute | 指向传感器订阅属性的指针。  |
849e41f4b71Sopenharmony_ci| samplingInterval | 要设置的数据报告间隔,以纳秒为单位。  |
850e41f4b71Sopenharmony_ci
851e41f4b71Sopenharmony_ci**返回:**
852e41f4b71Sopenharmony_ci
853e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
854e41f4b71Sopenharmony_ci
855e41f4b71Sopenharmony_ci
856e41f4b71Sopenharmony_ci### OH_SensorSubscriptionId_GetType()
857e41f4b71Sopenharmony_ci
858e41f4b71Sopenharmony_ci```
859e41f4b71Sopenharmony_ciint32_t OH_SensorSubscriptionId_GetType(Sensor_SubscriptionId* id, Sensor_Type *sensorType)
860e41f4b71Sopenharmony_ci```
861e41f4b71Sopenharmony_ci**描述:**
862e41f4b71Sopenharmony_ci
863e41f4b71Sopenharmony_ci获取传感器类型。
864e41f4b71Sopenharmony_ci
865e41f4b71Sopenharmony_ci**起始版本:** 11
866e41f4b71Sopenharmony_ci
867e41f4b71Sopenharmony_ci**参数:**
868e41f4b71Sopenharmony_ci
869e41f4b71Sopenharmony_ci| 名称 | 描述 |
870e41f4b71Sopenharmony_ci| -------- | -------- |
871e41f4b71Sopenharmony_ci| id | 指向传感器订阅ID的指针。  |
872e41f4b71Sopenharmony_ci| sensorType | 指向传感器类型的指针。  |
873e41f4b71Sopenharmony_ci
874e41f4b71Sopenharmony_ci**返回:**
875e41f4b71Sopenharmony_ci
876e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
877e41f4b71Sopenharmony_ci
878e41f4b71Sopenharmony_ci
879e41f4b71Sopenharmony_ci### OH_SensorSubscriptionId_SetType()
880e41f4b71Sopenharmony_ci
881e41f4b71Sopenharmony_ci```
882e41f4b71Sopenharmony_ciint32_t OH_SensorSubscriptionId_SetType(Sensor_SubscriptionId* id, const Sensor_Type sensorType)
883e41f4b71Sopenharmony_ci```
884e41f4b71Sopenharmony_ci**描述:**
885e41f4b71Sopenharmony_ci
886e41f4b71Sopenharmony_ci设置传感器类型。
887e41f4b71Sopenharmony_ci
888e41f4b71Sopenharmony_ci**起始版本:** 11
889e41f4b71Sopenharmony_ci
890e41f4b71Sopenharmony_ci**参数:**
891e41f4b71Sopenharmony_ci
892e41f4b71Sopenharmony_ci| 名称 | 描述 |
893e41f4b71Sopenharmony_ci| -------- | -------- |
894e41f4b71Sopenharmony_ci| id | 指向传感器订阅ID的指针。  |
895e41f4b71Sopenharmony_ci| sensorType | 要设置的传感器类型。  |
896e41f4b71Sopenharmony_ci
897e41f4b71Sopenharmony_ci**返回:**
898e41f4b71Sopenharmony_ci
899e41f4b71Sopenharmony_ci如果操作成功返回**SENSOR_SUCCESS**;否则返回 [Sensor_Result](#sensor_result) 中定义的错误代码。
900