forked from adafruit/Adafruit_Sensor
bump & clang
This commit is contained in:
@ -1,50 +1,70 @@
|
|||||||
#include "Adafruit_Sensor.h"
|
#include "Adafruit_Sensor.h"
|
||||||
|
|
||||||
void Adafruit_Sensor::printSensorDetails(void)
|
void Adafruit_Sensor::printSensorDetails(void) {
|
||||||
{
|
|
||||||
sensor_t sensor;
|
sensor_t sensor;
|
||||||
getSensor(&sensor);
|
getSensor(&sensor);
|
||||||
Serial.println(F("------------------------------------"));
|
Serial.println(F("------------------------------------"));
|
||||||
Serial.print (F("Sensor: ")); Serial.println(sensor.name);
|
Serial.print(F("Sensor: "));
|
||||||
Serial.print (F("Type: "));
|
Serial.println(sensor.name);
|
||||||
switch((sensors_type_t)sensor.type) {
|
Serial.print(F("Type: "));
|
||||||
case SENSOR_TYPE_ACCELEROMETER:
|
switch ((sensors_type_t)sensor.type) {
|
||||||
Serial.print(F("Acceleration (m/s2)")); break;
|
case SENSOR_TYPE_ACCELEROMETER:
|
||||||
case SENSOR_TYPE_MAGNETIC_FIELD:
|
Serial.print(F("Acceleration (m/s2)"));
|
||||||
Serial.print(F("Magnetic (uT)")); break;
|
break;
|
||||||
case SENSOR_TYPE_ORIENTATION:
|
case SENSOR_TYPE_MAGNETIC_FIELD:
|
||||||
Serial.print(F("Orientation (degrees)")); break;
|
Serial.print(F("Magnetic (uT)"));
|
||||||
case SENSOR_TYPE_GYROSCOPE :
|
break;
|
||||||
Serial.print(F("Gyroscopic (rad/s)")); break;
|
case SENSOR_TYPE_ORIENTATION:
|
||||||
case SENSOR_TYPE_LIGHT :
|
Serial.print(F("Orientation (degrees)"));
|
||||||
Serial.print(F("Light (lux)")); break;
|
break;
|
||||||
case SENSOR_TYPE_PRESSURE :
|
case SENSOR_TYPE_GYROSCOPE:
|
||||||
Serial.print(F("Pressure (hPa)")); break;
|
Serial.print(F("Gyroscopic (rad/s)"));
|
||||||
case SENSOR_TYPE_PROXIMITY :
|
break;
|
||||||
Serial.print(F("Distance (cm)")); break;
|
case SENSOR_TYPE_LIGHT:
|
||||||
case SENSOR_TYPE_GRAVITY :
|
Serial.print(F("Light (lux)"));
|
||||||
Serial.print(F("Gravity (m/s2)")); break;
|
break;
|
||||||
case SENSOR_TYPE_LINEAR_ACCELERATION :
|
case SENSOR_TYPE_PRESSURE:
|
||||||
Serial.print(F("Linear Acceleration (m/s2)")); break;
|
Serial.print(F("Pressure (hPa)"));
|
||||||
case SENSOR_TYPE_ROTATION_VECTOR :
|
break;
|
||||||
Serial.print(F("Rotation vector")); break;
|
case SENSOR_TYPE_PROXIMITY:
|
||||||
case SENSOR_TYPE_RELATIVE_HUMIDITY :
|
Serial.print(F("Distance (cm)"));
|
||||||
Serial.print(F("Relative Humidity (%)")); break;
|
break;
|
||||||
case SENSOR_TYPE_AMBIENT_TEMPERATURE :
|
case SENSOR_TYPE_GRAVITY:
|
||||||
Serial.print(F("Ambient Temp (C)")); break;
|
Serial.print(F("Gravity (m/s2)"));
|
||||||
case SENSOR_TYPE_VOLTAGE :
|
break;
|
||||||
Serial.print(F("Voltage (V)")); break;
|
case SENSOR_TYPE_LINEAR_ACCELERATION:
|
||||||
case SENSOR_TYPE_CURRENT :
|
Serial.print(F("Linear Acceleration (m/s2)"));
|
||||||
Serial.print(F("Current (mA)")); break;
|
break;
|
||||||
case SENSOR_TYPE_COLOR :
|
case SENSOR_TYPE_ROTATION_VECTOR:
|
||||||
Serial.print(F("Color (RGBA)")); break;
|
Serial.print(F("Rotation vector"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_RELATIVE_HUMIDITY:
|
||||||
|
Serial.print(F("Relative Humidity (%)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_AMBIENT_TEMPERATURE:
|
||||||
|
Serial.print(F("Ambient Temp (C)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_VOLTAGE:
|
||||||
|
Serial.print(F("Voltage (V)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_CURRENT:
|
||||||
|
Serial.print(F("Current (mA)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_COLOR:
|
||||||
|
Serial.print(F("Color (RGBA)"));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
|
Serial.print(F("Driver Ver: "));
|
||||||
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
|
Serial.println(sensor.version);
|
||||||
Serial.print (F("Min Value: ")); Serial.println(sensor.min_value);
|
Serial.print(F("Unique ID: "));
|
||||||
Serial.print (F("Max Value: ")); Serial.println(sensor.max_value);
|
Serial.println(sensor.sensor_id);
|
||||||
Serial.print (F("Resolution: ")); Serial.println(sensor.resolution);
|
Serial.print(F("Min Value: "));
|
||||||
|
Serial.println(sensor.min_value);
|
||||||
|
Serial.print(F("Max Value: "));
|
||||||
|
Serial.println(sensor.max_value);
|
||||||
|
Serial.print(F("Resolution: "));
|
||||||
|
Serial.println(sensor.resolution);
|
||||||
Serial.println(F("------------------------------------\n"));
|
Serial.println(F("------------------------------------\n"));
|
||||||
}
|
}
|
||||||
|
@ -1,160 +1,176 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2008 The Android Open Source Project
|
* Copyright (C) 2008 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software< /span>
|
* Unless required by applicable law or agreed to in writing, software< /span>
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Update by K. Townsend (Adafruit Industries) for lighter typedefs, and
|
/* Update by K. Townsend (Adafruit Industries) for lighter typedefs, and
|
||||||
* extended sensor support to include color, voltage and current */
|
* extended sensor support to include color, voltage and current */
|
||||||
|
|
||||||
#ifndef _ADAFRUIT_SENSOR_H
|
#ifndef _ADAFRUIT_SENSOR_H
|
||||||
#define _ADAFRUIT_SENSOR_H
|
#define _ADAFRUIT_SENSOR_H
|
||||||
|
|
||||||
#ifndef ARDUINO
|
#ifndef ARDUINO
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#elif ARDUINO >= 100
|
#elif ARDUINO >= 100
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "Print.h"
|
#include "Print.h"
|
||||||
#else
|
#else
|
||||||
#include "WProgram.h"
|
#include "WProgram.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Intentionally modeled after sensors.h in the Android API:
|
/* Intentionally modeled after sensors.h in the Android API:
|
||||||
* https://github.com/android/platform_hardware_libhardware/blob/master/include/hardware/sensors.h */
|
* https://github.com/android/platform_hardware_libhardware/blob/master/include/hardware/sensors.h
|
||||||
|
*/
|
||||||
|
|
||||||
/* Constants */
|
/* Constants */
|
||||||
#define SENSORS_GRAVITY_EARTH (9.80665F) /**< Earth's gravity in m/s^2 */
|
#define SENSORS_GRAVITY_EARTH (9.80665F) /**< Earth's gravity in m/s^2 */
|
||||||
#define SENSORS_GRAVITY_MOON (1.6F) /**< The moon's gravity in m/s^2 */
|
#define SENSORS_GRAVITY_MOON (1.6F) /**< The moon's gravity in m/s^2 */
|
||||||
#define SENSORS_GRAVITY_SUN (275.0F) /**< The sun's gravity in m/s^2 */
|
#define SENSORS_GRAVITY_SUN (275.0F) /**< The sun's gravity in m/s^2 */
|
||||||
#define SENSORS_GRAVITY_STANDARD (SENSORS_GRAVITY_EARTH)
|
#define SENSORS_GRAVITY_STANDARD (SENSORS_GRAVITY_EARTH)
|
||||||
#define SENSORS_MAGFIELD_EARTH_MAX (60.0F) /**< Maximum magnetic field on Earth's surface */
|
#define SENSORS_MAGFIELD_EARTH_MAX \
|
||||||
#define SENSORS_MAGFIELD_EARTH_MIN (30.0F) /**< Minimum magnetic field on Earth's surface */
|
(60.0F) /**< Maximum magnetic field on Earth's surface */
|
||||||
#define SENSORS_PRESSURE_SEALEVELHPA (1013.25F) /**< Average sea level pressure is 1013.25 hPa */
|
#define SENSORS_MAGFIELD_EARTH_MIN \
|
||||||
#define SENSORS_DPS_TO_RADS (0.017453293F) /**< Degrees/s to rad/s multiplier */
|
(30.0F) /**< Minimum magnetic field on Earth's surface */
|
||||||
#define SENSORS_GAUSS_TO_MICROTESLA (100) /**< Gauss to micro-Tesla multiplier */
|
#define SENSORS_PRESSURE_SEALEVELHPA \
|
||||||
|
(1013.25F) /**< Average sea level pressure is 1013.25 hPa */
|
||||||
|
#define SENSORS_DPS_TO_RADS (0.017453293F) /**< Degrees/s to rad/s multiplier \
|
||||||
|
*/
|
||||||
|
#define SENSORS_GAUSS_TO_MICROTESLA \
|
||||||
|
(100) /**< Gauss to micro-Tesla multiplier */
|
||||||
|
|
||||||
/** Sensor types */
|
/** Sensor types */
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
SENSOR_TYPE_ACCELEROMETER = (1), /**< Gravity + linear acceleration */
|
||||||
SENSOR_TYPE_ACCELEROMETER = (1), /**< Gravity + linear acceleration */
|
SENSOR_TYPE_MAGNETIC_FIELD = (2),
|
||||||
SENSOR_TYPE_MAGNETIC_FIELD = (2),
|
SENSOR_TYPE_ORIENTATION = (3),
|
||||||
SENSOR_TYPE_ORIENTATION = (3),
|
SENSOR_TYPE_GYROSCOPE = (4),
|
||||||
SENSOR_TYPE_GYROSCOPE = (4),
|
SENSOR_TYPE_LIGHT = (5),
|
||||||
SENSOR_TYPE_LIGHT = (5),
|
SENSOR_TYPE_PRESSURE = (6),
|
||||||
SENSOR_TYPE_PRESSURE = (6),
|
SENSOR_TYPE_PROXIMITY = (8),
|
||||||
SENSOR_TYPE_PROXIMITY = (8),
|
SENSOR_TYPE_GRAVITY = (9),
|
||||||
SENSOR_TYPE_GRAVITY = (9),
|
SENSOR_TYPE_LINEAR_ACCELERATION =
|
||||||
SENSOR_TYPE_LINEAR_ACCELERATION = (10), /**< Acceleration not including gravity */
|
(10), /**< Acceleration not including gravity */
|
||||||
SENSOR_TYPE_ROTATION_VECTOR = (11),
|
SENSOR_TYPE_ROTATION_VECTOR = (11),
|
||||||
SENSOR_TYPE_RELATIVE_HUMIDITY = (12),
|
SENSOR_TYPE_RELATIVE_HUMIDITY = (12),
|
||||||
SENSOR_TYPE_AMBIENT_TEMPERATURE = (13),
|
SENSOR_TYPE_AMBIENT_TEMPERATURE = (13),
|
||||||
SENSOR_TYPE_OBJECT_TEMPERATURE = (14),
|
SENSOR_TYPE_OBJECT_TEMPERATURE = (14),
|
||||||
SENSOR_TYPE_VOLTAGE = (15),
|
SENSOR_TYPE_VOLTAGE = (15),
|
||||||
SENSOR_TYPE_CURRENT = (16),
|
SENSOR_TYPE_CURRENT = (16),
|
||||||
SENSOR_TYPE_COLOR = (17)
|
SENSOR_TYPE_COLOR = (17)
|
||||||
} sensors_type_t;
|
} sensors_type_t;
|
||||||
|
|
||||||
/** struct sensors_vec_s is used to return a vector in a common format. */
|
/** struct sensors_vec_s is used to return a vector in a common format. */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
union {
|
union {
|
||||||
float v[3];
|
float v[3];
|
||||||
struct {
|
struct {
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
float z;
|
float z;
|
||||||
};
|
|
||||||
/* Orientation sensors */
|
|
||||||
struct {
|
|
||||||
float roll; /**< Rotation around the longitudinal axis (the plane body, 'X axis'). Roll is positive and increasing when moving downward. -90°<=roll<=90° */
|
|
||||||
float pitch; /**< Rotation around the lateral axis (the wing span, 'Y axis'). Pitch is positive and increasing when moving upwards. -180°<=pitch<=180°) */
|
|
||||||
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° */
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
int8_t status;
|
/* Orientation sensors */
|
||||||
uint8_t reserved[3];
|
struct {
|
||||||
|
float roll; /**< Rotation around the longitudinal axis (the plane body, 'X
|
||||||
|
axis'). Roll is positive and increasing when moving
|
||||||
|
downward. -90°<=roll<=90° */
|
||||||
|
float pitch; /**< Rotation around the lateral axis (the wing span, 'Y
|
||||||
|
axis'). Pitch is positive and increasing when moving
|
||||||
|
upwards. -180°<=pitch<=180°) */
|
||||||
|
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° */
|
||||||
|
};
|
||||||
|
};
|
||||||
|
int8_t status;
|
||||||
|
uint8_t reserved[3];
|
||||||
} sensors_vec_t;
|
} sensors_vec_t;
|
||||||
|
|
||||||
/** struct sensors_color_s is used to return color data in a common format. */
|
/** struct sensors_color_s is used to return color data in a common format. */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
union {
|
union {
|
||||||
float c[3];
|
float c[3];
|
||||||
/* RGB color space */
|
/* RGB color space */
|
||||||
struct {
|
struct {
|
||||||
float r; /**< Red component */
|
float r; /**< Red component */
|
||||||
float g; /**< Green component */
|
float g; /**< Green component */
|
||||||
float b; /**< Blue component */
|
float b; /**< Blue component */
|
||||||
};
|
|
||||||
};
|
};
|
||||||
uint32_t rgba; /**< 24-bit RGBA value */
|
};
|
||||||
|
uint32_t rgba; /**< 24-bit RGBA value */
|
||||||
} sensors_color_t;
|
} sensors_color_t;
|
||||||
|
|
||||||
/* Sensor event (36 bytes) */
|
/* Sensor event (36 bytes) */
|
||||||
/** struct sensor_event_s is used to provide a single sensor event in a common format. */
|
/** struct sensor_event_s is used to provide a single sensor event in a common
|
||||||
typedef struct
|
* format. */
|
||||||
{
|
typedef struct {
|
||||||
int32_t version; /**< must be sizeof(struct sensors_event_t) */
|
int32_t version; /**< must be sizeof(struct sensors_event_t) */
|
||||||
int32_t sensor_id; /**< unique sensor identifier */
|
int32_t sensor_id; /**< unique sensor identifier */
|
||||||
int32_t type; /**< sensor type */
|
int32_t type; /**< sensor type */
|
||||||
int32_t reserved0; /**< reserved */
|
int32_t reserved0; /**< reserved */
|
||||||
int32_t timestamp; /**< time is in milliseconds */
|
int32_t timestamp; /**< time is in milliseconds */
|
||||||
union
|
union {
|
||||||
{
|
float data[4];
|
||||||
float data[4];
|
sensors_vec_t acceleration; /**< acceleration values are in meter per second
|
||||||
sensors_vec_t acceleration; /**< acceleration values are in meter per second per second (m/s^2) */
|
per second (m/s^2) */
|
||||||
sensors_vec_t magnetic; /**< magnetic vector values are in micro-Tesla (uT) */
|
sensors_vec_t
|
||||||
sensors_vec_t orientation; /**< orientation values are in degrees */
|
magnetic; /**< magnetic vector values are in micro-Tesla (uT) */
|
||||||
sensors_vec_t gyro; /**< gyroscope values are in rad/s */
|
sensors_vec_t orientation; /**< orientation values are in degrees */
|
||||||
float temperature; /**< temperature is in degrees centigrade (Celsius) */
|
sensors_vec_t gyro; /**< gyroscope values are in rad/s */
|
||||||
float distance; /**< distance in centimeters */
|
float temperature; /**< temperature is in degrees centigrade (Celsius) */
|
||||||
float light; /**< light in SI lux units */
|
float distance; /**< distance in centimeters */
|
||||||
float pressure; /**< pressure in hectopascal (hPa) */
|
float light; /**< light in SI lux units */
|
||||||
float relative_humidity; /**< relative humidity in percent */
|
float pressure; /**< pressure in hectopascal (hPa) */
|
||||||
float current; /**< current in milliamps (mA) */
|
float relative_humidity; /**< relative humidity in percent */
|
||||||
float voltage; /**< voltage in volts (V) */
|
float current; /**< current in milliamps (mA) */
|
||||||
sensors_color_t color; /**< color in RGB component values */
|
float voltage; /**< voltage in volts (V) */
|
||||||
};
|
sensors_color_t color; /**< color in RGB component values */
|
||||||
|
};
|
||||||
} sensors_event_t;
|
} sensors_event_t;
|
||||||
|
|
||||||
/* Sensor details (40 bytes) */
|
/* Sensor details (40 bytes) */
|
||||||
/** struct sensor_s is used to describe basic information about a specific sensor. */
|
/** struct sensor_s is used to describe basic information about a specific
|
||||||
typedef struct
|
* sensor. */
|
||||||
{
|
typedef struct {
|
||||||
char name[12]; /**< sensor name */
|
char name[12]; /**< sensor name */
|
||||||
int32_t version; /**< version of the hardware + driver */
|
int32_t version; /**< version of the hardware + driver */
|
||||||
int32_t sensor_id; /**< unique sensor identifier */
|
int32_t sensor_id; /**< unique sensor identifier */
|
||||||
int32_t type; /**< this sensor's type (ex. SENSOR_TYPE_LIGHT) */
|
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 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 min_value; /**< minimum value of this sensor's value in SI units */
|
||||||
float resolution; /**< smallest difference between two values reported by this sensor */
|
float resolution; /**< smallest difference between two values reported by this
|
||||||
int32_t min_delay; /**< min delay in microseconds between events. zero = not a constant rate */
|
sensor */
|
||||||
|
int32_t min_delay; /**< min delay in microseconds between events. zero = not a
|
||||||
|
constant rate */
|
||||||
} sensor_t;
|
} sensor_t;
|
||||||
|
|
||||||
class Adafruit_Sensor {
|
class Adafruit_Sensor {
|
||||||
public:
|
public:
|
||||||
// Constructor(s)
|
// Constructor(s)
|
||||||
Adafruit_Sensor() {}
|
Adafruit_Sensor() {}
|
||||||
virtual ~Adafruit_Sensor() {}
|
virtual ~Adafruit_Sensor() {}
|
||||||
|
|
||||||
// These must be defined by the subclass
|
// These must be defined by the subclass
|
||||||
virtual void enableAutoRange(bool enabled) { (void)enabled; /* suppress unused warning */ };
|
virtual void enableAutoRange(bool enabled) {
|
||||||
virtual bool getEvent(sensors_event_t*) = 0;
|
(void)enabled; /* suppress unused warning */
|
||||||
virtual void getSensor(sensor_t*) = 0;
|
};
|
||||||
|
virtual bool getEvent(sensors_event_t *) = 0;
|
||||||
|
virtual void getSensor(sensor_t *) = 0;
|
||||||
|
|
||||||
void printSensorDetails(void);
|
void printSensorDetails(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _autoRange;
|
bool _autoRange;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=Adafruit Unified Sensor
|
name=Adafruit Unified Sensor
|
||||||
version=1.0.3
|
version=1.1.0
|
||||||
author=Adafruit <info@adafruit.com>
|
author=Adafruit <info@adafruit.com>
|
||||||
maintainer=Adafruit <info@adafruit.com>
|
maintainer=Adafruit <info@adafruit.com>
|
||||||
sentence=Required for all Adafruit Unified Sensor based libraries.
|
sentence=Required for all Adafruit Unified Sensor based libraries.
|
||||||
|
Reference in New Issue
Block a user