Adafruit driver converted to Mbed OS 6.x.
Dependents: Adafruit-BNO055-test
Adafruit_Sensor.h
00001 /* 00002 * Copyright (C) 2008 The Android Open Source Project 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software< /span> 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 /* Update by K. Townsend (Adafruit Industries) for lighter typedefs, and 00018 * extended sensor support to include color, voltage and current */ 00019 00020 #ifndef _ADAFRUIT_SENSOR_H 00021 #define _ADAFRUIT_SENSOR_H 00022 00023 00024 /* Intentionally modeled after sensors.h in the Android API: 00025 * https://github.com/android/platform_hardware_libhardware/blob/master/include/hardware/sensors.h */ 00026 00027 /* Constants */ 00028 #define SENSORS_GRAVITY_EARTH (9.80665F) /**< Earth's gravity in m/s^2 */ 00029 #define SENSORS_GRAVITY_MOON (1.6F) /**< The moon's gravity in m/s^2 */ 00030 #define SENSORS_GRAVITY_SUN (275.0F) /**< The sun's gravity in m/s^2 */ 00031 #define SENSORS_GRAVITY_STANDARD (SENSORS_GRAVITY_EARTH) 00032 #define SENSORS_MAGFIELD_EARTH_MAX (60.0F) /**< Maximum magnetic field on Earth's surface */ 00033 #define SENSORS_MAGFIELD_EARTH_MIN (30.0F) /**< Minimum magnetic field on Earth's surface */ 00034 #define SENSORS_PRESSURE_SEALEVELHPA (1013.25F) /**< Average sea level pressure is 1013.25 hPa */ 00035 #define SENSORS_DPS_TO_RADS (0.017453293F) /**< Degrees/s to rad/s multiplier */ 00036 #define SENSORS_GAUSS_TO_MICROTESLA (100) /**< Gauss to micro-Tesla multiplier */ 00037 00038 /** Sensor types */ 00039 typedef enum 00040 { 00041 SENSOR_TYPE_ACCELEROMETER = (1), /**< Gravity + linear acceleration */ 00042 SENSOR_TYPE_MAGNETIC_FIELD = (2), 00043 SENSOR_TYPE_ORIENTATION = (3), 00044 SENSOR_TYPE_GYROSCOPE = (4), 00045 SENSOR_TYPE_LIGHT = (5), 00046 SENSOR_TYPE_PRESSURE = (6), 00047 SENSOR_TYPE_PROXIMITY = (8), 00048 SENSOR_TYPE_GRAVITY = (9), 00049 SENSOR_TYPE_LINEAR_ACCELERATION = (10), /**< Acceleration not including gravity */ 00050 SENSOR_TYPE_ROTATION_VECTOR = (11), 00051 SENSOR_TYPE_RELATIVE_HUMIDITY = (12), 00052 SENSOR_TYPE_AMBIENT_TEMPERATURE = (13), 00053 SENSOR_TYPE_VOLTAGE = (15), 00054 SENSOR_TYPE_CURRENT = (16), 00055 SENSOR_TYPE_COLOR = (17) 00056 } sensors_type_t; 00057 00058 /** struct sensors_vec_s is used to return a vector in a common format. */ 00059 typedef struct { 00060 union { 00061 float v[3]; 00062 struct { 00063 float x; 00064 float y; 00065 float z; 00066 }; 00067 /* Orientation sensors */ 00068 struct { 00069 float roll; /**< Rotation around the longitudinal axis (the plane body, 'X axis'). Roll is positive and increasing when moving downward. -90°<=roll<=90° */ 00070 float pitch; /**< Rotation around the lateral axis (the wing span, 'Y axis'). Pitch is positive and increasing when moving upwards. -180°<=pitch<=180°) */ 00071 float heading; /**< Angle between the longitudinal axis (the plane body) and magnetic north, measured clockwise when viewing from the top of the device. 0-359° */ 00072 }; 00073 }; 00074 char status; 00075 unsigned char reserved[3]; 00076 } sensors_vec_t; 00077 00078 /** struct sensors_color_s is used to return color data in a common format. */ 00079 typedef struct { 00080 union { 00081 float c[3]; 00082 /* RGB color space */ 00083 struct { 00084 float r; /**< Red component */ 00085 float g; /**< Green component */ 00086 float b; /**< Blue component */ 00087 }; 00088 }; 00089 unsigned int rgba; /**< 24-bit RGBA value */ 00090 } sensors_color_t; 00091 00092 /* Sensor event (36 bytes) */ 00093 /** struct sensor_event_s is used to provide a single sensor event in a common format. */ 00094 typedef struct 00095 { 00096 int version; /**< must be sizeof(struct sensors_event_t) */ 00097 int sensor_id; /**< unique sensor identifier */ 00098 int type; /**< sensor type */ 00099 int reserved0; /**< reserved */ 00100 int timestamp; /**< time is in milliseconds */ 00101 union 00102 { 00103 float data[4]; 00104 sensors_vec_t acceleration; /**< acceleration values are in meter per second per second (m/s^2) */ 00105 sensors_vec_t magnetic; /**< magnetic vector values are in micro-Tesla (uT) */ 00106 sensors_vec_t orientation; /**< orientation values are in degrees */ 00107 sensors_vec_t gyro; /**< gyroscope values are in rad/s */ 00108 float temperature; /**< temperature is in degrees centigrade (Celsius) */ 00109 float distance; /**< distance in centimeters */ 00110 float light; /**< light in SI lux units */ 00111 float pressure; /**< pressure in hectopascal (hPa) */ 00112 float relative_humidity; /**< relative humidity in percent */ 00113 float current; /**< current in milliamps (mA) */ 00114 float voltage; /**< voltage in volts (V) */ 00115 sensors_color_t color; /**< color in RGB component values */ 00116 }; 00117 } sensors_event_t; 00118 00119 /* Sensor details (40 bytes) */ 00120 /** struct sensor_s is used to describe basic information about a specific sensor. */ 00121 typedef struct 00122 { 00123 char name[12]; /**< sensor name */ 00124 int version; /**< version of the hardware + driver */ 00125 int sensor_id; /**< unique sensor identifier */ 00126 int type; /**< this sensor's type (ex. SENSOR_TYPE_LIGHT) */ 00127 float max_value; /**< maximum value of this sensor's value in SI units */ 00128 float min_value; /**< minimum value of this sensor's value in SI units */ 00129 float resolution; /**< smallest difference between two values reported by this sensor */ 00130 int min_delay; /**< min delay in microseconds between events. zero = not a constant rate */ 00131 } sensor_t; 00132 00133 class Adafruit_Sensor { 00134 public: 00135 // Constructor(s) 00136 Adafruit_Sensor() {} 00137 virtual ~Adafruit_Sensor() {} 00138 00139 // These must be defined by the subclass 00140 virtual void enableAutoRange(bool enabled) {}; 00141 virtual bool getEvent(sensors_event_t*) = 0; 00142 virtual void getSensor(sensor_t*) = 0; 00143 00144 private: 00145 bool _autoRange; 00146 }; 00147 00148 #endif
Generated on Wed Jul 13 2022 00:45:44 by 1.7.2