mirror of
https://github.com/adafruit/Adafruit_Sensor.git
synced 2025-08-02 16:44:27 +02:00
This commit is contained in:
@@ -97,6 +97,9 @@ void Adafruit_Sensor::printSensorDetails(void) {
|
||||
case SENSOR_TYPE_GAS_RESISTANCE:
|
||||
Serial.print(F("Gas Resistance (ohms)"));
|
||||
break;
|
||||
case SENSOR_TYPE_UNITLESS_PERCENT:
|
||||
Serial.print(F("Unitless Percent (%)"));
|
||||
break;
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
|
@@ -79,6 +79,8 @@ typedef enum {
|
||||
SENSOR_TYPE_PM25_ENV = (27),
|
||||
SENSOR_TYPE_PM100_ENV = (28),
|
||||
SENSOR_TYPE_GAS_RESISTANCE = (29),
|
||||
SENSOR_TYPE_LUX = (30),
|
||||
SENSOR_TYPE_UNITLESS_PERCENT = (31)
|
||||
} sensors_type_t;
|
||||
|
||||
/** struct sensors_vec_s is used to return a vector in a common format. */
|
||||
@@ -132,7 +134,7 @@ typedef struct {
|
||||
int32_t reserved0; /**< reserved */
|
||||
int32_t timestamp; /**< time is in milliseconds */
|
||||
union {
|
||||
float data[4]; ///< Raw data
|
||||
float data[4]; ///< Raw data */
|
||||
sensors_vec_t acceleration; /**< acceleration values are in meter per second
|
||||
per second (m/s^2) */
|
||||
sensors_vec_t
|
||||
@@ -166,10 +168,12 @@ typedef struct {
|
||||
million (ppm) */
|
||||
float pm100_env; /**< Environmental Particulate Matter 100 in parts per
|
||||
million (ppm) */
|
||||
float gas_resistance; /**< Proportional to the amount of VOC particles in
|
||||
the air (Ohms) */
|
||||
sensors_color_t color; /**< color in RGB component values */
|
||||
}; ///< Union for the wide ranges of data we can carry
|
||||
float gas_resistance; /**< Proportional to the amount of VOC particles in
|
||||
the air (Ohms) */
|
||||
float lux; /**< SI lux (Lux) */
|
||||
float unitless_percent; /**<Percentage, unit-less (%) */
|
||||
sensors_color_t color; /**< color in RGB component values */
|
||||
}; ///< Union for the wide ranges of data we can carry
|
||||
} sensors_event_t;
|
||||
|
||||
/* Sensor details (40 bytes) */
|
||||
|
@@ -161,6 +161,7 @@ typedef struct
|
||||
float pm25_env,
|
||||
float pm100_env,
|
||||
float gas_resistance,
|
||||
float unitless_percent,
|
||||
sensors_color_t color;
|
||||
};
|
||||
} sensors_event_t;
|
||||
@@ -189,7 +190,7 @@ Calling this function will provide some basic information about the sensor (the
|
||||
|
||||
## Standardised SI values for `sensors_event_t`
|
||||
|
||||
A key part of the abstraction layer is the standardisation of values on SI units of a particular scale, which is accomplished via the data[4] union in sensors\_event\_t above. This 16 byte union includes fields for each main sensor type, and uses the following SI units and scales:
|
||||
A key part of the abstraction layer is the standardization of values on SI units of a particular scale, which is accomplished via the data[4] union in sensors\_event\_t above. This 16 byte union includes fields for each main sensor type, and uses the following SI units and scales:
|
||||
|
||||
- **acceleration**: values are in **meter per second per second** (m/s^2)
|
||||
- **magnetic**: values are in **micro-Tesla** (uT)
|
||||
@@ -215,12 +216,13 @@ A key part of the abstraction layer is the standardisation of values on SI units
|
||||
- **pm25_env**: values are in **parts per million** (ppm)
|
||||
- **pm100_env**: values are in **parts per million** (ppm)
|
||||
- **gas_resistance**: values are in **ohms**
|
||||
- **unitless_percent**: values are in **%**
|
||||
|
||||
## The Unified Driver Abstraction Layer in Practice ##
|
||||
|
||||
Using the unified sensor abstraction layer is relatively easy once a compliant driver has been created.
|
||||
|
||||
Every compliant sensor can now be read using a single, well-known 'type' (sensors\_event\_t), and there is a standardised way of interrogating a sensor about its specific capabilities (via sensor\_t).
|
||||
Every compliant sensor can now be read using a single, well-known 'type' (sensors\_event\_t), and there is a standardized way of interrogating a sensor about its specific capabilities (via sensor\_t).
|
||||
|
||||
An example of reading the [TSL2561](https://github.com/adafruit/Adafruit_TSL2561) light sensor can be seen below:
|
||||
|
||||
|
Reference in New Issue
Block a user