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 Sensor 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 * @version 1.0 28 */ 29 30 /** 31 * @file sensor_type.h 32 * 33 * @brief Defines the data used by the sensor module, including the sensor types, sensor information, 34 * and reported sensor data. 35 * 36 * @since 2.2 37 * @version 1.0 38 */ 39 40 #ifndef SENSOR_TYPE_H 41 #define SENSOR_TYPE_H 42 43 #include <stdint.h> 44 45 #ifdef __cplusplus 46 #if __cplusplus 47 extern "C" { 48 #endif 49 #endif /* __cplusplus */ 50 51 #define SENSOR_NAME_MAX_LEN 32 /**< Maximum length of the sensor name */ 52 #define SENSOR_VERSION_MAX_LEN 16 /**< Maximum length of the sensor version */ 53 54 /** 55 * @brief Enumerates return values of the sensor module. 56 * 57 * @since 2.2 58 */ 59 enum SensorStatus { 60 SENSOR_SUCCESS = 0, /**< The operation is successful. */ 61 SENSOR_FAILURE = -1, /**< The operation failed. */ 62 SENSOR_NOT_SUPPORT = -2, /**< The operation is not supported. */ 63 SENSOR_INVALID_PARAM = -3, /**< The sensor parameter is invalid. */ 64 SENSOR_INVALID_SERVICE = -4, /**< The sensor service is invalid. */ 65 SENSOR_NULL_PTR = -5, /**< The pointer is null. */ 66 }; 67 68 /** 69 * @brief Enumerates sensor types. 70 * 71 * @since 2.2 72 */ 73 enum SensorTypeTag { 74 SENSOR_TYPE_NONE = 0, /**< None, for testing only */ 75 SENSOR_TYPE_ACCELEROMETER = 1, /**< Acceleration sensor */ 76 SENSOR_TYPE_GYROSCOPE = 2, /**< Gyroscope sensor */ 77 SENSOR_TYPE_PHOTOPLETHYSMOGRAPH = 3, /**< Photoplethysmography sensor */ 78 SENSOR_TYPE_ELECTROCARDIOGRAPH = 4, /**< Electrocardiogram (ECG) sensor */ 79 SENSOR_TYPE_AMBIENT_LIGHT = 5, /**< Ambient light sensor */ 80 SENSOR_TYPE_MAGNETIC_FIELD = 6, /**< Magnetic field sensor */ 81 SENSOR_TYPE_CAPACITIVE = 7, /**< Capacitive sensor */ 82 SENSOR_TYPE_BAROMETER = 8, /**< Barometric pressure sensor */ 83 SENSOR_TYPE_TEMPERATURE = 9, /**< Temperature sensor */ 84 SENSOR_TYPE_HALL = 10, /**< Hall effect sensor */ 85 SENSOR_TYPE_GESTURE = 11, /**< Gesture sensor */ 86 SENSOR_TYPE_PROXIMITY = 12, /**< Proximity sensor */ 87 SENSOR_TYPE_HUMIDITY = 13, /**< Humidity sensor */ 88 SENSOR_TYPE_COLOR = 14, /**< Color sensor */ 89 SENSOR_TYPE_SAR = 15, /**< SAR sensor */ 90 SENSOR_TYPE_MEDICAL_BEGIN = 128, /**< The begin of medical sensorId enumeration value range */ 91 SENSOR_TYPE_MEDICAL_END = 160, /**< The end of medical sensorId enumeration value range */ 92 SENSOR_TYPE_PHYSICAL_MAX = 255, /**< Maximum type of a physical sensor */ 93 SENSOR_TYPE_ORIENTATION = 256, /**< Orientation sensor */ 94 SENSOR_TYPE_GRAVITY = 257, /**< Gravity sensor */ 95 SENSOR_TYPE_LINEAR_ACCELERATION = 258, /**< Linear acceleration sensor */ 96 SENSOR_TYPE_ROTATION_VECTOR = 259, /**< Rotation vector sensor */ 97 SENSOR_TYPE_AMBIENT_TEMPERATURE = 260, /**< Ambient temperature sensor */ 98 SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED = 261, /**< Uncalibrated magnetic field sensor */ 99 SENSOR_TYPE_GAME_ROTATION_VECTOR = 262, /**< Game rotation vector sensor */ 100 SENSOR_TYPE_GYROSCOPE_UNCALIBRATED = 263, /**< Uncalibrated gyroscope sensor */ 101 SENSOR_TYPE_SIGNIFICANT_MOTION = 264, /**< Significant motion sensor */ 102 SENSOR_TYPE_PEDOMETER_DETECTION = 265, /**< Pedometer detection sensor */ 103 SENSOR_TYPE_PEDOMETER = 266, /**< Pedometer sensor */ 104 SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR = 277, /**< Geomagnetic rotation vector sensor */ 105 SENSOR_TYPE_HEART_RATE = 278, /**< Heart rate sensor */ 106 SENSOR_TYPE_DEVICE_ORIENTATION = 279, /**< Device orientation sensor */ 107 SENSOR_TYPE_WEAR_DETECTION = 280, /**< Wear detection sensor */ 108 SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED = 281, /**< Uncalibrated acceleration sensor */ 109 SENSOR_TYPE_MAX, /**< Maximum number of sensor types */ 110 }; 111 112 /** 113 * @brief Enumerates accuracy types of sensors. 114 * 115 * @since 2.2 116 */ 117 enum SensorAccuracyType { 118 SENSOR_NO_ACCURACY = 0, /**< No accuracy */ 119 SENSOR_LOW_ACCURACY = 1, /**< Low accuracy */ 120 SENSOR_MEDIUM_ACCURACY = 2, /**< Medium accuracy */ 121 SENSOR_HIGH_ACCURACY = 3, /**< High accuracy */ 122 SENSOR_MAX_ACCURACY, /**< Maximum accuracy */ 123 }; 124 125 /** 126 * @brief Enumerates measurement ranges of sensors. 127 * 128 * @since 2.2 129 */ 130 enum SensorRangeType { 131 SENSOR_RANGE_LEVEL1 = 0, /**< Measurement range level 1 */ 132 SENSOR_RANGE_LEVEL2 = 1, /**< Measurement range level 2 */ 133 SENSOR_RANGE_LEVEL3 = 2, /**< Measurement range level 3 */ 134 SENSOR_RANGE_LEVEL_MAX, /**< Maximum measurement range level */ 135 }; 136 137 /** 138 * @brief Enumerates data reporting modes of sensors. 139 * 140 * @since 2.2 141 */ 142 enum SensorModeType { 143 SENSOR_MODE_DEFAULT = 0, /**< Default data reporting mode */ 144 SENSOR_MODE_REALTIME = 1, /**< Real-time data reporting mode to report a group of data each time */ 145 SENSOR_MODE_ON_CHANGE = 2, /**< Real-time data reporting mode to report data upon status changes */ 146 SENSOR_MODE_ONE_SHOT = 3, /**< Real-time data reporting mode to report data only once */ 147 SENSOR_MODE_FIFO_MODE = 4, /**< FIFO-based data reporting mode to report data based on the configured cache size */ 148 SENSOR_MODE_MAX, /**< Maximum sensor data reporting mode */ 149 }; 150 151 /** 152 * @brief Enumerates hardware service group for sensors 153 * 154 * @since 2.2 155 */ 156 enum SensorGroupType { 157 TRADITIONAL_SENSOR_TYPE = 0, /**< traditional sensor type, the sensorId enumeration value range is 128-160 */ 158 MEDICAL_SENSOR_TYPE = 1, /**< medical sensor type, the sensorId enumeration value range is not within 128-160 */ 159 SENSOR_GROUP_TYPE_MAX, /**< Maximum sensor type*/ 160 }; 161 162 /** 163 * @brief Defines basic sensor information. 164 * 165 * Information about a sensor includes the sensor name, vendor, firmware version, hardware version, sensor type ID, 166 * sensor ID, maximum measurement range, accuracy, and power. 167 * 168 * @since 2.2 169 */ 170 struct SensorInformation { 171 char sensorName[SENSOR_NAME_MAX_LEN]; /**< Sensor name */ 172 char vendorName[SENSOR_NAME_MAX_LEN]; /**< Sensor vendor */ 173 char firmwareVersion[SENSOR_VERSION_MAX_LEN]; /**< Sensor firmware version */ 174 char hardwareVersion[SENSOR_VERSION_MAX_LEN]; /**< Sensor hardware version */ 175 int32_t sensorTypeId; /**< Sensor type ID (described in {@link SensorTypeTag}) */ 176 int32_t sensorId; /**< Sensor ID, defined by the sensor driver developer */ 177 float maxRange; /**< Maximum measurement range of the sensor */ 178 float accuracy; /**< Sensor accuracy */ 179 float power; /**< Sensor power */ 180 int64_t minDelay; /**< Minimum sample period allowed in microseconds */ 181 int64_t maxDelay; /**< Maxmum sample period allowed in microseconds */ 182 }; 183 184 /** 185 * @brief Defines the data reported by the sensor. 186 * 187 * The reported sensor data includes the sensor ID, sensor algorithm version, data generation time, 188 * data options (such as the measurement range and accuracy), data reporting mode, data address, and data length. 189 * 190 * @since 2.2 191 */ 192 struct SensorEvents { 193 int32_t sensorId; /**< Sensor ID */ 194 int32_t version; /**< Sensor algorithm version */ 195 int64_t timestamp; /**< Time when sensor data was generated */ 196 uint32_t option; /**< Sensor data options, including the measurement range and accuracy */ 197 int32_t mode; /**< Sensor data reporting mode */ 198 uint8_t *data; /**< Sensor data address */ 199 uint32_t dataLen; /**< Sensor data length */ 200 }; 201 202 /** 203 * @brief Defines the callback for reporting sensor data. This callback needs to be registered when 204 * a sensor user subscribes to sensor data. Only after the sensor is enabled, the sensor data subscriber can receive 205 * sensor data. For details, see {@link SensorInterface}. 206 * 207 * @since 2.2 208 */ 209 typedef int32_t (*RecordDataCallback)(const struct SensorEvents*); 210 211 #ifdef __cplusplus 212 #if __cplusplus 213 } 214 #endif 215 #endif /* __cplusplus */ 216 217 #endif /* SENSOR_TYPE_H */ 218 /** @} */ 219