From 5a79e0584ff1222b6a963d1c1f3160f71a908791 Mon Sep 17 00:00:00 2001 From: andreas Date: Sun, 5 Nov 2023 12:15:39 +0100 Subject: [PATCH] simplify sensor config handling --- lib/iictask/GwBME280.cpp | 75 ++++++++++----------------------------- lib/iictask/GwQMP6988.cpp | 39 ++++++-------------- lib/iictask/GwSHT3X.cpp | 54 ++++++++-------------------- 3 files changed, 43 insertions(+), 125 deletions(-) diff --git a/lib/iictask/GwBME280.cpp b/lib/iictask/GwBME280.cpp index 675116c9..9804e7e8 100644 --- a/lib/iictask/GwBME280.cpp +++ b/lib/iictask/GwBME280.cpp @@ -90,87 +90,48 @@ class BME280Config : public SensorBase{ sendN2kHumidity(api, *this, humidity, counterId); } } + #define CFG280(prefix) \ + CFG_GET(prAct,prefix); \ + CFG_GET(tmAct,prefix);\ + CFG_GET(huAct,prefix);\ + CFG_GET(tmSrc,prefix);\ + CFG_GET(huSrc,prefix);\ + CFG_GET(iid,prefix);\ + CFG_GET(intv,prefix);\ + CFG_GET(tmNam,prefix);\ + CFG_GET(huNam,prefix);\ + CFG_GET(prNam,prefix);\ + CFG_GET(tmOff,prefix);\ + CFG_GET(prOff,prefix); + virtual void readConfig(GwConfigHandler *cfg) override { if (prefix == PRFX1) { busId = 1; addr = 0x76; - #undef CG - #define CG(name) CFG_GET(name, BME28011) - CG(prAct); - CG(tmAct); - CG(huAct); - CG(tmSrc); - CG(huSrc); - CG(iid); - CG(intv); - CG(tmNam); - CG(huNam); - CG(prNam); - CG(tmOff); - CG(prOff); + CFG280(BME28011); ok=true; } if (prefix == PRFX2) { busId = 1; addr = 0x77; - #undef CG - #define CG(name) CFG_GET(name, BME28012) - CG(prAct); - CG(tmAct); - CG(huAct); - CG(tmSrc); - CG(huSrc); - CG(iid); - CG(intv); - CG(tmNam); - CG(huNam); - CG(prNam); - CG(tmOff); - CG(prOff); + CFG280(BME28012); ok=true; } if (prefix == PRFX3) { busId = 2; addr = 0x76; - #undef CG - #define CG(name) CFG_GET(name, BME28021) - CG(prAct); - CG(tmAct); - CG(huAct); - CG(tmSrc); - CG(huSrc); - CG(iid); - CG(intv); - CG(tmNam); - CG(huNam); - CG(prNam); - CG(tmOff); - CG(prOff); + CFG280(BME28021); ok=true; } if (prefix == PRFX4) { busId = 2; addr = 0x77; - #undef CG - #define CG(name) CFG_GET(name, BME28022) - CG(prAct); - CG(tmAct); - CG(huAct); - CG(tmSrc); - CG(huSrc); - CG(iid); - CG(intv); - CG(tmNam); - CG(huNam); - CG(prNam); - CG(tmOff); - CG(prOff); - ok=true; + CFG280(BME28022); } intv *= 1000; } diff --git a/lib/iictask/GwQMP6988.cpp b/lib/iictask/GwQMP6988.cpp index d3f3a426..1f831999 100644 --- a/lib/iictask/GwQMP6988.cpp +++ b/lib/iictask/GwQMP6988.cpp @@ -40,53 +40,36 @@ class QMP6988Config : public SensorBase{ LOG_DEBUG(GwLog::DEBUG,"%s measure %2.0fPa, computed %2.0fPa",prefix.c_str(), pressure,computed); sendN2kPressure(api,*this,computed,counterId); } + #define CFG6988(prefix)\ + CFG_GET(prNam,prefix); \ + CFG_GET(iid,prefix); \ + CFG_GET(prAct,prefix); \ + CFG_GET(intv,prefix); \ + CFG_GET(prOff,prefix); + virtual void readConfig(GwConfigHandler *cfg){ if (prefix == PRFX1){ busId=1; addr=86; - #undef CG - #define CG(name) CFG_GET(name,QMP698811) - CG(prNam); - CG(iid); - CG(prAct); - CG(intv); - CG(prOff); + CFG6988(QMP698811); ok=true; } if (prefix == PRFX2){ busId=1; addr=112; - #undef CG - #define CG(name) CFG_GET(name,QMP698812) - CG(prNam); - CG(iid); - CG(prAct); - CG(intv); - CG(prOff); + CFG6988(QMP698812); ok=true; } if (prefix == PRFX3){ busId=2; addr=86; - #undef CG - #define CG(name) CFG_GET(name,QMP698821) - CG(prNam); - CG(iid); - CG(prAct); - CG(intv); - CG(prOff); + CFG6988(QMP698821); ok=true; } if (prefix == PRFX4){ busId=2; addr=112; - #undef CG - #define CG(name) CFG_GET(name,QMP698822) - CG(prNam); - CG(iid); - CG(prAct); - CG(intv); - CG(prOff); + CFG6988(QMP698822); ok=true; } intv*=1000; diff --git a/lib/iictask/GwSHT3X.cpp b/lib/iictask/GwSHT3X.cpp index 67f36295..e98647c5 100644 --- a/lib/iictask/GwSHT3X.cpp +++ b/lib/iictask/GwSHT3X.cpp @@ -66,65 +66,39 @@ class SHT3XConfig : public SensorBase{ * just to get compile time errors if something does not fit * correctly */ + #define CFG3X(prefix) \ + CFG_GET(tmNam,prefix); \ + CFG_GET(huNam,prefix); \ + CFG_GET(iid,prefix); \ + CFG_GET(tmAct,prefix); \ + CFG_GET(huAct,prefix); \ + CFG_GET(intv,prefix); \ + CFG_GET(huSrc,prefix); \ + CFG_GET(tmSrc,prefix); + virtual void readConfig(GwConfigHandler *cfg){ if (prefix == PRFX1){ busId=1; addr=0x44; - #undef CG - #define CG(name) CFG_GET(name,SHT3X11) - CG(tmNam); - CG(huNam); - CG(iid); - CG(tmAct); - CG(huAct); - CG(intv); - CG(huSrc); - CG(tmSrc); + CFG3X(SHT3X11); ok=true; } if (prefix == PRFX2){ busId=1; addr=0x45; - #undef CG - #define CG(name) CFG_GET(name,SHT3X12) - CG(tmNam); - CG(huNam); - CG(iid); - CG(tmAct); - CG(huAct); - CG(intv); - CG(huSrc); - CG(tmSrc); + CFG3X(SHT3X12); ok=true; } if (prefix == PRFX3){ busId=2; addr=0x44; - #undef CG - #define CG(name) CFG_GET(name,SHT3X21) - CG(tmNam); - CG(huNam); - CG(iid); - CG(tmAct); - CG(huAct); - CG(intv); - CG(huSrc); - CG(tmSrc); + CFG3X(SHT3X21); ok=true; } if (prefix == PRFX4){ busId=2; addr=0x45; - #undef CG - #define CG(name) CFG_GET(name,SHT3X22) - CG(tmNam); - CG(huNam); - CG(iid); - CG(tmAct); - CG(huAct); - CG(intv); - CG(huSrc); - CG(tmSrc); + CFG3X(SHT3X22); ok=true; } intv*=1000;