Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
Adafruit_Sensor.h
1 /*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software< /span>
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17 /* Update by K. Townsend (Adafruit Industries) for lighter typedefs, and
18  * extended sensor support to include color, voltage and current */
19 
20 #ifndef _ADAFRUIT_SENSOR_H
21 #define _ADAFRUIT_SENSOR_H
22 
23 #if ARDUINO >= 100
24  #include "Arduino.h"
25  #include "Print.h"
26 #else
27  #include "WProgram.h"
28 #endif
29 
30 /* Intentionally modeled after sensors.h in the Android API:
31  * https://github.com/android/platform_hardware_libhardware/blob/master/include/hardware/sensors.h */
32 
33 /* Constants */
34 #define SENSORS_GRAVITY_EARTH (9.80665F)
35 #define SENSORS_GRAVITY_MOON (1.6F)
36 #define SENSORS_GRAVITY_SUN (275.0F)
37 #define SENSORS_GRAVITY_STANDARD (SENSORS_GRAVITY_EARTH)
38 #define SENSORS_MAGFIELD_EARTH_MAX (60.0F)
39 #define SENSORS_MAGFIELD_EARTH_MIN (30.0F)
40 #define SENSORS_PRESSURE_SEALEVELHPA (1013.25F)
41 #define SENSORS_DPS_TO_RADS (0.017453293F)
42 #define SENSORS_GAUSS_TO_MICROTESLA (100)
45 typedef enum
46 {
47  SENSOR_TYPE_ACCELEROMETER = (1),
48  SENSOR_TYPE_MAGNETIC_FIELD = (2),
49  SENSOR_TYPE_ORIENTATION = (3),
50  SENSOR_TYPE_GYROSCOPE = (4),
51  SENSOR_TYPE_LIGHT = (5),
52  SENSOR_TYPE_PRESSURE = (6),
53  SENSOR_TYPE_PROXIMITY = (8),
54  SENSOR_TYPE_GRAVITY = (9),
55  SENSOR_TYPE_LINEAR_ACCELERATION = (10),
56  SENSOR_TYPE_ROTATION_VECTOR = (11),
57  SENSOR_TYPE_RELATIVE_HUMIDITY = (12),
58  SENSOR_TYPE_AMBIENT_TEMPERATURE = (13),
59  SENSOR_TYPE_VOLTAGE = (15),
60  SENSOR_TYPE_CURRENT = (16),
61  SENSOR_TYPE_COLOR = (17)
62 } sensors_type_t;
63 
65 typedef struct {
66  union {
67  float v[3];
68  struct {
69  float x;
70  float y;
71  float z;
72  };
73  /* Orientation sensors */
74  struct {
75  float roll;
76  float pitch;
77  float heading;
78  };
79  };
80  int8_t status;
81  uint8_t reserved[3];
83 
85 typedef struct {
86  union {
87  float c[3];
88  /* RGB color space */
89  struct {
90  float r;
91  float g;
92  float b;
93  };
94  };
95  uint32_t rgba;
97 
98 /* Sensor event (36 bytes) */
100 typedef struct
101 {
102  int32_t version;
103  int32_t sensor_id;
104  int32_t type;
105  int32_t reserved0;
106  int32_t timestamp;
107  union
108  {
109  float data[4];
114  float temperature;
115  float distance;
116  float light;
117  float pressure;
119  float current;
120  float voltage;
122  };
124 
125 /* Sensor details (40 bytes) */
127 typedef struct
128 {
129  char name[12];
130  int32_t version;
131  int32_t sensor_id;
132  int32_t type;
133  float max_value;
134  float min_value;
135  float resolution;
136  int32_t min_delay;
137 } sensor_t;
138 
140  public:
141  // Constructor(s)
142  Adafruit_Sensor() {}
143  virtual ~Adafruit_Sensor() {}
144 
145  // These must be defined by the subclass
146  virtual void enableAutoRange(bool enabled) {};
147  virtual bool getEvent(sensors_event_t*) = 0;
148  virtual void getSensor(sensor_t*) = 0;
149 
150  private:
151  bool _autoRange;
152 };
153 
154 #endif
sensors_vec_t orientation
Definition: Adafruit_Sensor.h:112
Definition: Adafruit_Sensor.h:65
float b
Definition: Adafruit_Sensor.h:92
float light
Definition: Adafruit_Sensor.h:116
float r
Definition: Adafruit_Sensor.h:90
float g
Definition: Adafruit_Sensor.h:91
Definition: Adafruit_Sensor.h:127
float voltage
Definition: Adafruit_Sensor.h:120
int32_t version
Definition: Adafruit_Sensor.h:130
float pressure
Definition: Adafruit_Sensor.h:117
int32_t type
Definition: Adafruit_Sensor.h:132
float distance
Definition: Adafruit_Sensor.h:115
sensors_vec_t acceleration
Definition: Adafruit_Sensor.h:110
sensors_vec_t magnetic
Definition: Adafruit_Sensor.h:111
int32_t sensor_id
Definition: Adafruit_Sensor.h:131
float min_value
Definition: Adafruit_Sensor.h:134
uint32_t rgba
Definition: Adafruit_Sensor.h:95
int32_t sensor_id
Definition: Adafruit_Sensor.h:103
int32_t timestamp
Definition: Adafruit_Sensor.h:106
Definition: Adafruit_Sensor.h:139
Definition: Adafruit_Sensor.h:100
int32_t reserved0
Definition: Adafruit_Sensor.h:105
float current
Definition: Adafruit_Sensor.h:119
Definition: Adafruit_Sensor.h:85
sensors_color_t color
Definition: Adafruit_Sensor.h:121
float roll
Definition: Adafruit_Sensor.h:75
float heading
Definition: Adafruit_Sensor.h:77
float relative_humidity
Definition: Adafruit_Sensor.h:118
float temperature
Definition: Adafruit_Sensor.h:114
int32_t version
Definition: Adafruit_Sensor.h:102
sensors_vec_t gyro
Definition: Adafruit_Sensor.h:113
float max_value
Definition: Adafruit_Sensor.h:133
int32_t type
Definition: Adafruit_Sensor.h:104
float resolution
Definition: Adafruit_Sensor.h:135
int32_t min_delay
Definition: Adafruit_Sensor.h:136
float pitch
Definition: Adafruit_Sensor.h:76