1/* 2 * Copyright (c) 2021-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 HdiSensor 18 * @{ 19 * 20 * @brief Provides unified APIs for sensor services to access sensor drivers. 21 * 22 * A sensor service can obtain a sensor driver object or agent and then call APIs provided by this object or agent to 23 * access different types of sensor devices based on the sensor IDs, thereby obtaining sensor information, 24 * subscribing to or unsubscribing from sensor data, enabling or disabling a sensor, 25 * setting the sensor data reporting mode, and setting sensor options such as the accuracy and measurement range. 26 * 27 * @since 4.0 28 */ 29 30/** 31 * @file ISensorInterface.idl 32 * 33 * @brief Declares the APIs provided by the sensor module for obtaining sensor information, subscribing to or 34 * unsubscribing from sensor data, enabling or disabling a sensor, setting the sensor data reporting mode, 35 * and setting sensor options such as the accuracy and measurement range. 36 * 37 * @since 4.0 38 * @version 1.1 39 */ 40 41package ohos.hdi.sensor.v1_1; 42 43import ohos.hdi.sensor.v1_1.SensorTypes; 44import ohos.hdi.sensor.v1_1.ISensorCallback; 45 46/** 47 * @brief Defines the functions for performing basic operations on sensors. 48 * 49 * The operations include obtaining sensor information, subscribing to or unsubscribing from sensor data, 50 * enabling or disabling a sensor, setting the sensor data reporting mode, and setting sensor options such as 51 * the accuracy and measurement range. 52 */ 53interface ISensorInterface { 54 /** 55 * @brief Obtains information about all sensors in the system. 56 * 57 * @param info Indicates the vector of the information about all sensors in the system. 58 * The information about a sensor generally includes the sensor name, sensor vendor, firmware version, 59 * hardware version, sensor type ID, sensor ID, maximum measurement range, accuracy, and power. For details, 60 * see {@link HdfSensorInformation}. 61 * @return Returns <b>0</b> if the information is obtained; returns a negative value otherwise. 62 * 63 * @since 2.2 64 * @version 1.0 65 */ 66 GetAllSensorInfo([out] struct HdfSensorInformation[] info); 67 68 /** 69 * @brief Enables the sensor available in the sensor list based on the specified sensor ID. 70 * The subscriber can obtain the sensor data only after the sensor is enabled. 71 * 72 * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. 73 * @return Returns <b>0</b> if the sensor is successfully enabled; returns a negative value otherwise. 74 * 75 * @since 2.2 76 * @version 1.0 77 */ 78 Enable([in] int sensorId); 79 80 /** 81 * @brief Disables an enabled sensor. 82 * 83 * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. 84 * @return Returns <b>0</b> if the sensor is successfully disabled; returns a negative value otherwise. 85 * 86 * @since 2.2 87 * @version 1.0 88 */ 89 Disable([in] int sensorId); 90 91 /** 92 * @brief Sets the data sampling interval and data reporting interval for the specified sensor. 93 * 94 * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. 95 * @param samplingInterval Indicates the sensor data sampling interval to set, in nanoseconds. 96 * @param reportInterval Indicates the sensor data reporting interval, in nanoseconds. 97 * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise. 98 * 99 * @since 2.2 100 * @version 1.0 101 */ 102 SetBatch([in] int sensorId,[in] long samplingInterval, [in] long reportInterval); 103 104 /** 105 * @brief Sets the data reporting mode for the specified sensor. 106 * 107 * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. 108 * @param mode Indicates the data reporting mode to set. For details, see {@link SensorModeType}. 109 * @return Returns <b>0</b> if the sensor data reporting mode is successfully set; 110 * returns a negative value otherwise. 111 * 112 * @since 2.2 113 * @version 1.0 114 */ 115 SetMode([in] int sensorId, [in] int mode); 116 117 /** 118 * @brief Sets options for the specified sensor, including its measurement range and accuracy. 119 * 120 * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. 121 * @param option Indicates the options to set, such as the measurement range and accuracy. 122 * @return Returns <b>0</b> if the options are successfully set; returns a negative value otherwise. 123 * 124 * @since 2.2 125 * @version 1.0 126 */ 127 SetOption([in] int sensorId, [in] unsigned int option); 128 129 /** 130 * @brief Registers the callback for reporting sensor data to the subscriber. 131 * 132 * @param groupId Indicates the sensor group ID. 133 * The sensorId enumeration value range is 128-160, which means that the medical sensor service is subscribed. 134 * It only needs to be subscribed once successfully, and there is no need to subscribe repeatedly. 135 * The sensorId enumeration value range is not within 128-160, which means that the traditional sensor 136 * is subscribed, and the subscription is successful once. 137 * @param callbackObj Indicates the callback to register. For details, see {@link ISensorCallback}. 138 * @return Returns <b>0</b> if the callback is successfully registered; returns a negative value otherwise. 139 * 140 * @since 2.2 141 * @version 1.0 142 */ 143 Register([in] int groupId, [in] ISensorCallback callbackObj); 144 145 /** 146 * @brief Deregisters the callback for reporting sensor data. 147 * 148 * @param groupId Indicates the sensor group ID. 149 * The sensorId enumeration value range is 128-160, which means that the medical sensor service is subscribed. 150 * It only needs to cancel the subscription once successfully, and there is no need to 151 * cancel the subscription repeatedly. The sensorId enumeration value range is not within 128-160, 152 * which means that the traditional sensor is subscribed. You can cancel the subscription once successfully. 153 * @param callbackObj Indicates the callback to deregister. For details, see {@link ISensorCallback}. 154 * @return Returns <b>0</b> if the callback is successfully deregistered; returns a negative value otherwise. 155 * 156 * @since 2.2 157 * @version 1.0 158 */ 159 Unregister([in] int groupId, [in] ISensorCallback callbackObj); 160 161 /** 162 * @brief Obtain the sensor event data in the small system. 163 * 164 * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. 165 * @param event Indicates the vector of the sensor event data in the system. 166 * The sensor event data includes the sensor ID, sensor algorithm version, data generation time, 167 * data options (such as the measurement range and accuracy), data reporting mode, data address, and data length. 168 * For details, see {@link HdfSensorEvents}. 169 * @return Returns <b>0</b> if the event data is obtained; returns a negative value otherwise. 170 * 171 * @since 4.0 172 * @version 1.1 173 */ 174 ReadData([in] int sensorId, [out] struct HdfSensorEvents[] event); 175} 176