1/* 2 * Copyright (c) 2025 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 5.1 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 5.1 38 * @version 3.0 39 */ 40 41package ohos.hdi.sensor.v3_0; 42 43import ohos.hdi.sensor.v3_0.SensorTypes; 44import ohos.hdi.sensor.v3_0.ISensorCallback; 45import ohos.hdi.sensor.v3_0.ISensorPlugCallback; 46 47/** 48 * @brief Defines the functions for performing basic operations on sensors. 49 * 50 * The operations include obtaining sensor information, subscribing to or unsubscribing from sensor data, 51 * enabling or disabling a sensor, setting the sensor data reporting mode, and setting sensor options such as 52 * the accuracy and measurement range. 53 */ 54 55interface ISensorInterface { 56 /** 57 * @brief Obtains information about all sensors in the system. 58 * 59 * @param info Indicates the vector of the information about all sensors in the system. 60 * The information about a sensor generally includes the sensor name, sensor vendor, firmware version, 61 * hardware version, sensor type ID, sensor ID, maximum measurement range, accuracy, and power. For details, 62 * see {@link HdfSensorInformation}. 63 * @return Returns <b>0</b> if the information is obtained; returns a negative value otherwise. 64 * 65 * @since 2.2 66 * @version 1.0 67 */ 68 GetAllSensorInfo([out] struct HdfSensorInformation[] info); 69 70 /** 71 * @brief Obtains information about this device contains sensors in the system. 72 * 73 * @param info Indicates the vector of the information about all sensors in the system. 74 * The information about a sensor generally includes the sensor name, sensor vendor, firmware version, 75 * hardware version, sensor type ID, sensor ID, maximum measurement range, accuracy, and power. For details, 76 * see {@link HdfSensorInformation}. 77 * @return Returns <b>0</b> if the information is obtained; returns a negative value otherwise. 78 * 79 * @since 2.2 80 * @version 1.0 81 */ 82 GetDeviceSensorInfo([in] int deviceId, [out] struct HdfSensorInformation[] info); 83 84 /** 85 * @brief Enables the sensor available in the sensor list based on the specified sensor ID. 86 * The subscriber can obtain the sensor data only after the sensor is enabled. 87 * 88 * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. 89 * @param deviceId Indicates the device ID. For details, see {@link SensorTypeTag}. 90 * @return Returns <b>0</b> if the sensor is successfully enabled; returns a negative value otherwise. 91 * 92 * @since 2.2 93 * @version 1.0 94 */ 95 Enable([in] struct DeviceSensorInfo deviceSensorInfo); 96 97 /** 98 * @brief Disables an enabled sensor. 99 * 100 * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. 101 * @param deviceId Indicates the device ID. For details, see {@link SensorTypeTag}. 102 * @return Returns <b>0</b> if the sensor is successfully disabled; returns a negative value otherwise. 103 * 104 * @since 2.2 105 * @version 1.0 106 */ 107 Disable([in] struct DeviceSensorInfo deviceSensorInfo); 108 109 /** 110 * @brief Sets the data sampling interval and data reporting interval for the specified sensor. 111 * 112 * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. 113 * @param deviceId Indicates the device ID. For details, see {@link SensorTypeTag}. 114 * @param samplingInterval Indicates the sensor data sampling interval to set, in nanoseconds. 115 * @param reportInterval Indicates the sensor data reporting interval, in nanoseconds. 116 * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise. 117 * 118 * @since 2.2 119 * @version 1.0 120 */ 121 SetBatch([in] struct DeviceSensorInfo deviceSensorInfo, [in] long samplingInterval, [in] long reportInterval); 122 123 /** 124 * @brief Sets the data reporting mode for the specified sensor. 125 * 126 * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. 127 * @param deviceId Indicates the device ID. For details, see {@link SensorTypeTag}. 128 * @param mode Indicates the data reporting mode to set. For details, see {@link SensorModeType}. 129 * @return Returns <b>0</b> if the sensor data reporting mode is successfully set; 130 * returns a negative value otherwise. 131 * 132 * @since 2.2 133 * @version 1.0 134 */ 135 SetMode([in] struct DeviceSensorInfo deviceSensorInfo, [in] int mode); 136 137 /** 138 * @brief Sets options for the specified sensor, including its measurement range and accuracy. 139 * 140 * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. 141 * @param deviceId Indicates the device ID. For details, see {@link SensorTypeTag}. 142 * @param option Indicates the options to set, such as the measurement range and accuracy. 143 * @return Returns <b>0</b> if the options are successfully set; returns a negative value otherwise. 144 * 145 * @since 2.2 146 * @version 1.0 147 */ 148 SetOption([in] struct DeviceSensorInfo deviceSensorInfo, [in] unsigned int option); 149 150 /** 151 * @brief Registers the callback for reporting sensor data to the subscriber. 152 * 153 * The sensorId enumeration value range is 128-160, which means that the medical sensor service is subscribed. 154 * It only needs to be subscribed once successfully, and there is no need to subscribe repeatedly. 155 * The sensorId enumeration value range is not within 128-160, which means that the traditional sensor 156 * is subscribed, and the subscription is successful once. 157 * @param callbackObj Indicates the callback to register. For details, see {@link ISensorCallback}. 158 * @return Returns <b>0</b> if the callback is successfully registered; returns a negative value otherwise. 159 * 160 * @since 2.2 161 * @version 1.0 162 */ 163 Register([in] int groupId, [in] ISensorCallback callbackObj); 164 165 /** 166 * @brief Deregisters the callback for reporting sensor data. 167 * 168 * The sensorId enumeration value range is 128-160, which means that the medical sensor service is subscribed. 169 * It only needs to cancel the subscription once successfully, and there is no need to 170 * cancel the subscription repeatedly. The sensorId enumeration value range is not within 128-160, 171 * which means that the traditional sensor is subscribed. You can cancel the subscription once successfully. 172 * @param callbackObj Indicates the callback to deregister. For details, see {@link ISensorCallback}. 173 * @return Returns <b>0</b> if the callback is successfully deregistered; returns a negative value otherwise. 174 * 175 * @since 2.2 176 * @version 1.0 177 */ 178 Unregister([in] int groupId, [in] ISensorCallback callbackObj); 179 180 /** 181 * @brief Obtain the sensor event data in the small system. 182 * 183 * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. 184 * @param event Indicates the vector of the sensor event data in the system. 185 * The sensor event data includes the sensor ID, sensor algorithm version, data generation time, 186 * data options (such as the measurement range and accuracy), data reporting mode, data address, and data length. 187 * For details, see {@link HdfSensorEvents}. 188 * @return Returns <b>0</b> if the event data is obtained; returns a negative value otherwise. 189 * 190 * @since 2.2 191 * @version 1.0 192 */ 193 ReadData([in] struct DeviceSensorInfo deviceSensorInfo, [out] struct HdfSensorEvents[] event); 194 195 /** 196 * @brief Obtain the sensor event data in the small system. 197 * 198 * @param sensorId Indicates the sensor ID. For details, see {@link SensorTypeTag}. 199 * @param enabled Indicates if the value is enabled. 200 * @param rateLevel Indicates rateClass. 201 * @return Returns <b>0</b> if the event data is obtained; returns a negative value otherwise. 202 * 203 * @since 4.1 204 * @version 2.0 205 */ 206 SetSdcSensor([in] struct DeviceSensorInfo deviceSensorInfo, [in] boolean enabled, [in] int rateLevel); 207 /** 208 * @brief Obtain sensor information for SDC 209 * 210 * @param sdcSensorInfos Indicates the data of the SDC type. 211 * @return Returns <b>0</b> if the event data is obtained; returns a negative value otherwise. 212 * 213 * @since 4.1 214 * @version 2.0 215 */ 216 GetSdcSensorInfo([out] struct SdcSensorInfo[] sdcSensorInfo); 217 218 /** 219 * @brief Registers the callback for reporting sensor data to the subscriber. 220 * 221 * The sensorId enumeration value range is 128-160, which means that the medical sensor service is subscribed. 222 * It only needs to be subscribed once successfully, and there is no need to subscribe repeatedly. 223 * The sensorId enumeration value range is not within 128-160, which means that the traditional sensor 224 * is subscribed, and the subscription is successful once. 225 * @param callbackObj Indicates the callback to register. For details, see {@link ISensorCallback}. 226 * @return Returns <b>0</b> if the callback is successfully registered; returns a negative value otherwise. 227 * 228 * @since 5.1 229 * @version 1.0 230 */ 231 RegisterAsync([in] int groupId, [in] ISensorCallback callbackObj); 232 233 /** 234 * @brief Deregisters the callback for reporting sensor data. 235 * 236 * The sensorId enumeration value range is 128-160, which means that the medical sensor service is subscribed. 237 * It only needs to cancel the subscription once successfully, and there is no need to 238 * cancel the subscription repeatedly. The sensorId enumeration value range is not within 128-160, 239 * which means that the traditional sensor is subscribed. You can cancel the subscription once successfully. 240 * @param callbackObj Indicates the callback to deregister. For details, see {@link ISensorCallback}. 241 * @return Returns <b>0</b> if the callback is successfully deregistered; returns a negative value otherwise. 242 * 243 * @since 5.1 244 * @version 1.0 245 */ 246 UnregisterAsync([in] int groupId, [in] ISensorCallback callbackObj); 247 248 /** 249 * @brief Deregisters the callback for reporting sensor plug in/out state. 250 * 251 * The sensorId enumeration value range is 128-160, which means that the medical sensor service is subscribed. 252 * It only needs to cancel the subscription once successfully, and there is no need to 253 * cancel the subscription repeatedly. The sensorId enumeration value range is not within 128-160, 254 * which means that the traditional sensor is subscribed. You can cancel the subscription once successfully. 255 * @param callbackObj Indicates the callback to deregister. For details, see {@link ISensorCallback}. 256 * @return Returns <b>0</b> if the callback is successfully deregistered; returns a negative value otherwise. 257 * 258 * @since 5.1 259 * @version 1.0 260 */ 261 RegSensorPlugCallBack([in] ISensorPlugCallback callbackObj); 262 263 /** 264 * @brief Unregisters the callback for reporting sensor plug in/out state. 265 * 266 * The sensorId enumeration value range is 128-160, which means that the medical sensor service is subscribed. 267 * It only needs to cancel the subscription once successfully, and there is no need to 268 * cancel the subscription repeatedly. The sensorId enumeration value range is not within 128-160, 269 * which means that the traditional sensor is subscribed. You can cancel the subscription once successfully. 270 * @param callbackObj Indicates the callback to deregister. For details, see {@link ISensorCallback}. 271 * @return Returns <b>0</b> if the callback is successfully deregistered; returns a negative value otherwise. 272 * 273 * @since 5.1 274 * @version 1.0 275 */ 276 UnRegSensorPlugCallBack([in] ISensorPlugCallback callbackObj); 277} 278