intermediate: read BME280
This commit is contained in:
parent
09eb59510d
commit
9308cca898
|
@ -7,6 +7,7 @@
|
||||||
#include "N2kMessages.h"
|
#include "N2kMessages.h"
|
||||||
#include "GwHardware.h"
|
#include "GwHardware.h"
|
||||||
#include "GwXdrTypeMappings.h"
|
#include "GwXdrTypeMappings.h"
|
||||||
|
#include <Adafruit_BME280.h>
|
||||||
//#define GWSHT3X -1
|
//#define GWSHT3X -1
|
||||||
|
|
||||||
#ifndef GWIIC_SDA
|
#ifndef GWIIC_SDA
|
||||||
|
@ -55,6 +56,16 @@ class QMP6988Config{
|
||||||
offset=config->getInt(GwConfigDefinitions::QMP6988POffset);
|
offset=config->getInt(GwConfigDefinitions::QMP6988POffset);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class BME280Config{
|
||||||
|
public:
|
||||||
|
bool active=true;
|
||||||
|
int iid=99;
|
||||||
|
long interval=2000;
|
||||||
|
BME280Config(GwConfigHandler *config){
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
void runIicTask(GwApi *api);
|
void runIicTask(GwApi *api);
|
||||||
void initIicTask(GwApi *api){
|
void initIicTask(GwApi *api){
|
||||||
GwLog *logger=api->getLogger();
|
GwLog *logger=api->getLogger();
|
||||||
|
@ -113,6 +124,17 @@ void initIicTask(GwApi *api){
|
||||||
LOG_DEBUG(GwLog::LOG,"QMP6988 configured but disabled");
|
LOG_DEBUG(GwLog::LOG,"QMP6988 configured but disabled");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef GWBME280
|
||||||
|
api->addCapability("BME280","true");
|
||||||
|
BME280Config bme280Config(api->getConfig());
|
||||||
|
if (bme280Config.active){
|
||||||
|
LOG_DEBUG(GwLog::DEBUG,"BME280 configured and active, adding capability and xdr mapping");
|
||||||
|
addTask=true;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
LOG_DEBUG(GwLog::DEBUG,"BME280 configured but disabled");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (addTask){
|
if (addTask){
|
||||||
api->addUserTask(runIicTask,"iicTask",3000);
|
api->addUserTask(runIicTask,"iicTask",3000);
|
||||||
}
|
}
|
||||||
|
@ -191,6 +213,30 @@ void runIicTask(GwApi *api){
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef GWBME280
|
||||||
|
int baddr=GWBME280;
|
||||||
|
if (baddr < 0) baddr=0x76;
|
||||||
|
BME280Config bme280Config(api->getConfig());
|
||||||
|
if (bme280Config.active){
|
||||||
|
Adafruit_BME280 *bme280=new Adafruit_BME280();
|
||||||
|
if (bme280->begin(baddr,&Wire)){
|
||||||
|
uint32_t sensorId=bme280->sensorID();
|
||||||
|
bool hasHumidity=sensorId == 0x60; //BME280, else BMP280
|
||||||
|
LOG_DEBUG(GwLog::LOG,"initialized BME280 at %d, sensorId 0x%x",baddr,sensorId);
|
||||||
|
timers.addAction(bme280Config.interval,[logger,api,bme280,bme280Config,counterId,hasHumidity](){
|
||||||
|
float pressure=bme280->readPressure();
|
||||||
|
float temperature=bme280->readTemperature();
|
||||||
|
float humidity=-1;
|
||||||
|
if (hasHumidity) humidity=bme280->readHumidity();
|
||||||
|
LOG_DEBUG(GwLog::DEBUG,"BME280 read press=%.0f, temp=%.1f, humid=%02.0f",pressure,temperature,humidity);
|
||||||
|
});
|
||||||
|
runLoop=true;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
LOG_DEBUG(GwLog::ERROR,"unable to initialize BME280 sensor at address %d",baddr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (! runLoop){
|
if (! runLoop){
|
||||||
LOG_DEBUG(GwLog::LOG,"nothing to do for IIC task, finish");
|
LOG_DEBUG(GwLog::LOG,"nothing to do for IIC task, finish");
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
|
|
|
@ -8,5 +8,13 @@ build_flags=
|
||||||
-D M5_ENV3
|
-D M5_ENV3
|
||||||
-D M5_CAN_KIT
|
-D M5_CAN_KIT
|
||||||
${env.build_flags}
|
${env.build_flags}
|
||||||
upload_port = /dev/esp32
|
|
||||||
upload_protocol = esptool
|
[env:m5stack-atom-bme280]
|
||||||
|
board = m5stack-atom
|
||||||
|
lib_deps =
|
||||||
|
${env.lib_deps}
|
||||||
|
build_flags=
|
||||||
|
-D GWBME280=-1
|
||||||
|
-D M5_GROOVEIIC
|
||||||
|
-D M5_CAN_KIT
|
||||||
|
${env.build_flags}
|
||||||
|
|
|
@ -34,6 +34,12 @@ lib_deps =
|
||||||
WiFi
|
WiFi
|
||||||
Update
|
Update
|
||||||
Wire
|
Wire
|
||||||
|
SPI
|
||||||
|
adafruit/Adafruit BME280 Library @ 2.2.2
|
||||||
|
adafruit/Adafruit BusIO @ 1.14.5
|
||||||
|
adafruit/Adafruit Unified Sensor @ 1.1.13
|
||||||
|
|
||||||
|
|
||||||
board_build.embed_files =
|
board_build.embed_files =
|
||||||
lib/generated/index.html.gz
|
lib/generated/index.html.gz
|
||||||
lib/generated/index.js.gz
|
lib/generated/index.js.gz
|
||||||
|
|
Loading…
Reference in New Issue