29
29
#include " WProgram.h"
30
30
#endif
31
31
32
- /* Intentionally modeled after sensors.h in the Android API:
33
- * https://github.com/android/platform_hardware_libhardware/blob/master/include/hardware/sensors.h
34
- */
35
-
36
32
/* Constants */
37
33
#define SENSORS_GRAVITY_EARTH (9 .80665F ) /* *< Earth's gravity in m/s^2 */
38
34
#define SENSORS_GRAVITY_MOON (1 .6F ) /* *< The moon's gravity in m/s^2 */
@@ -74,40 +70,41 @@ typedef enum {
74
70
/* * struct sensors_vec_s is used to return a vector in a common format. */
75
71
typedef struct {
76
72
union {
77
- float v[3 ];
73
+ float v[3 ]; // /< 3D vector elements
78
74
struct {
79
- float x;
80
- float y;
81
- float z;
82
- };
75
+ float x; // /< X component of vector
76
+ float y; // /< Y component of vector
77
+ float z; // /< Z component of vector
78
+ }; // /< Struct for holding XYZ component
83
79
/* Orientation sensors */
84
80
struct {
85
81
float roll; /* *< Rotation around the longitudinal axis (the plane body, 'X
86
82
axis'). Roll is positive and increasing when moving
87
- downward. -90°<=roll<=90° */
83
+ downward. -90°<=roll<=90° */
88
84
float pitch; /* *< Rotation around the lateral axis (the wing span, 'Y
89
85
axis'). Pitch is positive and increasing when moving
90
- upwards. -180°<=pitch<=180°) */
86
+ upwards. -180°<=pitch<=180°) */
91
87
float heading; /* *< Angle between the longitudinal axis (the plane body)
92
88
and magnetic north, measured clockwise when viewing from
93
- the top of the device. 0-359° */
94
- };
95
- };
96
- int8_t status;
97
- uint8_t reserved[3 ];
89
+ the top of the device. 0-359° */
90
+ }; // /< Struct for holding roll/pitch/heading
91
+ }; // /< Union that can hold 3D vector array, XYZ components or
92
+ // /< roll/pitch/heading
93
+ int8_t status; // /< Status byte
94
+ uint8_t reserved[3 ]; // /< Reserved
98
95
} sensors_vec_t ;
99
96
100
97
/* * struct sensors_color_s is used to return color data in a common format. */
101
98
typedef struct {
102
99
union {
103
- float c[3 ];
100
+ float c[3 ]; // /< Raw 3-element data
104
101
/* RGB color space */
105
102
struct {
106
- float r; /* *< Red component */
107
- float g; /* *< Green component */
108
- float b; /* *< Blue component */
109
- };
110
- };
103
+ float r; /* *< Red component */
104
+ float g; /* *< Green component */
105
+ float b; /* *< Blue component */
106
+ }; // /< RGB data in floating point notation
107
+ }; // /< Union of various ways to describe RGB colorspace
111
108
uint32_t rgba; /* *< 24-bit RGBA value */
112
109
} sensors_color_t ;
113
110
@@ -121,7 +118,7 @@ typedef struct {
121
118
int32_t reserved0; /* *< reserved */
122
119
int32_t timestamp; /* *< time is in milliseconds */
123
120
union {
124
- float data[4 ];
121
+ float data[4 ]; // /< Raw data
125
122
sensors_vec_t acceleration; /* *< acceleration values are in meter per second
126
123
per second (m/s^2) */
127
124
sensors_vec_t
@@ -136,7 +133,7 @@ typedef struct {
136
133
float current; /* *< current in milliamps (mA) */
137
134
float voltage; /* *< voltage in volts (V) */
138
135
sensors_color_t color; /* *< color in RGB component values */
139
- };
136
+ }; // /< Union for the wide ranges of data we can carry
140
137
} sensors_event_t ;
141
138
142
139
/* Sensor details (40 bytes) */
@@ -155,17 +152,29 @@ typedef struct {
155
152
constant rate */
156
153
} sensor_t ;
157
154
155
+ /* * @brief Common sensor interface to unify various sensors.
156
+ * Intentionally modeled after sensors.h in the Android API:
157
+ * https://github.com/android/platform_hardware_libhardware/blob/master/include/hardware/sensors.h
158
+ */
158
159
class Adafruit_Sensor {
159
160
public:
160
161
// Constructor(s)
161
162
Adafruit_Sensor () {}
162
163
virtual ~Adafruit_Sensor () {}
163
164
164
165
// These must be defined by the subclass
166
+
167
+ /* ! @brief Whether we should automatically change the range (if possible) for
168
+ higher precision
169
+ @param enabled True if we will try to autorange */
165
170
virtual void enableAutoRange (bool enabled) {
166
171
(void )enabled; /* suppress unused warning */
167
172
};
173
+
174
+ /* ! @brief Get the latest sensor event
175
+ @returns True if able to fetch an event */
168
176
virtual bool getEvent (sensors_event_t *) = 0;
177
+ /* ! @brief Get info about the sensor itself */
169
178
virtual void getSensor (sensor_t *) = 0;
170
179
171
180
void printSensorDetails (void );
0 commit comments