move QMP6988 to separate file

This commit is contained in:
andreas 2023-11-03 18:28:44 +01:00
parent 899aa3fe4a
commit e8e3262a0d
4 changed files with 163 additions and 143 deletions

View File

@ -7,18 +7,6 @@
#ifdef _GWIIC #ifdef _GWIIC
#include <Wire.h> #include <Wire.h>
#endif #endif
#ifndef GWIIC_SDA
#define GWIIC_SDA -1
#endif
#ifndef GWIIC_SCL
#define GWIIC_SCL -1
#endif
#ifndef GWIIC_SDA2
#define GWIIC_SDA2 -1
#endif
#ifndef GWIIC_SCL2
#define GWIIC_SCL2 -1
#endif
#define CFG_GET(name,prefix) \ #define CFG_GET(name,prefix) \
cfg->getValue(name, GwConfigDefinitions::prefix ## name) cfg->getValue(name, GwConfigDefinitions::prefix ## name)

View File

@ -2,6 +2,7 @@
#include "GwIicSensors.h" #include "GwIicSensors.h"
#include "GwHardware.h" #include "GwHardware.h"
#include "GwBME280.h" #include "GwBME280.h"
#include "GwQMP6988.h"
#include <map> #include <map>
#ifdef _GWIIC #ifdef _GWIIC
#if defined(GWSHT3X) || defined(GWSHT3X1) || defined(GWSHT3X2) || defined(GWSHT3X2) || defined(GWSHT3X4) #if defined(GWSHT3X) || defined(GWSHT3X1) || defined(GWSHT3X2) || defined(GWSHT3X2) || defined(GWSHT3X4)
@ -9,11 +10,6 @@
#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
@ -21,19 +17,24 @@
#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
#include "QMP6988.h" #ifndef GWIIC_SDA
#define GWIIC_SDA -1
#endif #endif
#ifndef GWIIC_SCL
#define GWIIC_SCL -1
#endif
#ifndef GWIIC_SDA2
#define GWIIC_SDA2 -1
#endif
#ifndef GWIIC_SCL2
#define GWIIC_SCL2 -1
#endif
#include "GwTimer.h" #include "GwTimer.h"
#include "GwHardware.h" #include "GwHardware.h"
@ -162,97 +163,7 @@ class SHT3XConfig : public SensorBase{
#endif #endif
#ifdef _GWQMP6988
class QMP6988Config : public SensorBase{
public:
String prNam="Pressure";
bool prAct=true;
tN2kPressureSource prSrc=tN2kPressureSource::N2kps_Atmospheric;
float prOff=0;
QMP6988 *device=nullptr;
QMP6988Config(GwApi* api,const String &prefix):SensorBase(api,prefix){}
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);
}
virtual void readConfig(GwConfigHandler *cfg){
if (prefix == "QMP69881"){
busId=1;
addr=86;
#undef CG
#define CG(name) CFG_GET(name,QMP69881)
CG(prNam);
CG(iid);
CG(prAct);
CG(intv);
CG(prOff);
ok=true;
}
if (prefix == "QMP69882"){
busId=1;
addr=112;
#undef CG
#define CG(name) CFG_GET(name,QMP69882)
CG(prNam);
CG(iid);
CG(prAct);
CG(intv);
CG(prOff);
ok=true;
}
if (prefix == "QMP69883"){
busId=2;
addr=86;
#undef CG
#define CG(name) CFG_GET(name,QMP69883)
CG(prNam);
CG(iid);
CG(prAct);
CG(intv);
CG(prOff);
ok=true;
}
if (prefix == "QMP69884"){
busId=2;
addr=112;
#undef CG
#define CG(name) CFG_GET(name,QMP69884)
CG(prNam);
CG(iid);
CG(prAct);
CG(intv);
CG(prOff);
ok=true;
}
intv*=1000;
}
};
#endif
void runIicTask(GwApi *api); void runIicTask(GwApi *api);
@ -295,34 +206,7 @@ void initIicTask(GwApi *api){
sensors.add(api,scfg); sensors.add(api,scfg);
} }
#endif #endif
#if defined(GWQMP6988) || defined(GWQMP69881) registerQMP6988(api,sensors);
{
QMP6988Config *scfg=new QMP6988Config(api,"QMP69881");
LOG_DEBUG(GwLog::LOG,"%s configured",scfg->prefix.c_str());
sensors.add(api,scfg);
}
#endif
#if defined(GWQMP69882)
{
QMP6988Config *scfg=new QMP6988Config(api,"QMP69882");
LOG_DEBUG(GwLog::LOG,"%s configured",scfg->prefix.c_str());
sensors.add(api,scfg);
}
#endif
#if defined(GWQMP69883)
{
QMP6988Config *scfg=new QMP6988Config(api,"QMP69883");
LOG_DEBUG(GwLog::LOG,"%s configured",scfg->prefix.c_str());
sensors.add(api,scfg);
}
#endif
#if defined(GWQMP69884)
{
QMP6988Config *scfg=new QMP6988Config(api,"QMP69884");
LOG_DEBUG(GwLog::LOG,"%s configured",scfg->prefix.c_str());
sensors.add(api,scfg);
}
#endif
registerBME280(api,sensors); registerBME280(api,sensors);
for (auto it=sensors.begin();it != sensors.end();it++){ for (auto it=sensors.begin();it != sensors.end();it++){
if ((*it)->preinit(api)) addTask=true; if ((*it)->preinit(api)) addTask=true;

143
lib/iictask/GwQMP6988.cpp Normal file
View File

@ -0,0 +1,143 @@
#include "GwQMP6988.h"
#ifdef _GWIIC
#if defined(GWQMP6988) || defined(GWQMP69881) || defined(GWQMP69882) || defined(GWQMP69883) || defined(GWQMP69884)
#define _GWQMP6988
#else
#undef _GWQMP6988
#endif
#else
#undef _GWQMP6988
#undef GWQMP6988
#undef GWQMP69881
#undef GWQMP69882
#undef GWQMP69883
#undef GWQMP69884
#endif
#ifdef _GWQMP6988
#include "QMP6988.h"
#endif
#ifdef _GWQMP6988
class QMP6988Config : public SensorBase{
public:
String prNam="Pressure";
bool prAct=true;
tN2kPressureSource prSrc=tN2kPressureSource::N2kps_Atmospheric;
float prOff=0;
QMP6988 *device=nullptr;
QMP6988Config(GwApi* api,const String &prefix):SensorBase(api,prefix){}
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);
}
virtual void readConfig(GwConfigHandler *cfg){
if (prefix == "QMP69881"){
busId=1;
addr=86;
#undef CG
#define CG(name) CFG_GET(name,QMP69881)
CG(prNam);
CG(iid);
CG(prAct);
CG(intv);
CG(prOff);
ok=true;
}
if (prefix == "QMP69882"){
busId=1;
addr=112;
#undef CG
#define CG(name) CFG_GET(name,QMP69882)
CG(prNam);
CG(iid);
CG(prAct);
CG(intv);
CG(prOff);
ok=true;
}
if (prefix == "QMP69883"){
busId=2;
addr=86;
#undef CG
#define CG(name) CFG_GET(name,QMP69883)
CG(prNam);
CG(iid);
CG(prAct);
CG(intv);
CG(prOff);
ok=true;
}
if (prefix == "QMP69884"){
busId=2;
addr=112;
#undef CG
#define CG(name) CFG_GET(name,QMP69884)
CG(prNam);
CG(iid);
CG(prAct);
CG(intv);
CG(prOff);
ok=true;
}
intv*=1000;
}
};
void registerQMP6988(GwApi *api,SensorList &sensors){
GwLog *logger=api->getLogger();
#if defined(GWQMP6988) || defined(GWQMP69881)
{
QMP6988Config *scfg=new QMP6988Config(api,"QMP69881");
LOG_DEBUG(GwLog::LOG,"%s configured",scfg->prefix.c_str());
sensors.add(api,scfg);
}
#endif
#if defined(GWQMP69882)
{
QMP6988Config *scfg=new QMP6988Config(api,"QMP69882");
LOG_DEBUG(GwLog::LOG,"%s configured",scfg->prefix.c_str());
sensors.add(api,scfg);
}
#endif
#if defined(GWQMP69883)
{
QMP6988Config *scfg=new QMP6988Config(api,"QMP69883");
LOG_DEBUG(GwLog::LOG,"%s configured",scfg->prefix.c_str());
sensors.add(api,scfg);
}
#endif
#if defined(GWQMP69884)
{
QMP6988Config *scfg=new QMP6988Config(api,"QMP69884");
LOG_DEBUG(GwLog::LOG,"%s configured",scfg->prefix.c_str());
sensors.add(api,scfg);
}
#endif
}
#else
void registerQMP6988(GwApi *api,SensorList &sensors){}
#endif

5
lib/iictask/GwQMP6988.h Normal file
View File

@ -0,0 +1,5 @@
#ifndef _GQQMP6988_H
#define _GQQMP6988_H
#include "GwIicSensors.h"
void registerQMP6988(GwApi *api,SensorList &sensors);
#endif