Skip to content

Commit

Permalink
Add support for BME680
Browse files Browse the repository at this point in the history
  • Loading branch information
ruimarinho committed Jul 4, 2020
1 parent 009bdf0 commit 3ee3892
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 3 deletions.
3 changes: 3 additions & 0 deletions code/espurna/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ PROGMEM const char espurna_sensors[] =
#if BMX280_SUPPORT
"BMX280 "
#endif
#if BME680_SUPPORT
"BME680 "
#endif
#if CSE7766_SUPPORT
"CSE7766 "
#endif
Expand Down
1 change: 1 addition & 0 deletions code/espurna/config/arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
//#define BH1750_SUPPORT 1
//#define BMP180_SUPPORT 1
//#define BMX280_SUPPORT 1
//#define BME680_SUPPORT 1
//#define CSE7766_SUPPORT 1
//#define DALLAS_SUPPORT 1
//#define DHT_SUPPORT 1
Expand Down
15 changes: 15 additions & 0 deletions code/espurna/config/sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,19 @@
#define SI1145_ADDRESS 0x60
#endif

//------------------------------------------------------------------------------
// BME680
// Enable support by passing BME680_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef BME680_SUPPORT
#define BME680_SUPPORT 0
#endif

#ifndef BME680_I2C_ADDRESS
#define BME680_I2C_ADDRESS 0x00 // 0x00 means auto
#endif

// -----------------------------------------------------------------------------
// ADC
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -1356,6 +1369,7 @@
BH1750_SUPPORT || \
BMP180_SUPPORT || \
BMX280_SUPPORT || \
BME680_SUPPORT || \
EMON_ADC121_SUPPORT || \
EMON_ADS1X15_SUPPORT || \
SHT3X_I2C_SUPPORT || \
Expand Down Expand Up @@ -1391,6 +1405,7 @@
ANALOG_SUPPORT || \
BH1750_SUPPORT || \
BMP180_SUPPORT || \
BME680_SUPPORT || \
BMX280_SUPPORT || \
CSE7766_SUPPORT || \
DALLAS_SUPPORT || \
Expand Down
8 changes: 7 additions & 1 deletion code/espurna/config/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@
#define SENSOR_SI1145_ID 39
#define SENSOR_HDC1080_ID 40
#define SENSOR_PZEM004TV30_ID 41
#define SENSOR_BME680_ID 42

//--------------------------------------------------------------------------------
// Magnitudes
Expand Down Expand Up @@ -370,8 +371,13 @@
#define MAGNITUDE_RESISTANCE 30
#define MAGNITUDE_PH 31
#define MAGNITUDE_FREQUENCY 32
#define MAGNITUDE_CO2E 33
#define MAGNITUDE_IAQ 34
#define MAGNITUDE_IAQ_ACCURACY 35
#define MAGNITUDE_STATIC_IAQ 36
#define MAGNITUDE_BVOC 37

#define MAGNITUDE_MAX 33
#define MAGNITUDE_MAX 38

#define SENSOR_ERROR_OK 0 // No error
#define SENSOR_ERROR_OUT_OF_RANGE 1 // Result out of sensor range
Expand Down
48 changes: 48 additions & 0 deletions code/espurna/sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include "sensors/BMX280Sensor.h"
#endif

#if BME680_SUPPORT
#include "sensors/BME680Sensor.h"
#endif

#if CSE7766_SUPPORT
#include "sensors/CSE7766Sensor.h"
#endif
Expand Down Expand Up @@ -515,6 +519,8 @@ sensor_magnitude_t::sensor_magnitude_t(unsigned char slot, unsigned char index_l
++_counts[type];

switch (type) {
case MAGNITUDE_IAQ:
case MAGNITUDE_STATIC_IAQ:
case MAGNITUDE_ENERGY:
filter = new LastFilter();
break;
Expand Down Expand Up @@ -639,6 +645,21 @@ String magnitudeTopic(unsigned char type) {
case MAGNITUDE_CO2:
result = F("co2");
break;
case MAGNITUDE_CO2E:
result = F("co2e");
break;
case MAGNITUDE_BVOC:
result = F("bvoc");
break;
case MAGNITUDE_IAQ:
result = F("iaq");
break;
case MAGNITUDE_IAQ_ACCURACY:
result = F("iaq_accuracy");
break;
case MAGNITUDE_STATIC_IAQ:
result = F("static_iaq");
break;
case MAGNITUDE_LUX:
result = F("lux");
break;
Expand Down Expand Up @@ -925,6 +946,11 @@ const char * const _magnitudeSettingsPrefix(unsigned char type) {
case MAGNITUDE_PM2dot5: return "pm1dot5";
case MAGNITUDE_PM10: return "pm10";
case MAGNITUDE_CO2: return "co2";
case MAGNITUDE_CO2E: return "co2e";
case MAGNITUDE_BVOC: return "bvoc";
case MAGNITUDE_IAQ: return "iaq";
case MAGNITUDE_IAQ_ACCURACY: return "iaqAccuracy";
case MAGNITUDE_STATIC_IAQ: return "staticIaq";
case MAGNITUDE_LUX: return "lux";
case MAGNITUDE_UVA: return "uva";
case MAGNITUDE_UVB: return "uvb";
Expand Down Expand Up @@ -1153,6 +1179,21 @@ String magnitudeName(unsigned char type) {
case MAGNITUDE_CO2:
result = F("CO2");
break;
case MAGNITUDE_CO2E:
result = F("CO2e");
break;
case MAGNITUDE_BVOC:
result = F("bVOC");
break;
case MAGNITUDE_STATIC_IAQ:
result = F("Static IAQ");
break;
case MAGNITUDE_IAQ:
result = F("IAQ");
break;
case MAGNITUDE_IAQ_ACCURACY:
result = F("IAQ Accuracy");
break;
case MAGNITUDE_LUX:
result = F("Lux");
break;
Expand Down Expand Up @@ -1568,6 +1609,13 @@ void _sensorLoad() {
}
#endif

#if BME680_SUPPORT
{
BME680Sensor * sensor = new BME680Sensor();
_sensors.push_back(sensor);
}
#endif

#if CSE7766_SUPPORT
{
CSE7766Sensor * sensor = new CSE7766Sensor();
Expand Down
Loading

0 comments on commit 3ee3892

Please sign in to comment.