diff --git a/lib/iictask/GwIicSensors.h b/lib/iictask/GwIicSensors.h index ad1007b..da94727 100644 --- a/lib/iictask/GwIicSensors.h +++ b/lib/iictask/GwIicSensors.h @@ -7,18 +7,6 @@ #ifdef _GWIIC #include #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) \ cfg->getValue(name, GwConfigDefinitions::prefix ## name) diff --git a/lib/iictask/GwIicTask.cpp b/lib/iictask/GwIicTask.cpp index 4d544ac..b330ab0 100644 --- a/lib/iictask/GwIicTask.cpp +++ b/lib/iictask/GwIicTask.cpp @@ -2,6 +2,7 @@ #include "GwIicSensors.h" #include "GwHardware.h" #include "GwBME280.h" +#include "GwQMP6988.h" #include #ifdef _GWIIC #if defined(GWSHT3X) || defined(GWSHT3X1) || defined(GWSHT3X2) || defined(GWSHT3X2) || defined(GWSHT3X4) @@ -9,11 +10,6 @@ #else #undef _GWSHT3X #endif - #if defined(GWQMP6988) || defined(GWQMP69881) || defined(GWQMP69882) || defined(GWQMP69883) || defined(GWQMP69884) - #define _GWQMP6988 - #else - #undef _GWQMP6988 - #endif #else #undef _GWSHT3X #undef GWSHT3X @@ -21,19 +17,24 @@ #undef GWSHT3X2 #undef GWSHT3X3 #undef GWSHT3X4 - #undef _GWQMP6988 - #undef GWQMP6988 - #undef GWQMP69881 - #undef GWQMP69882 - #undef GWQMP69883 - #undef GWQMP69884 #endif #ifdef _GWSHT3X #include "SHT3X.h" #endif -#ifdef _GWQMP6988 - #include "QMP6988.h" + +#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 + #include "GwTimer.h" #include "GwHardware.h" @@ -162,97 +163,7 @@ class SHT3XConfig : public SensorBase{ #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); @@ -295,34 +206,7 @@ void initIicTask(GwApi *api){ sensors.add(api,scfg); } #endif - #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 + registerQMP6988(api,sensors); registerBME280(api,sensors); for (auto it=sensors.begin();it != sensors.end();it++){ if ((*it)->preinit(api)) addTask=true; diff --git a/lib/iictask/GwQMP6988.cpp b/lib/iictask/GwQMP6988.cpp new file mode 100644 index 0000000..0ec3823 --- /dev/null +++ b/lib/iictask/GwQMP6988.cpp @@ -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 \ No newline at end of file diff --git a/lib/iictask/GwQMP6988.h b/lib/iictask/GwQMP6988.h new file mode 100644 index 0000000..e4cfef0 --- /dev/null +++ b/lib/iictask/GwQMP6988.h @@ -0,0 +1,5 @@ +#ifndef _GQQMP6988_H +#define _GQQMP6988_H +#include "GwIicSensors.h" +void registerQMP6988(GwApi *api,SensorList &sensors); +#endif \ No newline at end of file