Skip to content

Commit

Permalink
address #48
Browse files Browse the repository at this point in the history
  • Loading branch information
brentru committed Mar 3, 2023
1 parent a902f89 commit 1f527eb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Adafruit_Sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 9 additions & 5 deletions Adafruit_Sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) */
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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:

Expand Down

0 comments on commit 1f527eb

Please sign in to comment.