add some compile time checks for necessary i2c definitions

This commit is contained in:
andreas 2023-11-04 20:07:15 +01:00
parent 83e181fa59
commit cf1e0d1224
5 changed files with 36 additions and 4 deletions

View File

@ -191,6 +191,14 @@ class GwApi{
virtual GwBoatData *getBoatData()=0; virtual GwBoatData *getBoatData()=0;
virtual ~GwApi(){} virtual ~GwApi(){}
}; };
/**
* a simple generic function to create runtime errors if some necessary values are not defined
*/
template<typename... T>
static void checkDef(T... args){};
#ifndef DECLARE_USERTASK #ifndef DECLARE_USERTASK
#define DECLARE_USERTASK(task) #define DECLARE_USERTASK(task)
#endif #endif

View File

@ -176,11 +176,13 @@ class BME280Config : public SensorBase{
} }
}; };
void registerBME280(GwApi *api,SensorList &sensors){ void registerBME280(GwApi *api,SensorList &sensors){
#if defined(GWBME280) || defined(GWBME28011) #if defined(GWBME280) || defined(GWBME28011)
{ {
BME280Config *cfg=new BME280Config(api,PRFX1); BME280Config *cfg=new BME280Config(api,PRFX1);
sensors.add(api,cfg); sensors.add(api,cfg);
CHECK_IIC1();
#pragma message "GWBME28011 defined" #pragma message "GWBME28011 defined"
} }
#endif #endif
@ -188,6 +190,7 @@ void registerBME280(GwApi *api,SensorList &sensors){
{ {
BME280Config *cfg=new BME280Config(api,PRFX2); BME280Config *cfg=new BME280Config(api,PRFX2);
sensors.add(api,cfg); sensors.add(api,cfg);
CHECK_IIC1();
#pragma message "GWBME28012 defined" #pragma message "GWBME28012 defined"
} }
#endif #endif
@ -195,6 +198,7 @@ void registerBME280(GwApi *api,SensorList &sensors){
{ {
BME280Config *cfg=new BME280Config(api,PRFX3); BME280Config *cfg=new BME280Config(api,PRFX3);
sensors.add(api,cfg); sensors.add(api,cfg);
CHECK_IIC2();
#pragma message "GWBME28021 defined" #pragma message "GWBME28021 defined"
} }
#endif #endif
@ -202,6 +206,7 @@ void registerBME280(GwApi *api,SensorList &sensors){
{ {
BME280Config *cfg=new BME280Config(api,PRFX4); BME280Config *cfg=new BME280Config(api,PRFX4);
sensors.add(api,cfg); sensors.add(api,cfg);
CHECK_IIC1();
#pragma message "GWBME28022 defined" #pragma message "GWBME28022 defined"
} }
#endif #endif

View File

@ -126,4 +126,7 @@ class SensorList : public std::vector<SensorBase*>{
using std::vector<SensorBase*>::vector; using std::vector<SensorBase*>::vector;
}; };
#define CHECK_IIC1() checkDef(GWIIC_SCL,GWIIC_SDA)
#define CHECK_IIC2() checkDef(GWIIC_SCL2,GWIIC_SDA2)
#endif #endif

View File

@ -95,28 +95,36 @@ class QMP6988Config : public SensorBase{
}; };
void registerQMP6988(GwApi *api,SensorList &sensors){ void registerQMP6988(GwApi *api,SensorList &sensors){
GwLog *logger=api->getLogger(); GwLog *logger=api->getLogger();
#if defined(GWQMP6988) || defined(GWQMP69881) #if defined(GWQMP6988) || defined(GWQMP698811)
{ {
QMP6988Config *scfg=new QMP6988Config(api,PRFX1); QMP6988Config *scfg=new QMP6988Config(api,PRFX1);
sensors.add(api,scfg); sensors.add(api,scfg);
CHECK_IIC1();
#pragma message "GWQMP698811 defined"
} }
#endif #endif
#if defined(GWQMP69882) #if defined(GWQMP698812)
{ {
QMP6988Config *scfg=new QMP6988Config(api,PRFX2); QMP6988Config *scfg=new QMP6988Config(api,PRFX2);
sensors.add(api,scfg); sensors.add(api,scfg);
CHECK_IIC1();
#pragma message "GWQMP698812 defined"
} }
#endif #endif
#if defined(GWQMP69883) #if defined(GWQMP698821)
{ {
QMP6988Config *scfg=new QMP6988Config(api,PRFX3); QMP6988Config *scfg=new QMP6988Config(api,PRFX3);
sensors.add(api,scfg); sensors.add(api,scfg);
CHECK_IIC2();
#pragma message "GWQMP698821 defined"
} }
#endif #endif
#if defined(GWQMP69884) #if defined(GWQMP698822)
{ {
QMP6988Config *scfg=new QMP6988Config(api,PRFX4); QMP6988Config *scfg=new QMP6988Config(api,PRFX4);
sensors.add(api,scfg); sensors.add(api,scfg);
CHECK_IIC2();
#pragma message "GWQMP698822 defined"
} }
#endif #endif
} }

View File

@ -136,24 +136,32 @@ void registerSHT3X(GwApi *api,SensorList &sensors){
{ {
SHT3XConfig *scfg=new SHT3XConfig(api,PRFX1); SHT3XConfig *scfg=new SHT3XConfig(api,PRFX1);
sensors.add(api,scfg); sensors.add(api,scfg);
CHECK_IIC1();
#pragma message "GWSHT3X11 defined"
} }
#endif #endif
#if defined(GWSHT3X12) #if defined(GWSHT3X12)
{ {
SHT3XConfig *scfg=new SHT3XConfig(api,PRFX2); SHT3XConfig *scfg=new SHT3XConfig(api,PRFX2);
sensors.add(api,scfg); sensors.add(api,scfg);
CHECK_IIC1();
#pragma message "GWSHT3X12 defined"
} }
#endif #endif
#if defined(GWSHT3X21) #if defined(GWSHT3X21)
{ {
SHT3XConfig *scfg=new SHT3XConfig(api,PRFX3); SHT3XConfig *scfg=new SHT3XConfig(api,PRFX3);
sensors.add(api,scfg); sensors.add(api,scfg);
CHECK_IIC2();
#pragma message "GWSHT3X21 defined"
} }
#endif #endif
#if defined(GWSHT3X22) #if defined(GWSHT3X22)
{ {
SHT3XConfig *scfg=new SHT3XConfig(api,PRFX4); SHT3XConfig *scfg=new SHT3XConfig(api,PRFX4);
sensors.add(api,scfg); sensors.add(api,scfg);
CHECK_IIC2();
#pragma message "GWSHT3X22 defined"
} }
#endif #endif
} }