1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup Sensor
18  * @{
19  *
20  * @brief Provides APIs to use common sensor features. For example, you can call the APIs to obtain sensor information
21  * and subscribe to or unsubscribe from sensor data.
22  * @since 11
23  */
24 /**
25  * @file oh_sensor.h
26  * @kit SensorServiceKit
27  * @brief Declares the APIs for operating sensors, including obtaining sensor information and subscribing to or
28  * unsubscribing from sensor data.
29  * @library libohsensor.so
30  * @syscap SystemCapability.Sensors.Sensor
31  * @since 11
32  */
33 
34 #ifndef OH_SENSOR_H
35 #define OH_SENSOR_H
36 
37 #include "oh_sensor_type.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 /**
43  * @brief Obtains information about all sensors on the device.
44  *
45  * @param infos - Double pointer to the information about all sensors on the device.
46  * For details, see {@link Sensor_Info}.
47  * @param count - Pointer to the number of sensors on the device.
48  * @return Returns <b>SENSOR_SUCCESS</b> if the operation is successful; returns the following error code otherwise.
49  * {@link SENSOR_PARAMETER_ERROR} Parameter check failed. For example, the parameter is invalid,
50  * or the parameter type passed in is incorrect.\n
51  * {@link SENSOR_SERVICE_EXCEPTION} The sensor service is abnormal.\n
52  *
53  * @since 11
54  */
55 Sensor_Result OH_Sensor_GetInfos(Sensor_Info **infos, uint32_t *count);
56 
57 /**
58  * @brief Subscribes to sensor data. The system will report sensor data to the subscriber at the specified frequency.
59  * If you need to apply for the ohos.permission.ACCELEROMETER permission when subscribing to the accelerometer sensor,
60  * you need to apply for the ohos.permission.GYROSCOPE permission when subscribing to the gyroscope sensor, and you need
61  * to apply for the ohos.permission.ACTIVITY_MOTION permission when subscribing to the pedometer related sensor. Apply
62  * for ohos.permission.READ_HEALTH_DATA permission when subscribing to health-related sensors, such as heart rate
63  * sensors, otherwise the subscription fails. Other sensors do not require permissions.
64  *
65  * @param id - Pointer to the sensor subscription ID. For details, see {@link Sensor_SubscriptionId}.
66  * @param attribute - Pointer to the subscription attribute, which is used to specify the data reporting frequency.
67  * For details, see {@link Sensor_SubscriptionAttribute}.
68  * @param subscriber - Pointer to the subscriber information, which is used to specify the callback function for
69  * reporting the sensor data. For details, see {@link Sensor_Subscriber}.
70  * @return Returns <b>SENSOR_SUCCESS</b> if the operation is successful; returns the following error code otherwise.
71  * {@link SENSOR_PERMISSION_DENIED} Permission verification failed.\n
72  * {@link SENSOR_PARAMETER_ERROR} Parameter check failed. For example, the parameter is invalid,
73  * or the parameter type passed in is incorrect.\n
74  * {@link SENSOR_SERVICE_EXCEPTION} The sensor service is abnormal.\n
75  * @permission ohos.permission.ACCELEROMETER or ohos.permission.GYROSCOPE or
76  *             ohos.permission.ACTIVITY_MOTION or ohos.permission.READ_HEALTH_DATA
77  * @since 11
78  */
79 Sensor_Result OH_Sensor_Subscribe(const Sensor_SubscriptionId *id,
80     const Sensor_SubscriptionAttribute *attribute, const Sensor_Subscriber *subscriber);
81 
82 /**
83  * @brief Unsubscribes from sensor data.
84  * If you need to apply for the ohos.permission.ACCELEROMETER permission to unsubscribe from the accelerometer sensor,
85  * you need to request the ohos.permission.GYROSCOPE permission to unsubscribe from the gyroscope sensor, and you need
86  * to request the ohos.permission.ACTIVITY_MOTION permission to unsubscribe from the pedometer-related sensor. When you
87  * unsubscribe from health-related sensors, such as heart rate sensors, apply for ohos.permission.READ_HEALTH_DATA
88  * permissions, otherwise the subscription will fail. Other sensors do not require permissions.
89  *
90  * @param id - Pointer to the sensor subscription ID. For details, see {@link Sensor_SubscriptionId}.
91  * @param subscriber - Pointer to the subscriber information, which is used to specify the callback function for
92  * reporting the sensor data. For details, see {@link Sensor_Subscriber}.
93  * @return Returns <b>SENSOR_SUCCESS</b> if the operation is successful; returns the following error code otherwise.
94  * {@link SENSOR_PERMISSION_DENIED} Permission verification failed.\n
95  * {@link SENSOR_PARAMETER_ERROR} Parameter check failed. For example, the parameter is invalid,
96  * or the parameter type passed in is incorrect.\n
97  * {@link SENSOR_SERVICE_EXCEPTION} The sensor service is abnormal.\n
98  * @permission ohos.permission.ACCELEROMETER or ohos.permission.GYROSCOPE or
99  *             ohos.permission.ACTIVITY_MOTION or ohos.permission.READ_HEALTH_DATA
100  *
101  * @since 11
102  */
103 Sensor_Result OH_Sensor_Unsubscribe(const Sensor_SubscriptionId *id, const Sensor_Subscriber *subscriber);
104 #ifdef __cplusplus
105 }
106 #endif
107 /** @} */
108 #endif // OH_SENSOR_H