mirror of
https://github.com/adafruit/Adafruit_Sensor.git
synced 2025-07-31 23:54:26 +02:00
First commit
This commit is contained in:
23
Adafruit_Sensor.cpp
Normal file
23
Adafruit_Sensor.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "Adafruit_Sensor.h"
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
void Adafruit_Sensor::constructor() {
|
||||
}
|
||||
|
||||
size_t Adafruit_Sensor::serializeSensor(sensor_t sensor) {
|
||||
}
|
||||
|
||||
size_t Adafruit_Sensor::serializeEvent(sensors_event_t event) {
|
||||
}
|
||||
|
||||
size_t Adafruit_Sensor::logSensor(sensor_t sensor) {
|
||||
}
|
||||
|
||||
size_t Adafruit_Sensor::logEvent(sensors_event_t event) {
|
||||
}
|
||||
|
||||
int32_t Adafruit_Sensor::average(int32_t values[], const size_t len) {
|
||||
}
|
||||
|
||||
float Adafruit_Sensor::average(float values[], const size_t len) {
|
||||
}
|
111
Adafruit_Sensor.h
Normal file
111
Adafruit_Sensor.h
Normal file
@@ -0,0 +1,111 @@
|
||||
#ifndef _ADAFRUIT_SENSOR_H
|
||||
#define _ADAFRUIT_SENSOR_H
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#include "Print.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
/** Sensor types */
|
||||
typedef enum
|
||||
{
|
||||
SENSOR_TYPE_ACCELEROMETER = (1), /**< Gravity + linear acceleration */
|
||||
SENSOR_TYPE_MAGNETIC_FIELD = (2),
|
||||
SENSOR_TYPE_ORIENTATION = (3),
|
||||
SENSOR_TYPE_GYROSCOPE = (4),
|
||||
SENSOR_TYPE_LIGHT = (5),
|
||||
SENSOR_TYPE_PRESSURE = (6),
|
||||
SENSOR_TYPE_PROXIMITY = (8),
|
||||
SENSOR_TYPE_GRAVITY = (9),
|
||||
SENSOR_TYPE_LINEAR_ACCELERATION = (10), /**< Acceleration not including gravity */
|
||||
SENSOR_TYPE_ROTATION_VECTOR = (11),
|
||||
SENSOR_TYPE_RELATIVE_HUMIDITY = (12),
|
||||
SENSOR_TYPE_AMBIENT_TEMPERATURE = (13),
|
||||
SENSOR_TYPE_VOLTAGE = (15),
|
||||
SENSOR_TYPE_CURRENT = (16)
|
||||
} sensors_type_t;
|
||||
|
||||
/** struct sensors_vec_s is used to return a vector in a common format. */
|
||||
typedef struct {
|
||||
union {
|
||||
float v[3];
|
||||
struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
};
|
||||
/* Orientation sensors */
|
||||
struct {
|
||||
float azimuth; /**< Angle between the magnetic north direction and the Y axis, around the Z axis (0<=azimuth<360). 0=North, 90=East, 180=South, 270=West */
|
||||
float pitch; /**< Rotation around X axis (-180<=pitch<=180), with positive values when the z-axis moves toward the y-axis. */
|
||||
float roll; /**< Rotation around Y axis (-90<=roll<=90), with positive values when the x-axis moves towards the z-axis. */
|
||||
};
|
||||
};
|
||||
int8_t status;
|
||||
uint8_t reserved[3];
|
||||
} sensors_vec_t;
|
||||
|
||||
/* Sensor event (52 bytes) */
|
||||
/** struct sensor_event_s is used to provide a single sensor event in a common format. */
|
||||
typedef struct
|
||||
{
|
||||
int32_t version; /**< must be sizeof(struct sensors_event_t) */
|
||||
int32_t sensor_id; /**< unique sensor identifier */
|
||||
int32_t type; /**< sensor type */
|
||||
int32_t reserved0; /**< reserved */
|
||||
int32_t timestamp; /**< time is in milliseconds */
|
||||
union
|
||||
{
|
||||
float data[4];
|
||||
sensors_vec_t acceleration; /**< acceleration values are in meter per second per second (m/s^2) */
|
||||
sensors_vec_t magnetic; /**< magnetic vector values are in micro-Tesla (uT) */
|
||||
sensors_vec_t orientation; /**< orientation values are in degrees */
|
||||
sensors_vec_t gyro; /**< gyroscope values are in rad/s */
|
||||
float temperature; /**< temperature is in degrees centigrade (Celsius) */
|
||||
float distance; /**< distance in centimeters */
|
||||
float light; /**< light in SI lux units */
|
||||
float pressure; /**< pressure in hectopascal (hPa) */
|
||||
float relative_humidity; /**< relative humidity in percent */
|
||||
float current; /**< current in milliamps (mA) */
|
||||
float voltage; /**< voltage in volts (V) */
|
||||
};
|
||||
uint32_t reserved1[4];
|
||||
} sensors_event_t;
|
||||
|
||||
/* Sensor details (56 bytes) */
|
||||
/** struct sensor_s is used to describe basic information about a specific sensor. */
|
||||
typedef struct
|
||||
{
|
||||
char name[12]; /**< sensor name */
|
||||
int32_t version; /**< version of the hardware + driver */
|
||||
int32_t sensor_id; /**< unique sensor identifier */
|
||||
int32_t type; /**< this sensor's type (ex. SENSOR_TYPE_LIGHT) */
|
||||
float max_value; /**< maximum value of this sensor's value in SI units */
|
||||
float min_value; /**< minimum value of this sensor's value in SI units */
|
||||
float resolution; /**< smallest difference between two values reported by this sensor */
|
||||
int32_t min_delay; /**< min delay in microseconds between events. zero = not a constant rate */
|
||||
void* reserved[4]; /**< reserved fields, must be zero */
|
||||
} sensor_t;
|
||||
|
||||
class Adafruit_Sensor {
|
||||
public:
|
||||
// Constructor(s)
|
||||
// Adafruit_Sensor();
|
||||
void constructor();
|
||||
|
||||
// These must be defined by the subclass
|
||||
virtual void getEvent(sensors_event_t*);
|
||||
virtual void getSensor(sensor_t*);
|
||||
|
||||
// These helper functions are defined in Adafruit_Sensor.cpp
|
||||
size_t serializeSensor(sensor_t);
|
||||
size_t serializeEvent(sensors_event_t);
|
||||
size_t logSensor(sensor_t);
|
||||
size_t logEvent(sensors_event_t);
|
||||
int32_t average(int32_t values[], const size_t len);
|
||||
float average(float values[], const size_t len);
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user