diff --git a/lib/iictask/GwBME280.cpp b/lib/iictask/GwBME280.cpp index c50b998..1bf541f 100644 --- a/lib/iictask/GwBME280.cpp +++ b/lib/iictask/GwBME280.cpp @@ -55,7 +55,6 @@ class BME280Config : public IICSensorBase{ virtual bool preinit(GwApi * api){ GwLog *logger=api->getLogger(); LOG_DEBUG(GwLog::LOG,"%s configured",prefix.c_str()); - api->addCapability(prefix,"true"); addPressureXdr(api,*this); addTempXdr(api,*this); addHumidXdr(api,*this); diff --git a/lib/iictask/GwBMP280.cpp b/lib/iictask/GwBMP280.cpp index ce6ea63..e51bd4b 100644 --- a/lib/iictask/GwBMP280.cpp +++ b/lib/iictask/GwBMP280.cpp @@ -56,7 +56,6 @@ class BMP280Config : public IICSensorBase{ virtual bool preinit(GwApi * api){ GwLog *logger=api->getLogger(); LOG_DEBUG(GwLog::LOG,"%s configured",prefix.c_str()); - api->addCapability(prefix,"true"); addPressureXdr(api,*this); addTempXdr(api,*this); return isActive(); diff --git a/lib/iictask/GwQMP6988.cpp b/lib/iictask/GwQMP6988.cpp index 1997343..4f2b78c 100644 --- a/lib/iictask/GwQMP6988.cpp +++ b/lib/iictask/GwQMP6988.cpp @@ -30,7 +30,6 @@ class QMP6988Config : public IICSensorBase{ virtual bool preinit(GwApi * api){ GwLog *logger=api->getLogger(); LOG_DEBUG(GwLog::LOG,"QMP6988 configured"); - api->addCapability(prefix,"true"); addPressureXdr(api,*this); return isActive(); } diff --git a/lib/iictask/GwSHT3X.cpp b/lib/iictask/GwSHT3X.cpp index ee6b8b7..c93486f 100644 --- a/lib/iictask/GwSHT3X.cpp +++ b/lib/iictask/GwSHT3X.cpp @@ -26,7 +26,6 @@ class SHT3XConfig : public IICSensorBase{ virtual bool preinit(GwApi * api){ GwLog *logger=api->getLogger(); LOG_DEBUG(GwLog::LOG,"%s configured",prefix.c_str()); - api->addCapability(prefix,"true"); addHumidXdr(api,*this); addTempXdr(api,*this); return isActive(); diff --git a/lib/spitask/GWDMS22B.cpp b/lib/spitask/GWDMS22B.cpp index 63bdf85..fca345e 100644 --- a/lib/spitask/GWDMS22B.cpp +++ b/lib/spitask/GWDMS22B.cpp @@ -21,76 +21,23 @@ #define CHECK_BUS(BUS) \ checkDef("missing config for " #BUS,GW ## BUS ## _CLK ,GW ## BUS ## _MISO); -#define ADD22B(PRFX,BUS) \ - {\ - CHECK_BUS(BUS); \ - GWDMS22B *dms=new GWDMS22B(api,#PRFX,GW ## BUS ## _HOST);\ - api->addSensor(dms,true); \ - } - -#ifdef GWDMS22B11 - #define ADD22B11 ADD22B(DMS22B11,SPI1) - #ifndef GWDMS22B11_CS - #define GWDMS22B11_CS -1 - #endif -#else - #define GWDMS22B11_CS -1 - #define ADD22B11 -#endif - -#ifdef GWDMS22B12 - #define ADD22B12 ADD22B(DMS22B12,SPI1) - #ifndef GWDMS22B12_CS - #error "you need to define GWDMS22B12_CS" - #endif - #if GWDMS22B11_CS == -1 - #error "multiple devices on one SPI bus need chip select defines - GWDMS22B11_CS is unset" - #endif -#else - #define GWDMS22B12_CS -1 - #define ADD22B12 -#endif - - -#ifdef GWDMS22B21 - #define ADD22B21 ADD22B(DMS22B21,SPI2) - #ifndef GWDMS22B21_CS - #define GWDMS22B21_CS -1 - #endif -#else - #define GWDMS22B21_CS -1 - #define ADD22B21 -#endif - -#ifdef GWDMS22B22 - #define ADD22B22 ADD22B(DMS22B22,SPI2) - #ifndef GWDMS22B22_CS - #error "you need to define GWDMS22B22_CS" - #endif - #if GWDMS22B21_CS == -1 - #error "multiple devices on one SPI bus need chip select defines - GWDMS22B21_CS is unset" - #endif -#else - #define GWDMS22B22_CS -1 - #define ADD22B22 -#endif - +class GWDMS22B; +static GwSensorConfigInitializerList configs; class GWDMS22B : public SSISensor{ + public: int zero=2047; bool invt=false; String zeroConfigName; - public: - GWDMS22B(GwApi *api,const String &prfx, int host):SSISensor(api,prfx,host){} + GWDMS22B(GwApi *api,const String &prfx):SSISensor(api,prfx){} virtual bool preinit(GwApi * api){ GwLog *logger=api->getLogger(); LOG_DEBUG(GwLog::LOG,"DMS22B configured, prefix=%s, intv=%f, active=%d",prefix.c_str(),fintv,(int)act); - api->addCapability(prefix,"true"); return act; } - virtual void measure(GwApi * api,BusType *bus, int counterId){ + virtual void measure(GwApi * api,BUSTYPE *bus, int counterId){ GwLog *logger=api->getLogger(); uint32_t value=0; esp_err_t res=readData(value); @@ -106,34 +53,84 @@ class GWDMS22B : public SSISensor{ api->increment(counterId,prefix); api->setCalibrationValue(zeroConfigName,(double)value); } - #define DMS22B(PRFX,...) \ - if (prefix == #PRFX) {\ - CFG_GET(act,PRFX); \ - CFG_GET(iid,PRFX); \ - CFG_GET(fintv,PRFX); \ - CFG_GET(zero,PRFX); \ - zeroConfigName=GwConfigDefinitions::PRFX ## zero;\ - CFG_GET(invt,PRFX); \ - bits=12; \ - clock=500000; \ - cs=GW ## PRFX ## _CS; \ - __VA_ARGS__ \ - } - virtual void readConfig(GwConfigHandler *cfg){ - DMS22B(DMS22B11); - DMS22B(DMS22B12); - DMS22B(DMS22B21); - DMS22B(DMS22B22); - intv=1000*fintv; + if (ok) return; + configs.readConfig(this,cfg); } }; -void registerDMS22B(GwApi *api){ - ADD22B11 - ADD22B12 - ADD22B21 - ADD22B22 +#define ADD22B(PRFX,BUS) \ + {\ + CHECK_BUS(BUS); \ + GWDMS22B *dms=new GWDMS22B(api,#PRFX);\ + api->addSensor(dms,true); \ + } +void registerDMS22B(GwApi *api){ +#ifdef GWDMS22B11 + ADD22B(DMS22B11,SPI1) + #ifndef GWDMS22B11_CS + #define GWDMS22B11_CS -1 + #endif +#else + #define GWDMS22B11_CS -1 +#endif + +#ifdef GWDMS22B12 + ADD22B(DMS22B12,SPI1) + #ifndef GWDMS22B12_CS + #error "you need to define GWDMS22B12_CS" + #endif + #if GWDMS22B11_CS == -1 + #error "multiple devices on one SPI bus need chip select defines - GWDMS22B11_CS is unset" + #endif +#else + #define GWDMS22B12_CS -1 +#endif + + +#ifdef GWDMS22B21 + ADD22B(DMS22B21,SPI2) + #ifndef GWDMS22B21_CS + #define GWDMS22B21_CS -1 + #endif +#else + #define GWDMS22B21_CS -1 +#endif + +#ifdef GWDMS22B22 + ADD22B(DMS22B22,SPI2) + #ifndef GWDMS22B22_CS + #error "you need to define GWDMS22B22_CS" + #endif + #if GWDMS22B21_CS == -1 + #error "multiple devices on one SPI bus need chip select defines - GWDMS22B21_CS is unset" + #endif +#else + #define GWDMS22B22_CS -1 +#endif } + + +#define CFGDMS22B(s,PRFX,bus,csv) \ + CFG_SGET(s,act,PRFX); \ + CFG_SGET(s,iid,PRFX); \ + CFG_SGET(s,fintv,PRFX); \ + CFG_SGET(s,zero,PRFX); \ + s->zeroConfigName=GwConfigDefinitions::PRFX ## zero;\ + CFG_SGET(s,invt,PRFX); \ + s->bits=12; \ + s->clock=500000; \ + s->cs=csv; \ + s->busId=bus; \ + s->intv=1000*s->fintv; \ + s->ok=true; + +#define SCDMS22B(prefix,bus) \ + GWSENSORDEF(configs,GWDMS22B,CFGDMS22B,prefix,GW ## bus ## _HOST,GW ## prefix ## _CS) + +SCDMS22B(DMS22B11,SPI1); +SCDMS22B(DMS22B12,SPI1); +SCDMS22B(DMS22B21,SPI2); +SCDMS22B(DMS22B22,SPI2); diff --git a/lib/spitask/GwSpiSensor.h b/lib/spitask/GwSpiSensor.h index cedfd81..3491641 100644 --- a/lib/spitask/GwSpiSensor.h +++ b/lib/spitask/GwSpiSensor.h @@ -92,13 +92,14 @@ class SSIDevice{ class SSISensor : public SensorTemplate{ std::unique_ptr device; - protected: + public: int bits=12; int mask=0xffff; int cs=-1; int clock=0; bool act=false; float fintv=0; + protected: virtual bool initSSI(GwLog*logger,const SPIBus *bus, int clock,int cs, int bits){ mask= (1 << bits)-1; @@ -125,9 +126,8 @@ class SSISensor : public SensorTemplate{ } public: - SSISensor(GwApi *api,const String &prfx, int host):SensorTemplate(api,prfx) + SSISensor(GwApi *api,const String &prfx):SensorTemplate(api,prfx) { - busId=host; } virtual bool isActive(){return act;}; virtual bool initDevice(GwApi *api,BUSTYPE *bus){