17777dab0Sopenharmony_ci/*
27777dab0Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
37777dab0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
47777dab0Sopenharmony_ci * you may not use this file except in compliance with the License.
57777dab0Sopenharmony_ci * You may obtain a copy of the License at
67777dab0Sopenharmony_ci *
77777dab0Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
87777dab0Sopenharmony_ci *
97777dab0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
107777dab0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
117777dab0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127777dab0Sopenharmony_ci * See the License for the specific language governing permissions and
137777dab0Sopenharmony_ci * limitations under the License.
147777dab0Sopenharmony_ci */
157777dab0Sopenharmony_ci
167777dab0Sopenharmony_ci/**
177777dab0Sopenharmony_ci * @addtogroup Sensor
187777dab0Sopenharmony_ci * @{
197777dab0Sopenharmony_ci *
207777dab0Sopenharmony_ci * @brief Provides APIs to use common sensor features. For example, you can call the APIs to obtain sensor information
217777dab0Sopenharmony_ci * and subscribe to or unsubscribe from sensor data.
227777dab0Sopenharmony_ci * @since 11
237777dab0Sopenharmony_ci */
247777dab0Sopenharmony_ci/**
257777dab0Sopenharmony_ci * @file oh_sensor.h
267777dab0Sopenharmony_ci * @kit SensorServiceKit
277777dab0Sopenharmony_ci * @brief Declares the APIs for operating sensors, including obtaining sensor information and subscribing to or
287777dab0Sopenharmony_ci * unsubscribing from sensor data.
297777dab0Sopenharmony_ci * @library libohsensor.so
307777dab0Sopenharmony_ci * @syscap SystemCapability.Sensors.Sensor
317777dab0Sopenharmony_ci * @since 11
327777dab0Sopenharmony_ci */
337777dab0Sopenharmony_ci
347777dab0Sopenharmony_ci#ifndef OH_SENSOR_H
357777dab0Sopenharmony_ci#define OH_SENSOR_H
367777dab0Sopenharmony_ci
377777dab0Sopenharmony_ci#include "oh_sensor_type.h"
387777dab0Sopenharmony_ci
397777dab0Sopenharmony_ci#ifdef __cplusplus
407777dab0Sopenharmony_ciextern "C" {
417777dab0Sopenharmony_ci#endif
427777dab0Sopenharmony_ci/**
437777dab0Sopenharmony_ci * @brief Obtains information about all sensors on the device.
447777dab0Sopenharmony_ci *
457777dab0Sopenharmony_ci * @param infos - Double pointer to the information about all sensors on the device.
467777dab0Sopenharmony_ci * For details, see {@link Sensor_Info}.
477777dab0Sopenharmony_ci * @param count - Pointer to the number of sensors on the device.
487777dab0Sopenharmony_ci * @return Returns <b>SENSOR_SUCCESS</b> if the operation is successful; returns the following error code otherwise.
497777dab0Sopenharmony_ci * {@link SENSOR_PARAMETER_ERROR} Parameter check failed. For example, the parameter is invalid,
507777dab0Sopenharmony_ci * or the parameter type passed in is incorrect.\n
517777dab0Sopenharmony_ci * {@link SENSOR_SERVICE_EXCEPTION} The sensor service is abnormal.\n
527777dab0Sopenharmony_ci *
537777dab0Sopenharmony_ci * @since 11
547777dab0Sopenharmony_ci */
557777dab0Sopenharmony_ciSensor_Result OH_Sensor_GetInfos(Sensor_Info **infos, uint32_t *count);
567777dab0Sopenharmony_ci
577777dab0Sopenharmony_ci/**
587777dab0Sopenharmony_ci * @brief Subscribes to sensor data. The system will report sensor data to the subscriber at the specified frequency.
597777dab0Sopenharmony_ci * If you need to apply for the ohos.permission.ACCELEROMETER permission when subscribing to the accelerometer sensor,
607777dab0Sopenharmony_ci * you need to apply for the ohos.permission.GYROSCOPE permission when subscribing to the gyroscope sensor, and you need
617777dab0Sopenharmony_ci * to apply for the ohos.permission.ACTIVITY_MOTION permission when subscribing to the pedometer related sensor. Apply
627777dab0Sopenharmony_ci * for ohos.permission.READ_HEALTH_DATA permission when subscribing to health-related sensors, such as heart rate
637777dab0Sopenharmony_ci * sensors, otherwise the subscription fails. Other sensors do not require permissions.
647777dab0Sopenharmony_ci *
657777dab0Sopenharmony_ci * @param id - Pointer to the sensor subscription ID. For details, see {@link Sensor_SubscriptionId}.
667777dab0Sopenharmony_ci * @param attribute - Pointer to the subscription attribute, which is used to specify the data reporting frequency.
677777dab0Sopenharmony_ci * For details, see {@link Sensor_SubscriptionAttribute}.
687777dab0Sopenharmony_ci * @param subscriber - Pointer to the subscriber information, which is used to specify the callback function for
697777dab0Sopenharmony_ci * reporting the sensor data. For details, see {@link Sensor_Subscriber}.
707777dab0Sopenharmony_ci * @return Returns <b>SENSOR_SUCCESS</b> if the operation is successful; returns the following error code otherwise.
717777dab0Sopenharmony_ci * {@link SENSOR_PERMISSION_DENIED} Permission verification failed.\n
727777dab0Sopenharmony_ci * {@link SENSOR_PARAMETER_ERROR} Parameter check failed. For example, the parameter is invalid,
737777dab0Sopenharmony_ci * or the parameter type passed in is incorrect.\n
747777dab0Sopenharmony_ci * {@link SENSOR_SERVICE_EXCEPTION} The sensor service is abnormal.\n
757777dab0Sopenharmony_ci * @permission ohos.permission.ACCELEROMETER or ohos.permission.GYROSCOPE or
767777dab0Sopenharmony_ci *             ohos.permission.ACTIVITY_MOTION or ohos.permission.READ_HEALTH_DATA
777777dab0Sopenharmony_ci * @since 11
787777dab0Sopenharmony_ci */
797777dab0Sopenharmony_ciSensor_Result OH_Sensor_Subscribe(const Sensor_SubscriptionId *id,
807777dab0Sopenharmony_ci    const Sensor_SubscriptionAttribute *attribute, const Sensor_Subscriber *subscriber);
817777dab0Sopenharmony_ci
827777dab0Sopenharmony_ci/**
837777dab0Sopenharmony_ci * @brief Unsubscribes from sensor data.
847777dab0Sopenharmony_ci * If you need to apply for the ohos.permission.ACCELEROMETER permission to unsubscribe from the accelerometer sensor,
857777dab0Sopenharmony_ci * you need to request the ohos.permission.GYROSCOPE permission to unsubscribe from the gyroscope sensor, and you need
867777dab0Sopenharmony_ci * to request the ohos.permission.ACTIVITY_MOTION permission to unsubscribe from the pedometer-related sensor. When you
877777dab0Sopenharmony_ci * unsubscribe from health-related sensors, such as heart rate sensors, apply for ohos.permission.READ_HEALTH_DATA
887777dab0Sopenharmony_ci * permissions, otherwise the subscription will fail. Other sensors do not require permissions.
897777dab0Sopenharmony_ci *
907777dab0Sopenharmony_ci * @param id - Pointer to the sensor subscription ID. For details, see {@link Sensor_SubscriptionId}.
917777dab0Sopenharmony_ci * @param subscriber - Pointer to the subscriber information, which is used to specify the callback function for
927777dab0Sopenharmony_ci * reporting the sensor data. For details, see {@link Sensor_Subscriber}.
937777dab0Sopenharmony_ci * @return Returns <b>SENSOR_SUCCESS</b> if the operation is successful; returns the following error code otherwise.
947777dab0Sopenharmony_ci * {@link SENSOR_PERMISSION_DENIED} Permission verification failed.\n
957777dab0Sopenharmony_ci * {@link SENSOR_PARAMETER_ERROR} Parameter check failed. For example, the parameter is invalid,
967777dab0Sopenharmony_ci * or the parameter type passed in is incorrect.\n
977777dab0Sopenharmony_ci * {@link SENSOR_SERVICE_EXCEPTION} The sensor service is abnormal.\n
987777dab0Sopenharmony_ci * @permission ohos.permission.ACCELEROMETER or ohos.permission.GYROSCOPE or
997777dab0Sopenharmony_ci *             ohos.permission.ACTIVITY_MOTION or ohos.permission.READ_HEALTH_DATA
1007777dab0Sopenharmony_ci *
1017777dab0Sopenharmony_ci * @since 11
1027777dab0Sopenharmony_ci */
1037777dab0Sopenharmony_ciSensor_Result OH_Sensor_Unsubscribe(const Sensor_SubscriptionId *id, const Sensor_Subscriber *subscriber);
1047777dab0Sopenharmony_ci#ifdef __cplusplus
1057777dab0Sopenharmony_ci}
1067777dab0Sopenharmony_ci#endif
1077777dab0Sopenharmony_ci/** @} */
1087777dab0Sopenharmony_ci#endif // OH_SENSOR_H