1 /* 2 * Copyright (c) 2021 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 PanSensor 18 * @{ 19 * 20 * @brief Provides standard open APIs for you to use common capabilities of sensors. 21 * 22 * For example, you can call these APIs to obtain sensor information, 23 * subscribe to or unsubscribe from sensor data, enable or disable a sensor, 24 * and set the sensor data reporting mode. 25 * 26 * @since 5 27 */ 28 29 /** 30 * @file sensor_agent_type.h 31 * 32 * @brief Defines the basic data used by the sensor agent to manage sensors. 33 * 34 * @since 5 35 */ 36 37 #ifndef SENSOR_AGENT_TYPE_H 38 #define SENSOR_AGENT_TYPE_H 39 40 #include <stdint.h> 41 42 #ifdef __cplusplus 43 #if __cplusplus 44 extern "C" { 45 #endif 46 #endif 47 48 /** Maximum length of the sensor name */ 49 #ifndef NAME_MAX_LEN 50 #define NAME_MAX_LEN 128 51 #endif /* NAME_MAX_LEN */ 52 /** Size of sensor data */ 53 #ifndef SENSOR_USER_DATA_SIZE 54 #define SENSOR_USER_DATA_SIZE 104 55 #endif /* SENSOR_USER_DATA_SIZE */ 56 /** Maximum length of the sensor version */ 57 #ifndef VERSION_MAX_LEN 58 #define VERSION_MAX_LEN 16 59 #endif /* SENSOR_USER_DATA_SIZE */ 60 61 /** 62 * @brief Enumerates sensor types. 63 * 64 * @since 5 65 */ 66 typedef enum SensorTypeId { 67 SENSOR_TYPE_ID_NONE = 0, /**< None */ 68 SENSOR_TYPE_ID_ACCELEROMETER = 1, /**< Acceleration sensor */ 69 SENSOR_TYPE_ID_GYROSCOPE = 2, /**< Gyroscope sensor */ 70 SENSOR_TYPE_ID_AMBIENT_LIGHT = 5, /**< Ambient light sensor */ 71 SENSOR_TYPE_ID_MAGNETIC_FIELD = 6, /**< Magnetic field sensor */ 72 SENSOR_TYPE_ID_CAPACITIVE = 7, /**< Capacitive sensor */ 73 SENSOR_TYPE_ID_BAROMETER = 8, /**< Barometric pressure sensor */ 74 SENSOR_TYPE_ID_TEMPERATURE = 9, /**< Temperature sensor */ 75 SENSOR_TYPE_ID_HALL = 10, /**< Hall effect sensor */ 76 SENSOR_TYPE_ID_GESTURE = 11, /**< Gesture sensor */ 77 SENSOR_TYPE_ID_PROXIMITY = 12, /**< Proximity sensor */ 78 SENSOR_TYPE_ID_HUMIDITY = 13, /**< Humidity sensor */ 79 SENSOR_TYPE_ID_PHYSICAL_MAX = 0xFF, /**< Maximum type ID of a physical sensor */ 80 SENSOR_TYPE_ID_ORIENTATION = 256, /**< Orientation sensor */ 81 SENSOR_TYPE_ID_GRAVITY = 257, /**< Gravity sensor */ 82 SENSOR_TYPE_ID_LINEAR_ACCELERATION = 258, /**< Linear acceleration sensor */ 83 SENSOR_TYPE_ID_ROTATION_VECTOR = 259, /**< Rotation vector sensor */ 84 SENSOR_TYPE_ID_AMBIENT_TEMPERATURE = 260, /**< Ambient temperature sensor */ 85 SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED = 261, /**< Uncalibrated magnetic field sensor */ 86 SENSOR_TYPE_ID_GAME_ROTATION_VECTOR = 262, /**< Game rotation vector sensor */ 87 SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED = 263, /**< Uncalibrated gyroscope sensor */ 88 SENSOR_TYPE_ID_SIGNIFICANT_MOTION = 264, /**< Significant motion sensor */ 89 SENSOR_TYPE_ID_PEDOMETER_DETECTION = 265, /**< Pedometer detection sensor */ 90 SENSOR_TYPE_ID_PEDOMETER = 266, /**< Pedometer sensor */ 91 SENSOR_TYPE_ID_GEOMAGNETIC_ROTATION_VECTOR = 277, /**< Geomagnetic rotation vector sensor */ 92 SENSOR_TYPE_ID_HEART_RATE = 278, /**< Heart rate sensor */ 93 SENSOR_TYPE_ID_DEVICE_ORIENTATION = 279, /**< Device orientation sensor */ 94 SENSOR_TYPE_ID_WEAR_DETECTION = 280, /**< Wear detection sensor */ 95 SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED = 281, /**< Uncalibrated acceleration sensor */ 96 SENSOR_TYPE_ID_MAX = 30, /**< Maximum number of sensor type IDs*/ 97 } SensorTypeId; 98 99 /** 100 * @brief Defines sensor information. 101 * 102 * @since 5 103 */ 104 typedef struct SensorInfo { 105 char sensorName[NAME_MAX_LEN]; /**< Sensor name */ 106 char vendorName[NAME_MAX_LEN]; /**< Sensor vendor */ 107 char firmwareVersion[VERSION_MAX_LEN]; /**< Sensor firmware version */ 108 char hardwareVersion[VERSION_MAX_LEN]; /**< Sensor hardware version */ 109 int32_t sensorTypeId; /**< Sensor type ID */ 110 int32_t sensorId; /**< Sensor ID */ 111 float maxRange; /**< Maximum measurement range of the sensor */ 112 float precision; /**< Sensor accuracy */ 113 float power; /**< Sensor power */ 114 int64_t minSamplePeriod; /**< Minimum sample period allowed, in ns */ 115 int64_t maxSamplePeriod; /**< Maxmum sample period allowed, in ns */ 116 } SensorInfo; 117 118 /** 119 * @brief Defines the data reported by the sensor. 120 * 121 * @since 5 122 */ 123 typedef struct SensorEvent { 124 int32_t sensorTypeId; /**< Sensor type ID */ 125 int32_t version; /**< Sensor algorithm version */ 126 int64_t timestamp; /**< Time when sensor data was reported */ 127 uint32_t option; /**< Sensor data options, including the measurement range and accuracy */ 128 int32_t mode; /**< Sensor data reporting mode (described in {@link SensorMode}) */ 129 uint8_t *data; /**< Sensor data */ 130 uint32_t dataLen; /**< Sensor data length */ 131 } SensorEvent; 132 133 /** 134 * @brief Defines the callback for data reporting by the sensor agent. 135 * 136 * @since 5 137 */ 138 typedef void (*RecordSensorCallback)(SensorEvent *event); 139 140 /** 141 * @brief Defines a reserved field for the sensor data subscriber. 142 * 143 * @since 5 144 */ 145 typedef struct UserData { 146 char userData[SENSOR_USER_DATA_SIZE]; /**< Reserved for the sensor data subscriber */ 147 } UserData; 148 149 /** 150 * @brief Defines information about the sensor data subscriber. 151 * 152 * @since 5 153 */ 154 typedef struct SensorUser { 155 char name[NAME_MAX_LEN]; /**< Name of the sensor data subscriber */ 156 RecordSensorCallback callback; /**< Callback for reporting sensor data */ 157 UserData *userData; /**< Reserved field for the sensor data subscriber */ 158 } SensorUser; 159 160 /** 161 * @brief Enumerates data reporting modes of sensors. 162 * 163 * @since 5 164 */ 165 typedef enum SensorMode { 166 SENSOR_DEFAULT_MODE = 0, /**< Default data reporting mode */ 167 SENSOR_REALTIME_MODE = 1, /**< Real-time data reporting mode to report a group of data each time */ 168 SENSOR_ON_CHANGE = 2, /**< Real-time data reporting mode to report data upon status changes */ 169 SENSOR_ONE_SHOT = 3, /**< Real-time data reporting mode to report data only once */ 170 SENSOR_FIFO_MODE = 4, /**< FIFO-based data reporting mode to report data based on the <b>BatchCnt</b> setting */ 171 SENSOR_MODE_MAX2, /**< Maximum sensor data reporting mode */ 172 } SensorMode; 173 174 /** 175 * @brief Defines the accelerometer data structure. Measures the acceleration applied to 176 * the device on three physical axes (x, y, and z) in m/s2. 177 * 178 */ 179 typedef struct AccelData { 180 float x; 181 float y; 182 float z; 183 } AccelData; 184 185 /** 186 * @brief Defines the linear accelerometer data structure. Measures the linear acceleration applied to 187 * the device on three physical axes (x, y, and z) in m/s2. 188 */ 189 typedef struct LinearAccelData { 190 float x; 191 float y; 192 float z; 193 } LinearAccelData; 194 195 /** 196 * @brief Defines the gyroscope sensor data structure. Measures the rotational angular velocity of the 197 * device on three physical axes (x, y, and z) in rad/s. 198 */ 199 typedef struct GyroscopeData { 200 float x; 201 float y; 202 float z; 203 } GyroscopeData; 204 205 /** 206 * @brief Defines the gravity sensor data structure. Measures the acceleration of gravity applied 207 * to the device on three physical axes (x, y, and z) in m/s2. 208 */ 209 typedef struct GravityData { 210 float x; 211 float y; 212 float z; 213 } GravityData; 214 215 /** 216 * @brief Defines the uncalibrated accelerometer data structure. Measures the uncalibrated accelerometer applied to 217 * the device on three physical axes (x, y, and z) in m/s2. 218 */ 219 typedef struct AccelUncalibratedData { 220 float x; 221 float y; 222 float z; 223 float biasX; 224 float biasY; 225 float biasZ; 226 } AccelUncalibratedData; 227 228 /** 229 * @brief Defines the uncalibrated gyroscope sensor data structure. Measures the uncalibrated rotational angular velocity of the 230 * device on three physical axes (x, y, and z) in rad/s. 231 */ 232 typedef struct GyroUncalibratedData { 233 float x; 234 float y; 235 float z; 236 float biasX; 237 float biasY; 238 float biasZ; 239 } GyroUncalibratedData; 240 241 /** 242 * @brief Defines the significant Motion sensor data structure. Measures whether there is substantial motion in the device on 243 * the three physical axes (x, y, and z); a value of 1 indicates the presence of large motion; and a value of 0 indicates that 244 * there is no large movement. 245 */ 246 typedef struct SignificantMotionData { 247 float scalar; 248 } SignificantMotionData; 249 250 /** 251 * @brief Defines the pedometer detection sensor data structure. Detects the user's step counting action; if the value is 1, it 252 * means that the user has generated the action of counting walking; if the value is 0, it means that the user has not moved. 253 */ 254 typedef struct PedometerDetectData { 255 float scalar; 256 } PedometerDetectData; 257 258 /** 259 * @brief Defines the pedometer sensor data structure. Counts the number of steps taken by the user. 260 */ 261 typedef struct PedometerData { 262 float steps; 263 } PedometerData; 264 265 /** 266 * @brief Defines the ambient temperature sensor data structure. Measures ambient temperature in degrees Celsius (°C) 267 */ 268 typedef struct AmbientTemperatureData { 269 float temperature; 270 } AmbientTemperatureData; 271 272 /** 273 * @brief Define the humidity sensor data structure. Measures the relative humidity of the environment, 274 * expressed as a percentage (%). 275 */ 276 typedef struct HumidityData { 277 float humidity; 278 } HumidityData; 279 280 /** 281 * @brief Defines the magnetic field sensor data structure. Measure the ambient geomagnetic field in three 282 * physical axes (x, y, z) in μT. 283 */ 284 typedef struct MagneticFieldData { 285 float x; 286 float y; 287 float z; 288 } MagneticFieldData; 289 290 /** 291 * @brief Defines the uncalibrated magnetic field sensor data structure. Measure the uncalibrated ambient geomagnetic field in three 292 * physical axes (x, y, z) in μT. 293 */ 294 typedef struct MagneticFieldUncalibratedData { 295 float x; 296 float y; 297 float z; 298 float biasX; 299 float biasY; 300 float biasZ; 301 } MagneticFieldUncalibratedData; 302 303 /** 304 * @brief Defines the barometer sensor data structure. Measures ambient air pressure in : hPa or mbar. 305 */ 306 typedef struct BarometerData { 307 float pressure; 308 } BarometerData; 309 310 /** 311 * @brief Defines the device orientation sensor data structure. Measure the direction of rotation of the device in rad. 312 */ 313 typedef struct DeviceOrientationData { 314 float scalar; 315 } DeviceOrientationData; 316 317 /** 318 * @brief Defines the orientation sensor data structure. Measures the angle value of the rotation of the device 319 * around all three physical axes (z, x, y), in rad. 320 */ 321 typedef struct OrientationData { 322 float alpha; /**< The device rotates at an angle around the Z axis */ 323 float beta; /**< The device rotates at an angle around the X axis */ 324 float gamma; /**< The device rotates at an angle around the Y axis */ 325 } OrientationData; 326 327 /** 328 * @brief Defines the rotation vector sensor data structure. Measuring device game rotation vector, composite sensor: 329 * synthesized by acceleration sensor, gyroscope sensor. 330 */ 331 typedef struct RotationVectorData { 332 float x; 333 float y; 334 float z; 335 float w; 336 } RotationVectorData; 337 338 /** 339 * @brief Defines the game rotation vector sensor data structure. Measuring device game rotation vector, composite sensor: 340 * synthesized by acceleration sensor, gyroscope sensor. 341 */ 342 typedef struct GameRotationVectorData { 343 float x; 344 float y; 345 float z; 346 float w; 347 } GameRotationVectorData; 348 349 /** 350 * @brief Defines the geomagnetic rotation vector sensor data structure. Measuring device geomagnetic rotation vector, composite 351 * sensor: synthesized by acceleration sensor and magnetic field sensor. 352 */ 353 typedef struct GeomagneticRotaVectorData { 354 float x; 355 float y; 356 float z; 357 float w; 358 } GeomagneticRotaVectorData; 359 360 /** 361 * @brief Defines the proximity light sensor data structure. Measures the proximity or distance of visible objects relative to 362 * the device display, where 0 indicates proximity and 1 indicates distance. 363 */ 364 typedef struct ProximityData { 365 float distance; 366 } ProximityData; 367 368 /** 369 * @brief Defines the ambient light sensor data structure. Measures the intensity of light around the device in lux. 370 */ 371 typedef struct AmbientLightData { 372 float intensity; 373 } AmbientLightData; 374 375 /** 376 * @brief Defines the hall sensor data structure. Measure whether there is magnetic attraction around the device, 377 * 0 means no magnet attraction, and 1 means there is magnet attraction. 378 */ 379 typedef struct HallData { 380 float status; 381 } HallData; 382 383 /** 384 * @brief Define the heart rate sensor data structure. Measures the user's heart rate, in bpm. 385 */ 386 typedef struct HeartRateData { 387 float heartRate; 388 } HeartRateData; 389 390 /** 391 * @brief Defines the wear detection sensor data structure. To detect whether the user is wearing it, 392 * 0 means not wearing it, while 1 means wearing it 393 */ 394 typedef struct WearDetectionData { 395 float value; 396 } WearDetectionData; 397 398 #ifdef __cplusplus 399 #if __cplusplus 400 } 401 #endif 402 #endif 403 #endif /* SENSOR_AGENT_TYPE_H */ 404 /**< @} */