From cf1e0d122422bdf2bf9d80de00412f55e6021bee Mon Sep 17 00:00:00 2001 From: andreas Date: Sat, 4 Nov 2023 20:07:15 +0100 Subject: [PATCH] add some compile time checks for necessary i2c definitions --- lib/api/GwApi.h | 8 ++++++++ lib/iictask/GwBME280.cpp | 5 +++++ lib/iictask/GwIicSensors.h | 3 +++ lib/iictask/GwQMP6988.cpp | 16 ++++++++++++---- lib/iictask/GwSHT3X.cpp | 8 ++++++++ 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/lib/api/GwApi.h b/lib/api/GwApi.h index af3b010..95892cf 100644 --- a/lib/api/GwApi.h +++ b/lib/api/GwApi.h @@ -191,6 +191,14 @@ class GwApi{ virtual GwBoatData *getBoatData()=0; virtual ~GwApi(){} }; + +/** + * a simple generic function to create runtime errors if some necessary values are not defined +*/ +template +static void checkDef(T... args){}; + + #ifndef DECLARE_USERTASK #define DECLARE_USERTASK(task) #endif diff --git a/lib/iictask/GwBME280.cpp b/lib/iictask/GwBME280.cpp index a1bca7d..675116c 100644 --- a/lib/iictask/GwBME280.cpp +++ b/lib/iictask/GwBME280.cpp @@ -176,11 +176,13 @@ class BME280Config : public SensorBase{ } }; + void registerBME280(GwApi *api,SensorList &sensors){ #if defined(GWBME280) || defined(GWBME28011) { BME280Config *cfg=new BME280Config(api,PRFX1); sensors.add(api,cfg); + CHECK_IIC1(); #pragma message "GWBME28011 defined" } #endif @@ -188,6 +190,7 @@ void registerBME280(GwApi *api,SensorList &sensors){ { BME280Config *cfg=new BME280Config(api,PRFX2); sensors.add(api,cfg); + CHECK_IIC1(); #pragma message "GWBME28012 defined" } #endif @@ -195,6 +198,7 @@ void registerBME280(GwApi *api,SensorList &sensors){ { BME280Config *cfg=new BME280Config(api,PRFX3); sensors.add(api,cfg); + CHECK_IIC2(); #pragma message "GWBME28021 defined" } #endif @@ -202,6 +206,7 @@ void registerBME280(GwApi *api,SensorList &sensors){ { BME280Config *cfg=new BME280Config(api,PRFX4); sensors.add(api,cfg); + CHECK_IIC1(); #pragma message "GWBME28022 defined" } #endif diff --git a/lib/iictask/GwIicSensors.h b/lib/iictask/GwIicSensors.h index 30068e6..c6630c7 100644 --- a/lib/iictask/GwIicSensors.h +++ b/lib/iictask/GwIicSensors.h @@ -126,4 +126,7 @@ class SensorList : public std::vector{ using std::vector::vector; }; +#define CHECK_IIC1() checkDef(GWIIC_SCL,GWIIC_SDA) +#define CHECK_IIC2() checkDef(GWIIC_SCL2,GWIIC_SDA2) + #endif \ No newline at end of file diff --git a/lib/iictask/GwQMP6988.cpp b/lib/iictask/GwQMP6988.cpp index 960e8b9..d3f3a42 100644 --- a/lib/iictask/GwQMP6988.cpp +++ b/lib/iictask/GwQMP6988.cpp @@ -95,28 +95,36 @@ class QMP6988Config : public SensorBase{ }; void registerQMP6988(GwApi *api,SensorList &sensors){ GwLog *logger=api->getLogger(); - #if defined(GWQMP6988) || defined(GWQMP69881) + #if defined(GWQMP6988) || defined(GWQMP698811) { QMP6988Config *scfg=new QMP6988Config(api,PRFX1); sensors.add(api,scfg); + CHECK_IIC1(); + #pragma message "GWQMP698811 defined" } #endif - #if defined(GWQMP69882) + #if defined(GWQMP698812) { QMP6988Config *scfg=new QMP6988Config(api,PRFX2); sensors.add(api,scfg); + CHECK_IIC1(); + #pragma message "GWQMP698812 defined" } #endif - #if defined(GWQMP69883) + #if defined(GWQMP698821) { QMP6988Config *scfg=new QMP6988Config(api,PRFX3); sensors.add(api,scfg); + CHECK_IIC2(); + #pragma message "GWQMP698821 defined" } #endif - #if defined(GWQMP69884) + #if defined(GWQMP698822) { QMP6988Config *scfg=new QMP6988Config(api,PRFX4); sensors.add(api,scfg); + CHECK_IIC2(); + #pragma message "GWQMP698822 defined" } #endif } diff --git a/lib/iictask/GwSHT3X.cpp b/lib/iictask/GwSHT3X.cpp index 3bda811..67f3629 100644 --- a/lib/iictask/GwSHT3X.cpp +++ b/lib/iictask/GwSHT3X.cpp @@ -136,24 +136,32 @@ void registerSHT3X(GwApi *api,SensorList &sensors){ { SHT3XConfig *scfg=new SHT3XConfig(api,PRFX1); sensors.add(api,scfg); + CHECK_IIC1(); + #pragma message "GWSHT3X11 defined" } #endif #if defined(GWSHT3X12) { SHT3XConfig *scfg=new SHT3XConfig(api,PRFX2); sensors.add(api,scfg); + CHECK_IIC1(); + #pragma message "GWSHT3X12 defined" } #endif #if defined(GWSHT3X21) { SHT3XConfig *scfg=new SHT3XConfig(api,PRFX3); sensors.add(api,scfg); + CHECK_IIC2(); + #pragma message "GWSHT3X21 defined" } #endif #if defined(GWSHT3X22) { SHT3XConfig *scfg=new SHT3XConfig(api,PRFX4); sensors.add(api,scfg); + CHECK_IIC2(); + #pragma message "GWSHT3X22 defined" } #endif }