intermediate: QMP6988 new config

This commit is contained in:
andreas 2023-11-03 16:19:10 +01:00
parent 2052f07a81
commit e449b7836d
1 changed files with 122 additions and 39 deletions

View File

@ -8,6 +8,11 @@
#else #else
#undef _GWSHT3X #undef _GWSHT3X
#endif #endif
#if defined(GWQMP6988) || defined(GWQMP69881) || defined(GWQMP69882) || defined(GWQMP69883) || defined(GWQMP69884)
#define _GWQMP6988
#else
#undef _GWQMP6988
#endif
#else #else
#undef _GWSHT3X #undef _GWSHT3X
#undef GWSHT3X #undef GWSHT3X
@ -15,11 +20,17 @@
#undef GWSHT3X2 #undef GWSHT3X2
#undef GWSHT3X3 #undef GWSHT3X3
#undef GWSHT3X4 #undef GWSHT3X4
#undef _GWQMP6988
#undef GWQMP6988
#undef GWQMP69881
#undef GWQMP69882
#undef GWQMP69883
#undef GWQMP69884
#endif #endif
#ifdef _GWSHT3X #ifdef _GWSHT3X
#include "SHT3X.h" #include "SHT3X.h"
#endif #endif
#ifdef GWQMP6988 #ifdef _GWQMP6988
#include "QMP6988.h" #include "QMP6988.h"
#endif #endif
#include "GwTimer.h" #include "GwTimer.h"
@ -224,24 +235,48 @@ class SHT3XConfig : public SensorBase{
#endif #endif
class QMP6988Config{ #ifdef _GWQMP6988
class QMP6988Config : public SensorBase{
public: public:
const String prefix="QMP69881";
String prNam="Pressure"; String prNam="Pressure";
int iid=99;
bool prAct=true; bool prAct=true;
long intv=2000;
tN2kPressureSource prSrc=tN2kPressureSource::N2kps_Atmospheric; tN2kPressureSource prSrc=tN2kPressureSource::N2kps_Atmospheric;
float prOff=0; float prOff=0;
QMP6988Config(GwConfigHandler *config){ QMP6988 *device=nullptr;
CQMP6988(prNam); QMP6988Config(GwApi* api,const String &prefix,int bus, int addr):SensorBase(api,prefix){
CQMP6988(iid); busId=bus;
CQMP6988(prAct); this->addr=addr;
CQMP6988(intv);
intv*=1000;
CQMP6988(prOff);
} }
virtual bool isActive(){return prAct;};
virtual bool initDevice(GwApi *api,TwoWire *wire){
if (!isActive()) return false;
GwLog *logger=api->getLogger();
device=new QMP6988();
if (!device->init(addr,wire)){
LOG_DEBUG(GwLog::ERROR,"unable to initialize %s at address %d, intv %ld",prefix.c_str(),addr,intv);
delete device;
device=nullptr;
return false;
}
LOG_DEBUG(GwLog::LOG,"initialized %s at address %d, intv %ld",prefix.c_str(),addr,intv);
return true;
};
virtual bool preinit(GwApi * api){
GwLog *logger=api->getLogger();
LOG_DEBUG(GwLog::LOG,"QMP6988 configured");
api->addCapability(prefix,"true");
addPressureXdr(api,*this);
return isActive();
}
virtual void measure(GwApi * api,TwoWire *wire, int counterId){
GwLog *logger=api->getLogger();
float pressure=device->calcPressure();
float computed=pressure+prOff;
LOG_DEBUG(GwLog::DEBUG,"%s measure %2.0fPa, computed %2.0fPa",prefix.c_str(), pressure,computed);
sendN2kPressure(api,*this,computed,counterId);
};
}; };
#endif
class BME280Config{ class BME280Config{
public: public:
@ -290,8 +325,9 @@ void initIicTask(GwApi *api){
bool addTask=false; bool addTask=false;
GwConfigHandler *config=api->getConfig(); GwConfigHandler *config=api->getConfig();
#if defined(GWSHT3X) || defined (GWSHT3X1) #if defined(GWSHT3X) || defined (GWSHT3X1)
LOG_DEBUG(GwLog::LOG,"SHT3X1 configured"); {
SHT3XConfig *scfg=new SHT3XConfig(api,"SHT3X1",1,0x44); SHT3XConfig *scfg=new SHT3XConfig(api,"SHT3X1",1,0x44);
LOG_DEBUG(GwLog::LOG,"%s configured",scfg->prefix.c_str());
#undef _SET #undef _SET
#define _SET(name) \ #define _SET(name) \
CFG_SET(scfg,config,name,SHT3X1) CFG_SET(scfg,config,name,SHT3X1)
@ -305,10 +341,12 @@ void initIicTask(GwApi *api){
_SET(huSrc); _SET(huSrc);
_SET(tmSrc); _SET(tmSrc);
sensors.push_back(scfg); sensors.push_back(scfg);
}
#endif #endif
#if defined(GWSHT3X2) #if defined(GWSHT3X2)
LOG_DEBUG(GwLog::LOG,"SHT3X2 configured"); {
SHT3XConfig *scfg=new SHT3XConfig(api,"SHT3X2",1,0x45); SHT3XConfig *scfg=new SHT3XConfig(api,"SHT3X2",1,0x45);
LOG_DEBUG(GwLog::LOG,"%s configured",scfg->prefix.c_str());
#undef _SET #undef _SET
#define _SET(name) \ #define _SET(name) \
CFG_SET(scfg,config,name,SHT3X2) CFG_SET(scfg,config,name,SHT3X2)
@ -322,10 +360,12 @@ void initIicTask(GwApi *api){
_SET(huSrc); _SET(huSrc);
_SET(tmSrc); _SET(tmSrc);
sensors.push_back(scfg); sensors.push_back(scfg);
}
#endif #endif
#if defined(GWSHT3X3) #if defined(GWSHT3X3)
LOG_DEBUG(GwLog::LOG,"SHT3X3 configured"); {
SHT3XConfig *scfg=new SHT3XConfig(api,"SHT3X3",2,0x44); SHT3XConfig *scfg=new SHT3XConfig(api,"SHT3X3",2,0x44);
LOG_DEBUG(GwLog::LOG,"%s configured",scfg->prefix.c_str());
#undef _SET #undef _SET
#define _SET(name) \ #define _SET(name) \
CFG_SET(scfg,config,name,SHT3X3) CFG_SET(scfg,config,name,SHT3X3)
@ -339,10 +379,12 @@ void initIicTask(GwApi *api){
_SET(huSrc); _SET(huSrc);
_SET(tmSrc); _SET(tmSrc);
sensors.push_back(scfg); sensors.push_back(scfg);
}
#endif #endif
#if defined(GWSHT3X4) #if defined(GWSHT3X4)
LOG_DEBUG(GwLog::LOG,"SHT3X4 configured"); {
SHT3XConfig *scfg=new SHT3XConfig(api,"SHT3X4",2,0x45); SHT3XConfig *scfg=new SHT3XConfig(api,"SHT3X4",2,0x45);
LOG_DEBUG(GwLog::LOG,"%s configured",scfg->prefix.c_str());
#undef _SET #undef _SET
#define _SET(name) \ #define _SET(name) \
CFG_SET(scfg,config,name,SHT3X4) CFG_SET(scfg,config,name,SHT3X4)
@ -356,12 +398,71 @@ void initIicTask(GwApi *api){
_SET(huSrc); _SET(huSrc);
_SET(tmSrc); _SET(tmSrc);
sensors.push_back(scfg); sensors.push_back(scfg);
}
#endif #endif
#ifdef GWQMP6988 #if defined(GWQMP6988) || defined(GWQMP69881)
LOG_DEBUG(GwLog::LOG,"QMP6988 configured"); {
QMP6988Config qmp6988Config(api->getConfig()); QMP6988Config *scfg=new QMP6988Config(api,"QMP69881",1,86);
api->addCapability(qmp6988Config.prefix,"true"); LOG_DEBUG(GwLog::LOG,"%s configured",scfg->prefix.c_str());
addPressureXdr(api,qmp6988Config); #undef _SET
#define _SET(name) \
CFG_SET(scfg,config,name,QMP69881)
_SET(prNam);
_SET(iid);
_SET(prAct);
_SET(intv);
scfg->intv*=1000;
_SET(prOff);
sensors.push_back(scfg);
}
#endif
#if defined(GWQMP69882)
{
QMP6988Config *scfg=new QMP6988Config(api,"QMP69882",1,112);
LOG_DEBUG(GwLog::LOG,"%s configured",scfg->prefix.c_str());
#undef _SET
#define _SET(name) \
CFG_SET(scfg,config,name,QMP69882)
_SET(prNam);
_SET(iid);
_SET(prAct);
_SET(intv);
scfg->intv*=1000;
_SET(prOff);
sensors.push_back(scfg);
}
#endif
#if defined(GWQMP69883)
{
QMP6988Config *scfg=new QMP6988Config(api,"QMP69883",2,86);
LOG_DEBUG(GwLog::LOG,"%s configured",scfg->prefix.c_str());
#undef _SET
#define _SET(name) \
CFG_SET(scfg,config,name,QMP69883)
_SET(prNam);
_SET(iid);
_SET(prAct);
_SET(intv);
scfg->intv*=1000;
_SET(prOff);
sensors.push_back(scfg);
}
#endif
#if defined(GWQMP69884)
{
QMP6988Config *scfg=new QMP6988Config(api,"QMP69884",2,112);
LOG_DEBUG(GwLog::LOG,"%s configured",scfg->prefix.c_str());
#undef _SET
#define _SET(name) \
CFG_SET(scfg,config,name,QMP69884)
_SET(prNam);
_SET(iid);
_SET(prAct);
_SET(intv);
scfg->intv*=1000;
_SET(prOff);
sensors.push_back(scfg);
}
#endif #endif
#ifdef GWBME280 #ifdef GWBME280
LOG_DEBUG(GwLog::LOG,"BME280 configured"); LOG_DEBUG(GwLog::LOG,"BME280 configured");
@ -458,24 +559,6 @@ void runIicTask(GwApi *api){
}); });
} }
} }
#ifdef GWQMP6988
int qaddr=GWQMP6988;
if (qaddr < 0) qaddr=0x56;
QMP6988Config qmp6988Config(api->getConfig());
QMP6988 *qmp6988=nullptr;
if (qmp6988Config.prAct){
runLoop=true;
qmp6988=new QMP6988();
qmp6988->init(qaddr,&Wire);
LOG_DEBUG(GwLog::LOG,"initialized QMP6988 at address %d, intv %ld",qaddr,qmp6988Config.intv);
timers.addAction(qmp6988Config.intv,[logger,api,qmp6988,qmp6988Config,counterId](){
float pressure=qmp6988->calcPressure();
float computed=pressure+qmp6988Config.prOff;
LOG_DEBUG(GwLog::DEBUG,"qmp6988 measure %2.0fPa, computed %2.0fPa",pressure,computed);
sendN2kPressure(api,qmp6988Config,computed,counterId);
});
}
#endif
#ifdef GWBME280 #ifdef GWBME280
int baddr=GWBME280; int baddr=GWBME280;
if (baddr < 0) baddr=0x76; if (baddr < 0) baddr=0x76;