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 * 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; 49 * returns an error code defined in {@link Sensor_Result} otherwise. 50 * 51 * @since 11 52 */ 53 Sensor_Result OH_Sensor_GetInfos(Sensor_Info **infos, uint32_t *count); 54 55 /** 56 * @brief Subscribes to sensor data. The system will report sensor data to the subscriber at the specified frequency. 57 * If you need to apply for the ohos.permission.ACCELEROMETER permission when subscribing to the accelerometer sensor, 58 * you need to apply for the ohos.permission.GYROSCOPE permission when subscribing to the gyroscope sensor, and you need 59 * to apply for the ohos.permission.ACTIVITY_MOTION permission when subscribing to the pedometer related sensor. Apply 60 * for ohos.permission.READ_HEALTH_DATA permission when subscribing to health-related sensors, such as heart rate 61 * sensors, otherwise the subscription fails. Other sensors do not require permissions. 62 * 63 * @param id - Pointer to the sensor subscription ID. For details, see {@link Sensor_SubscriptionId}. 64 * @param attribute - Pointer to the subscription attribute, which is used to specify the data reporting frequency. 65 * For details, see {@link Sensor_SubscriptionAttribute}. 66 * @param subscriber - Pointer to the subscriber information, which is used to specify the callback function for 67 * reporting the sensor data. For details, see {@link Sensor_Subscriber}. 68 * @return Returns <b>SENSOR_SUCCESS</b> if the operation is successful; 69 * returns an error code defined in {@link Sensor_Result} otherwise. 70 * @permission ohos.permission.ACCELEROMETER or ohos.permission.GYROSCOPE or 71 * ohos.permission.ACTIVITY_MOTION or ohos.permission.READ_HEALTH_DATA 72 * @since 11 73 */ 74 Sensor_Result OH_Sensor_Subscribe(const Sensor_SubscriptionId *id, 75 const Sensor_SubscriptionAttribute *attribute, const Sensor_Subscriber *subscriber); 76 77 /** 78 * @brief Unsubscribes from sensor data. 79 * If you need to apply for the ohos.permission.ACCELEROMETER permission to unsubscribe from the accelerometer sensor, 80 * you need to request the ohos.permission.GYROSCOPE permission to unsubscribe from the gyroscope sensor, and you need 81 * to request the ohos.permission.ACTIVITY_MOTION permission to unsubscribe from the pedometer-related sensor. When you 82 * unsubscribe from health-related sensors, such as heart rate sensors, apply for ohos.permission.READ_HEALTH_DATA 83 * permissions, otherwise the subscription will fail. Other sensors do not require permissions. 84 * 85 * @param id - Pointer to the sensor subscription ID. For details, see {@link Sensor_SubscriptionId}. 86 * @param subscriber - Pointer to the subscriber information, which is used to specify the callback function for 87 * reporting the sensor data. For details, see {@link Sensor_Subscriber}. 88 * @return Returns <b>SENSOR_SUCCESS</b> if the operation is successful; 89 * returns an error code defined in {@link Sensor_Result} otherwise. 90 * @permission ohos.permission.ACCELEROMETER or ohos.permission.GYROSCOPE or 91 * ohos.permission.ACTIVITY_MOTION or ohos.permission.READ_HEALTH_DATA 92 * 93 * @since 11 94 */ 95 Sensor_Result OH_Sensor_Unsubscribe(const Sensor_SubscriptionId *id, const Sensor_Subscriber *subscriber); 96 #ifdef __cplusplus 97 } 98 #endif 99 /** @} */ 100 #endif // OH_SENSOR_H