Skip to content

Commit

Permalink
simplify sensor config handling
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas committed Nov 5, 2023
1 parent cf1e0d1 commit 5a79e05
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 125 deletions.
75 changes: 18 additions & 57 deletions lib/iictask/GwBME280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
39 changes: 11 additions & 28 deletions lib/iictask/GwQMP6988.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
54 changes: 14 additions & 40 deletions lib/iictask/GwSHT3X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5a79e05

Please sign in to comment.