Jatin Sharma / Mbed 2 deprecated RaheeNew

Dependencies:   mbed

Dependents:   RaheeNew

Fork of Adafruit9-DOf by Bruno Manganelli

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Adafruit_Sensor.h Source File

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 #include <cstdint>
00018 using namespace std;
00019 
00020 /* Update by K. Townsend (Adafruit Industries) for lighter typedefs, and
00021  * extended sensor support to include color, voltage and current */
00022  
00023 #ifndef _ADAFRUIT_SENSOR_H
00024 #define _ADAFRUIT_SENSOR_H
00025 
00026 
00027 /* Intentionally modeled after sensors.h in the Android API:
00028  * https://github.com/android/platform_hardware_libhardware/blob/master/include/hardware/sensors.h */
00029 
00030 /* Constants */
00031 #define SENSORS_GRAVITY_EARTH             (9.80665F)              /**< Earth's gravity in m/s^2 */
00032 #define SENSORS_GRAVITY_MOON              (1.6F)                  /**< The moon's gravity in m/s^2 */
00033 #define SENSORS_GRAVITY_SUN               (275.0F)                /**< The sun's gravity in m/s^2 */
00034 #define SENSORS_GRAVITY_STANDARD          (SENSORS_GRAVITY_EARTH)
00035 #define SENSORS_MAGFIELD_EARTH_MAX        (60.0F)                 /**< Maximum magnetic field on Earth's surface */
00036 #define SENSORS_MAGFIELD_EARTH_MIN        (30.0F)                 /**< Minimum magnetic field on Earth's surface */
00037 #define SENSORS_PRESSURE_SEALEVELHPA      (1013.25F)              /**< Average sea level pressure is 1013.25 hPa */
00038 #define SENSORS_DPS_TO_RADS               (0.017453293F)          /**< Degrees/s to rad/s multiplier */
00039 #define SENSORS_GAUSS_TO_MICROTESLA       (100)                   /**< Gauss to micro-Tesla multiplier */
00040 
00041 /** Sensor types */
00042 typedef enum
00043 {
00044   SENSOR_TYPE_ACCELEROMETER         = (1),   /**< Gravity + linear acceleration */
00045   SENSOR_TYPE_MAGNETIC_FIELD        = (2),
00046   SENSOR_TYPE_ORIENTATION           = (3),
00047   SENSOR_TYPE_GYROSCOPE             = (4),
00048   SENSOR_TYPE_LIGHT                 = (5),
00049   SENSOR_TYPE_PRESSURE              = (6),
00050   SENSOR_TYPE_PROXIMITY             = (8),
00051   SENSOR_TYPE_GRAVITY               = (9),
00052   SENSOR_TYPE_LINEAR_ACCELERATION   = (10),  /**< Acceleration not including gravity */
00053   SENSOR_TYPE_ROTATION_VECTOR       = (11),
00054   SENSOR_TYPE_RELATIVE_HUMIDITY     = (12),
00055   SENSOR_TYPE_AMBIENT_TEMPERATURE   = (13),
00056   SENSOR_TYPE_VOLTAGE               = (15),
00057   SENSOR_TYPE_CURRENT               = (16),
00058   SENSOR_TYPE_COLOR                 = (17)
00059 } sensors_type_t;
00060 
00061 /** struct sensors_vec_s is used to return a vector in a common format. */
00062 typedef struct {
00063     union {
00064         float v[3];
00065         struct {
00066             float x;
00067             float y;
00068             float z;
00069         };
00070         /* Orientation sensors */
00071         struct {
00072             float roll;    /**< Rotation around the longitudinal axis (the plane body, 'X axis'). Roll is positive and increasing when moving downward. -90�<=roll<=90� */
00073             float pitch;   /**< Rotation around the lateral axis (the wing span, 'Y axis'). Pitch is positive and increasing when moving upwards. -180�<=pitch<=180�) */
00074             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� */
00075         };
00076     };
00077     int8_t status;
00078     uint8_t reserved[3];
00079 } sensors_vec_t;
00080 
00081 /** struct sensors_color_s is used to return color data in a common format. */
00082 typedef struct {
00083     union {
00084         float c[3];
00085         /* RGB color space */
00086         struct {
00087             float r;       /**< Red component */
00088             float g;       /**< Green component */
00089             float b;       /**< Blue component */
00090         };
00091     };
00092     uint32_t rgba;         /**< 24-bit RGBA value */
00093 } sensors_color_t;
00094 
00095 /* Sensor event (36 bytes) */
00096 /** struct sensor_event_s is used to provide a single sensor event in a common format. */
00097 typedef struct
00098 {
00099     int32_t version;                          /**< must be sizeof(struct sensors_event_t) */
00100     int32_t sensor_id;                        /**< unique sensor identifier */
00101     int32_t type;                             /**< sensor type */
00102     int32_t reserved0;                        /**< reserved */
00103     int32_t timestamp;                        /**< time is in milliseconds */
00104     union
00105     {
00106         float           data[4];
00107         sensors_vec_t   acceleration;         /**< acceleration values are in meter per second per second (m/s^2) */
00108         sensors_vec_t   magnetic;             /**< magnetic vector values are in micro-Tesla (uT) */
00109         sensors_vec_t   orientation;          /**< orientation values are in degrees */
00110         sensors_vec_t   gyro;                 /**< gyroscope values are in rad/s */
00111         float           temperature;          /**< temperature is in degrees centigrade (Celsius) */
00112         float           distance;             /**< distance in centimeters */
00113         float           light;                /**< light in SI lux units */
00114         float           pressure;             /**< pressure in hectopascal (hPa) */
00115         float           relative_humidity;    /**< relative humidity in percent */
00116         float           current;              /**< current in milliamps (mA) */
00117         float           voltage;              /**< voltage in volts (V) */
00118         sensors_color_t color;                /**< color in RGB component values */
00119     };
00120 } sensors_event_t;
00121 
00122 /* Sensor details (40 bytes) */
00123 /** struct sensor_s is used to describe basic information about a specific sensor. */
00124 typedef struct
00125 {
00126     char     name[12];                        /**< sensor name */
00127     int32_t  version;                         /**< version of the hardware + driver */
00128     int32_t  sensor_id;                       /**< unique sensor identifier */
00129     int32_t  type;                            /**< this sensor's type (ex. SENSOR_TYPE_LIGHT) */
00130     float    max_value;                       /**< maximum value of this sensor's value in SI units */
00131     float    min_value;                       /**< minimum value of this sensor's value in SI units */
00132     float    resolution;                      /**< smallest difference between two values reported by this sensor */
00133     int32_t  min_delay;                       /**< min delay in microseconds between events. zero = not a constant rate */
00134 } sensor_t;
00135 
00136 class Adafruit_Sensor {
00137  public:
00138   // Constructor(s)
00139   void constructor();
00140 
00141   // These must be defined by the subclass
00142   virtual void enableAutoRange(bool enabled) = 0;
00143   virtual void getEvent(sensors_event_t*)    = 0;
00144   virtual void getSensor(sensor_t*)          = 0;
00145   
00146  private:
00147   bool _autoRange;
00148 };
00149 
00150 #endif