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 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_COLOR = 14, /**< Color sensor */ 80 SENSOR_TYPE_ID_SAR = 15, /**< Sar sensor */ 81 SENSOR_TYPE_ID_AMBIENT_LIGHT1 = 16, /**< Secondary ambient light sensor */ 82 SENSOR_TYPE_ID_HALL_EXT = 17, /**< Extended hall effect sensor */ 83 SENSOR_TYPE_ID_PROXIMITY1 = 18, /**< Secondary proximity sensor */ 84 SENSOR_TYPE_ID_PHYSICAL_MAX = 0xFF, /**< Maximum type ID of a physical sensor */ 85 SENSOR_TYPE_ID_ORIENTATION = 256, /**< Orientation sensor */ 86 SENSOR_TYPE_ID_GRAVITY = 257, /**< Gravity sensor */ 87 SENSOR_TYPE_ID_LINEAR_ACCELERATION = 258, /**< Linear acceleration sensor */ 88 SENSOR_TYPE_ID_ROTATION_VECTOR = 259, /**< Rotation vector sensor */ 89 SENSOR_TYPE_ID_AMBIENT_TEMPERATURE = 260, /**< Ambient temperature sensor */ 90 SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED = 261, /**< Uncalibrated magnetic field sensor */ 91 SENSOR_TYPE_ID_GAME_ROTATION_VECTOR = 262, /**< Game rotation vector sensor */ 92 SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED = 263, /**< Uncalibrated gyroscope sensor */ 93 SENSOR_TYPE_ID_SIGNIFICANT_MOTION = 264, /**< Significant motion sensor */ 94 SENSOR_TYPE_ID_PEDOMETER_DETECTION = 265, /**< Pedometer detection sensor */ 95 SENSOR_TYPE_ID_PEDOMETER = 266, /**< Pedometer sensor */ 96 SENSOR_TYPE_ID_POSTURE = 267, /**< Posture sensor */ 97 SENSOR_TYPE_ID_HEADPOSTURE = 268, /**< Head posture sensor */ 98 SENSOR_TYPE_ID_DROP_DETECTION = 269, /**< Drop detection sensor */ 99 SENSOR_TYPE_ID_GEOMAGNETIC_ROTATION_VECTOR = 277, /**< Geomagnetic rotation vector sensor */ 100 SENSOR_TYPE_ID_HEART_RATE = 278, /**< Heart rate sensor */ 101 SENSOR_TYPE_ID_DEVICE_ORIENTATION = 279, /**< Device orientation sensor */ 102 SENSOR_TYPE_ID_WEAR_DETECTION = 280, /**< Wear detection sensor */ 103 SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED = 281, /**< Uncalibrated acceleration sensor */ 104 SENSOR_TYPE_ID_RPC = 282, /**< Radio power control sensor */ 105 SENSOR_TYPE_ID_MAX = 30, /**< Maximum number of sensor type IDs*/ 106 } SensorTypeId; 107 108 /** 109 * @brief Defines sensor information. 110 * 111 * @since 5 112 */ 113 typedef struct SensorInfo { 114 char sensorName[NAME_MAX_LEN]; /**< Sensor name */ 115 char vendorName[NAME_MAX_LEN]; /**< Sensor vendor */ 116 char firmwareVersion[VERSION_MAX_LEN]; /**< Sensor firmware version */ 117 char hardwareVersion[VERSION_MAX_LEN]; /**< Sensor hardware version */ 118 int32_t sensorTypeId = -1; /**< Sensor type ID */ 119 int32_t sensorId = -1; /**< Sensor ID */ 120 float maxRange = 0.0; /**< Maximum measurement range of the sensor */ 121 float precision = 0.0; /**< Sensor accuracy */ 122 float power = 0.0; /**< Sensor power */ 123 int64_t minSamplePeriod = -1; /**< Minimum sample period allowed, in ns */ 124 int64_t maxSamplePeriod = -1; /**< Maximum sample period allowed, in ns */ 125 } SensorInfo; 126 127 /** 128 * @brief Enumerates the accuracy levels of data reported by a sensor. 129 * 130 * @since 11 131 */ 132 typedef enum SensorAccuracy { 133 /**< The sensor data is unreliable. 134 * It is possible that the sensor does not contact with the device to measure.*/ 135 ACCURACY_UNRELIABLE = 0, 136 /**< The sensor data is at a low accuracy level. 137 * You are required to calibrate the data based on the environment before using it. */ 138 ACCURACY_LOW = 1, 139 /**< The sensor data is at a medium accuracy level. 140 * You are advised to calibrate the data based on the environment before using it. */ 141 ACCURACY_MEDIUM = 2, 142 /**< The sensor data is at a high accuracy level. 143 * The data can be used directly. */ 144 ACCURACY_HIGH = 3, 145 } SensorAccuracy; 146 147 /** 148 * @brief Defines the data reported by the sensor. 149 * 150 * @since 5 151 */ 152 typedef struct SensorEvent { 153 int32_t sensorTypeId = -1; /**< Sensor type ID */ 154 int32_t version = -1; /**< Sensor algorithm version */ 155 int64_t timestamp = -1; /**< Time when sensor data was reported */ 156 int32_t option = -1; /**< Sensor data options, including the measurement range and accuracy */ 157 int32_t mode = -1; /**< Sensor data reporting mode (described in {@link SensorMode}) */ 158 uint8_t *data = nullptr; /**< Sensor data */ 159 uint32_t dataLen = 0; /**< Sensor data length */ 160 } SensorEvent; 161 162 /** 163 * @brief Defines the callback for data reporting by the sensor agent. 164 * 165 * @since 5 166 */ 167 typedef void (*RecordSensorCallback)(SensorEvent *event); 168 169 /** 170 * @brief Defines a reserved field for the sensor data subscriber. 171 * 172 * @since 5 173 */ 174 typedef struct UserData { 175 char userData[SENSOR_USER_DATA_SIZE]; /**< Reserved for the sensor data subscriber */ 176 } UserData; 177 178 /** 179 * @brief Defines information about the sensor data subscriber. 180 * 181 * @since 5 182 */ 183 typedef struct SensorUser { 184 char name[NAME_MAX_LEN]; /**< Name of the sensor data subscriber */ 185 RecordSensorCallback callback; /**< Callback for reporting sensor data */ 186 UserData *userData = nullptr; /**< Reserved field for the sensor data subscriber */ 187 } SensorUser; 188 189 /** 190 * @brief Enumerates data reporting modes of sensors. 191 * 192 * @since 5 193 */ 194 typedef enum SensorMode { 195 SENSOR_DEFAULT_MODE = 0, /**< Default data reporting mode */ 196 SENSOR_REALTIME_MODE = 1, /**< Real-time data reporting mode to report a group of data each time */ 197 SENSOR_ON_CHANGE = 2, /**< Real-time data reporting mode to report data upon status changes */ 198 SENSOR_ONE_SHOT = 3, /**< Real-time data reporting mode to report data only once */ 199 SENSOR_FIFO_MODE = 4, /**< FIFO-based data reporting mode to report data based on the <b>BatchCnt</b> setting */ 200 SENSOR_MODE_MAX2, /**< Maximum sensor data reporting mode */ 201 } SensorMode; 202 203 /** 204 * @brief Defines the struct of the data reported by the acceleration sensor. 205 * This sensor measures the acceleration applied to the device on three physical axes (x, y, and z), in m/s2. 206 * 207 */ 208 typedef struct AccelData { 209 float x = 0.0; 210 float y = 0.0; 211 float z = 0.0; 212 } AccelData; 213 214 /** 215 * @brief Defines the struct of the data reported by the linear acceleration sensor. 216 * This sensor measures the linear acceleration applied to the device on three physical axes (x, y, and z), in m/s2. 217 */ 218 typedef struct LinearAccelData { 219 float x = 0.0; 220 float y = 0.0; 221 float z = 0.0; 222 } LinearAccelData; 223 224 /** 225 * @brief Defines the struct of the data reported by the gyroscope sensor. 226 * This sensor measures the angular velocity of the device on three physical axes (x, y, and z), in rad/s. 227 */ 228 typedef struct GyroscopeData { 229 float x = 0.0; 230 float y = 0.0; 231 float z = 0.0; 232 } GyroscopeData; 233 234 /** 235 * @brief Defines the struct of the data reported by the gravity sensor. 236 * This sensor measures the acceleration of gravity applied to the device on three physical axes (x, y, and z), in m/s2. 237 */ 238 typedef struct GravityData { 239 float x = 0.0; 240 float y = 0.0; 241 float z = 0.0; 242 } GravityData; 243 244 /** 245 * @brief Defines the struct of the data reported by the uncalibrated acceleration sensor. 246 * This sensor measures the uncalibrated acceleration applied to the device on three physical axes (x, y, and z), 247 * in m/s2. 248 */ 249 typedef struct AccelUncalibratedData { 250 float x = 0.0; 251 float y = 0.0; 252 float z = 0.0; 253 float biasX = 0.0; 254 float biasY = 0.0; 255 float biasZ = 0.0; 256 } AccelUncalibratedData; 257 258 /** 259 * @brief Defines the struct of the data reported by the uncalibrated gyroscope sensor. 260 * This sensor measures the uncalibrated angular velocity of the device on three physical axes (x, y, and z), in rad/s. 261 */ 262 typedef struct GyroUncalibratedData { 263 float x = 0.0; 264 float y = 0.0; 265 float z = 0.0; 266 float biasX = 0.0; 267 float biasY = 0.0; 268 float biasZ = 0.0; 269 } GyroUncalibratedData; 270 271 /** 272 * @brief Defines the struct of the data reported by the significant motion sensor. 273 * This sensor detects whether there is substantial motion in the device on the three physical axes (x, y, and z). 274 * The value <b>1</b> means that there is substantial motion, and <b>0</b> means the opposite. 275 */ 276 typedef struct SignificantMotionData { 277 float scalar = 0.0; 278 } SignificantMotionData; 279 280 /** 281 * @brief Defines the struct of the data reported by the pedometer detection sensor. 282 * This sensor detects whether a user is walking. 283 * The value <b>1</b> means that the user is walking, and <b>0</b> means the opposite. 284 */ 285 typedef struct PedometerDetectData { 286 float scalar = 0.0; 287 } PedometerDetectData; 288 289 /** 290 * @brief Defines the struct of the data reported by the pedometer sensor. 291 * This sensor counts the number of steps taken by a user. 292 */ 293 typedef struct PedometerData { 294 float steps = 0.0; 295 } PedometerData; 296 297 /** 298 * @brief Defines the struct of the data reported by the ambient temperature sensor. 299 * This sensor measures the ambient temperature, in degrees Celsius (°C). 300 */ 301 typedef struct AmbientTemperatureData { 302 float temperature = 0.0; 303 } AmbientTemperatureData; 304 305 /** 306 * @brief Defines the struct of the data reported by the humidity sensor. 307 * This sensor measures the relative humidity of the environment, 308 * expressed as a percentage (%). 309 */ 310 typedef struct HumidityData { 311 float humidity = 0.0; 312 } HumidityData; 313 314 /** 315 * @brief Defines the struct of the data reported by the temperature sensor. 316 * This sensor measures the relative temperature of the environment, in degrees Celsius (°C). 317 */ 318 typedef struct TemperatureData { 319 float temperature = 0.0; 320 } TemperatureData; 321 322 /** 323 * @brief Defines the struct of the data reported by the magnetic field sensor. 324 * This sensor measures the ambient geomagnetic field in three physical axes (x, y, z), in μT. 325 */ 326 typedef struct MagneticFieldData { 327 float x = 0.0; 328 float y = 0.0; 329 float z = 0.0; 330 } MagneticFieldData; 331 332 /** 333 * @brief Defines the struct of the data reported by the uncalibrated magnetic field sensor. 334 * This sensor measures the uncalibrated ambient geomagnetic field in three physical axes (x, y, z), in μT. 335 */ 336 typedef struct MagneticFieldUncalibratedData { 337 float x = 0.0; 338 float y = 0.0; 339 float z = 0.0; 340 float biasX = 0.0; 341 float biasY = 0.0; 342 float biasZ = 0.0; 343 } MagneticFieldUncalibratedData; 344 345 /** 346 * @brief Defines the struct of the data reported by the barometer sensor. 347 * This sensor measures the atmospheric pressure, in hPa or mb. 348 */ 349 typedef struct BarometerData { 350 float pressure = 0.0; 351 } BarometerData; 352 353 /** 354 * @brief Defines the struct of the data reported by the device orientation sensor. 355 * This sensor measures the direction of rotation of the device, in rad. 356 */ 357 typedef struct DeviceOrientationData { 358 float scalar = 0.0; 359 } DeviceOrientationData; 360 361 /** 362 * @brief Defines the struct of the data reported by the orientation sensor. 363 * This sensor measures the angle of rotation of the device around all three physical axes (z, x, y), in rad. 364 */ 365 typedef struct OrientationData { 366 float alpha = 0.0; /**< The device rotates at an angle around the Z axis. */ 367 float beta = 0.0; /**< The device rotates at an angle around the X axis. */ 368 float gamma = 0.0; /**< The device rotates at an angle around the Y axis. */ 369 } OrientationData; 370 371 /** 372 * @brief Defines the struct of the data reported by the rotation vector sensor. 373 * This sensor measures the rotation vector of the device. 374 * It is synthesized by the acceleration sensor and gyroscope sensor. 375 */ 376 typedef struct RotationVectorData { 377 float x = 0.0; 378 float y = 0.0; 379 float z = 0.0; 380 float w = 0.0; 381 } RotationVectorData; 382 383 /** 384 * @brief Defines the struct of the data reported by the game rotation vector sensor. 385 * This sensor measures the game rotation vector of the device. 386 * It is synthesized by the acceleration sensor and gyroscope sensor. 387 */ 388 typedef struct GameRotationVectorData { 389 float x = 0.0; 390 float y = 0.0; 391 float z = 0.0; 392 float w = 0.0; 393 } GameRotationVectorData; 394 395 /** 396 * @brief Defines the struct of the data reported by the geomagnetic rotation vector sensor. 397 * This sensor measures the geomagnetic rotation vector of the device. 398 * It is synthesized by the acceleration sensor and magnetic field sensor. 399 */ 400 typedef struct GeomagneticRotaVectorData { 401 float x = 0.0; 402 float y = 0.0; 403 float z = 0.0; 404 float w = 0.0; 405 } GeomagneticRotaVectorData; 406 407 /** 408 * @brief Defines the struct of the data reported by the proximity light sensor. 409 * This sensor measures the proximity or distance of visible objects relative to the device display, 410 * where 0 indicates proximity and 1 indicates distance. 411 */ 412 typedef struct ProximityData { 413 float distance = 0.0; 414 } ProximityData; 415 416 /** 417 * @brief Defines the struct of the data reported by the ambient light sensor. 418 * This sensor measures the intensity of light around the device, in lux. 419 */ 420 typedef struct AmbientLightData { 421 float intensity = 0.0; 422 float colorTemperature = 0.0; 423 float infraredLuminance = 0.0; 424 } AmbientLightData; 425 426 /** 427 * @brief Defines the struct of the data reported by the hall effect sensor. 428 * This sensor measures whether there is magnetic attraction around the device. 429 * The value <b>1</b> means that there is magnet attraction, and <b>0</b> means the opposite. 430 */ 431 typedef struct HallData { 432 float status = 0.0; 433 } HallData; 434 435 /** 436 * @brief Defines the struct of the data reported by the heart rate sensor. 437 * This sensor measures a user's heart rate, in bpm. 438 */ 439 typedef struct HeartRateData { 440 float heartRate = 0.0; 441 } HeartRateData; 442 443 /** 444 * @brief Defines the struct of the data reported by the wear detection sensor. 445 * This sensor detects whether a user is wearing a wearable device. 446 * The value <b>1</b> means that the user is wearing a wearable device, and <b>0</b> means the opposite. 447 */ 448 typedef struct WearDetectionData { 449 float value = 0.0; 450 } WearDetectionData; 451 452 /** 453 * @brief Defines the struct of the data reported by the color sensor. 454 * This sensor is used to measure the luminous intensity (in lux) and color temperature (in Kelvin). 455 */ 456 typedef struct ColorData { 457 float lightIntensity = 0.0; 458 float colorTemperature = 0.0; 459 } ColorData; 460 461 /** 462 * @brief Defines the struct of the data reported by the SAR sensor. 463 * This sensor measures the SAR, in W/kg. 464 */ 465 typedef struct SarData { 466 float absorptionRatio = 0.0; 467 } SarData; 468 469 /** 470 * @brief Defines the struct of the data reported by the RPC sensor. 471 * This sensor measures the radio power control. 472 */ 473 typedef struct RPCData { 474 float absorptionRatio = 0.0; 475 float threshold = 0.0; 476 float offset = 0.0; 477 } RPCData; 478 479 /** 480 * @brief Defines the struct of the data reported by the posture sensor. 481 * This sensor measures the angle between two screens, in degrees. The angle ranges from 0 to 180. 482 */ 483 typedef struct PostureData { 484 float gxm = 0.0; /**< The main screen acceleration on the x axis */ 485 float gym = 0.0; /**< The main screen acceleration on the y axis */ 486 float gzm = 0.0; /**< The main screen acceleration on the z axis */ 487 float gxs = 0.0; /**< The second screen acceleration on the x axis */ 488 float gys = 0.0; /**< The second screen acceleration on the y axis */ 489 float gzs = 0.0; /**< The second screen acceleration on the z axis */ 490 float angle = 0.0; /**< The angle between two screens. The angle ranges from 0 to 180 degrees. */ 491 } PostureData; 492 493 /** 494 * @brief Defines the struct of the data reported by the head posture sensor. 495 * This sensor measures the head posture of user. 496 */ 497 typedef struct HeadPostureData { 498 int32_t order = 0; 499 float w = 0.0; 500 float x = 0.0; 501 float y = 0.0; 502 float z = 0.0; 503 } HeadPostureData; 504 505 typedef struct DropDetectionData { 506 float status = 0.0F; 507 } DropDetectionData; 508 509 typedef struct SensorActiveInfo { 510 int32_t pid = -1; /**< PID */ 511 int32_t sensorId = -1; /**< Sensor ID */ 512 int64_t samplingPeriodNs = -1; /**< Sample period, in ns */ 513 int64_t maxReportDelayNs = -1; /**< Maximum Report Delay, in ns */ 514 } SensorActiveInfo; 515 516 typedef void (*SensorActiveInfoCB)(SensorActiveInfo &sensorActiveInfo); 517 518 #ifdef __cplusplus 519 #if __cplusplus 520 } 521 #endif 522 #endif 523 #endif /* SENSOR_AGENT_TYPE_H */ 524 /**< @} */ 525