Skip to content

Commit 6bc09d6

Browse files
authored
Merge pull request #50 from brentru/add-more-units
Add sensor types for gas resistance and unitless percentage
2 parents 716fa39 + 3423c95 commit 6bc09d6

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

Adafruit_Sensor.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ void Adafruit_Sensor::printSensorDetails(void) {
9494
case SENSOR_TYPE_PM100_ENV:
9595
Serial.print(F("Environmental Particulate Matter 100 (ppm)"));
9696
break;
97+
case SENSOR_TYPE_GAS_RESISTANCE:
98+
Serial.print(F("Gas Resistance (ohms)"));
99+
break;
100+
case SENSOR_TYPE_UNITLESS_PERCENT:
101+
Serial.print(F("Unitless Percent (%)"));
102+
break;
97103
}
98104

99105
Serial.println();

Adafruit_Sensor.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ typedef enum {
7777
SENSOR_TYPE_PM100_STD = (25),
7878
SENSOR_TYPE_PM10_ENV = (26),
7979
SENSOR_TYPE_PM25_ENV = (27),
80-
SENSOR_TYPE_PM100_ENV = (28)
80+
SENSOR_TYPE_PM100_ENV = (28),
81+
SENSOR_TYPE_GAS_RESISTANCE = (29),
82+
SENSOR_TYPE_UNITLESS_PERCENT = (30)
8183
} sensors_type_t;
8284

8385
/** struct sensors_vec_s is used to return a vector in a common format. */
@@ -131,7 +133,7 @@ typedef struct {
131133
int32_t reserved0; /**< reserved */
132134
int32_t timestamp; /**< time is in milliseconds */
133135
union {
134-
float data[4]; ///< Raw data
136+
float data[4]; ///< Raw data */
135137
sensors_vec_t acceleration; /**< acceleration values are in meter per second
136138
per second (m/s^2) */
137139
sensors_vec_t
@@ -163,10 +165,13 @@ typedef struct {
163165
million (ppm) */
164166
float pm25_env; /**< Environmental Particulate Matter 2.5 in parts per
165167
million (ppm) */
166-
float pm100_env; /**< EnvironmentalParticulate Matter 100 in parts per
168+
float pm100_env; /**< Environmental Particulate Matter 100 in parts per
167169
million (ppm) */
168-
sensors_color_t color; /**< color in RGB component values */
169-
}; ///< Union for the wide ranges of data we can carry
170+
float gas_resistance; /**< Proportional to the amount of VOC particles in
171+
the air (Ohms) */
172+
float unitless_percent; /**<Percentage, unit-less (%) */
173+
sensors_color_t color; /**< color in RGB component values */
174+
}; ///< Union for the wide ranges of data we can carry
170175
} sensors_event_t;
171176

172177
/* Sensor details (40 bytes) */

README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ typedef enum
8585
SENSOR_TYPE_PM100_STD = (25),
8686
SENSOR_TYPE_PM10_ENV = (26),
8787
SENSOR_TYPE_PM25_ENV = (27),
88-
SENSOR_TYPE_PM100_ENV = (28)
88+
SENSOR_TYPE_PM100_ENV = (28),
89+
SENSOR_TYPE_GAS_RESISTANCE = (29),
90+
SENSOR_TYPE_UNITLESS_PERCENT = (30)
8991
} sensors_type_t;
9092
```
9193

@@ -159,6 +161,8 @@ typedef struct
159161
float pm10_env,
160162
float pm25_env,
161163
float pm100_env,
164+
float gas_resistance,
165+
float unitless_percent,
162166
sensors_color_t color;
163167
};
164168
} sensors_event_t;
@@ -187,7 +191,7 @@ Calling this function will provide some basic information about the sensor (the
187191

188192
## Standardised SI values for `sensors_event_t`
189193

190-
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:
194+
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:
191195

192196
- **acceleration**: values are in **meter per second per second** (m/s^2)
193197
- **magnetic**: values are in **micro-Tesla** (uT)
@@ -204,20 +208,22 @@ A key part of the abstraction layer is the standardisation of values on SI units
204208
- **tvoc**: values are in **parts per billion** (ppb)
205209
- **voc_index**: values are an **index** from 1-500 with 100 being normal
206210
- **nox_index**: values are an **index** from 1-500 with 100 being normal
207-
- **CO2**: values are in **parts per million*** (ppm)
208-
- **eCO2**: values are in **parts per million*** (ppm)
209-
- **pm10_std**: values are in **parts per million*** (ppm)
210-
- **pm25_std**: values are in **parts per million*** (ppm)
211-
- **pm100_std**: values are in **parts per million*** (ppm)
212-
- **pm10_env**: values are in **parts per million*** (ppm)
213-
- **pm25_env**: values are in **parts per million*** (ppm)
214-
- **pm100_env**: values are in **parts per million*** (ppm)
211+
- **CO2**: values are in **parts per million** (ppm)
212+
- **eCO2**: values are in **parts per million** (ppm)
213+
- **pm10_std**: values are in **parts per million** (ppm)
214+
- **pm25_std**: values are in **parts per million** (ppm)
215+
- **pm100_std**: values are in **parts per million** (ppm)
216+
- **pm10_env**: values are in **parts per million** (ppm)
217+
- **pm25_env**: values are in **parts per million** (ppm)
218+
- **pm100_env**: values are in **parts per million** (ppm)
219+
- **gas_resistance**: values are in **ohms**
220+
- **unitless_percent**: values are in **%**
215221

216222
## The Unified Driver Abstraction Layer in Practice ##
217223

218224
Using the unified sensor abstraction layer is relatively easy once a compliant driver has been created.
219225

220-
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).
226+
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).
221227

222228
An example of reading the [TSL2561](https://github.com/adafruit/Adafruit_TSL2561) light sensor can be seen below:
223229

0 commit comments

Comments
 (0)