1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-14 06:23:07 +01:00

intermediate, untested: move creator to SensorBase

This commit is contained in:
andreas
2024-11-19 18:58:29 +01:00
parent d904d15ece
commit 0200352f91
13 changed files with 51 additions and 37 deletions

View File

@@ -146,10 +146,10 @@ class BME280Config : public IICSensorBase{
}
};
static IICSensorBase::Creator creator([](GwApi *api, const String &prfx){
static SensorBase::Creator creator([](GwApi *api, const String &prfx){
return new BME280Config(api,prfx);
});
IICSensorBase::Creator registerBME280(GwApi *api){
SensorBase::Creator registerBME280(GwApi *api){
#if defined(GWBME280) || defined(GWBME28011)
{
api->addSensor(creator(api,PRFX1));
@@ -181,8 +181,8 @@ IICSensorBase::Creator registerBME280(GwApi *api){
return creator;
}
#else
IICSensorBase::Creator registerBME280(GwApi *api){
return IICSensorBase::Creator();
SensorBase::Creator registerBME280(GwApi *api){
return SensorBase::Creator();
}
#endif

View File

@@ -1,5 +1,5 @@
#ifndef _GWBME280_H
#define _GWBME280_H
#include "GwIicSensors.h"
IICSensorBase::Creator registerBME280(GwApi *api);
SensorBase::Creator registerBME280(GwApi *api);
#endif

View File

@@ -25,7 +25,7 @@
class BMP280Config;
GwSensorConfigInitializerList<BMP280Config> configs;
class BMP280Config : public IICSensorBase{
class BMP280Config : public IICSensorBase<BMP280Config>{
public:
bool prAct=true;
bool tmAct=true;
@@ -38,8 +38,7 @@ class BMP280Config : public IICSensorBase{
float prOff=0;
Adafruit_BMP280 *device=nullptr;
uint32_t sensorId=-1;
BMP280Config(GwApi * api, const String &prfx):IICSensorBase("BMP280",api,prfx){
}
using IICSensorBase<BMP280Config>::IICSensorBase;
virtual bool isActive(){return prAct||tmAct;}
virtual bool initDevice(GwApi *api,TwoWire *wire){
GwLog *logger=api->getLogger();
@@ -98,13 +97,13 @@ class BMP280Config : public IICSensorBase{
};
static IICSensorBase::Creator creator([](GwApi *api, const String &prfx)->BMP280Config*{
static SensorBase::Creator creator([](GwApi *api, const String &prfx)->BMP280Config*{
if (! configs.knowsPrefix(prfx)){
return nullptr;
}
return new BMP280Config(api,prfx);
});
IICSensorBase::Creator registerBMP280(GwApi *api){
SensorBase::Creator registerBMP280(GwApi *api){
#if defined(GWBMP280) || defined(GWBMP28011)
{
api->addSensor(creator(api,"BMP28011"));
@@ -171,8 +170,8 @@ SCBMP280(configs, BMP28021, 2, 0x76);
SCBMP280(configs, BMP28022, 2, 0x77);
#else
IICSensorBase::Creator registerBMP280(GwApi *api){
return IICSensorBase::Creator();
SensorBase::Creator registerBMP280(GwApi *api){
return SensorBase::Creator();
}
#endif

View File

@@ -1,6 +1,6 @@
#ifndef _GWBMP280_H
#define _GWBMP280_H
#include "GwIicSensors.h"
IICSensorBase::Creator registerBMP280(GwApi *api);
SensorBase::Creator registerBMP280(GwApi *api);
#endif

View File

@@ -13,7 +13,8 @@
using BUSTYPE=TwoWire;
using IICSensorList=SensorList;
using IICSensorBase=SensorTemplate<BUSTYPE,SensorBase::IIC>;
template<typename Sensor>
using IICSensorBase=SensorTemplate<BUSTYPE,SensorBase::IIC,Sensor>;
template <class CFG>

View File

@@ -43,7 +43,7 @@ static std::vector<IICGrove> iicGroveList;
void runIicTask(GwApi *api);
static void addGroveItems(std::vector<IICSensorBase::Creator> &creators,GwApi *api, const String &bus,const String &grove, int, int)
static void addGroveItems(std::vector<SensorBase::Creator> &creators,GwApi *api, const String &bus,const String &grove, int, int)
{
GwLog *logger=api->getLogger();
for (auto &&init : iicGroveList)
@@ -71,7 +71,7 @@ static void addGroveItems(std::vector<IICSensorBase::Creator> &creators,GwApi *a
}
else
{
LOG_DEBUG(GwLog::DEBUG, "unmatched grove sensor config %s for %s", prfx.c_str(), scfg->type.c_str());
LOG_DEBUG(GwLog::DEBUG, "unmatched grove sensor config %s", prfx.c_str());
delete scfg;
}
}
@@ -89,7 +89,7 @@ void initIicTask(GwApi *api){
#else
bool addTask=false;
GwConfigHandler *config=api->getConfig();
std::vector<IICSensorBase::Creator> creators;
std::vector<SensorBase::Creator> creators;
creators.push_back(registerSHT3X(api));
creators.push_back(registerQMP6988(api));
creators.push_back(registerBME280(api));

View File

@@ -79,10 +79,10 @@ class QMP6988Config : public IICSensorBase{
}
};
static IICSensorBase::Creator creator=[](GwApi *api,const String &prfx){
static SensorBase::Creator creator=[](GwApi *api,const String &prfx){
return new QMP6988Config(api,prfx);
};
IICSensorBase::Creator registerQMP6988(GwApi *api,IICSensorList &sensors){
SensorBase::Creator registerQMP6988(GwApi *api,IICSensorList &sensors){
GwLog *logger=api->getLogger();
#if defined(GWQMP6988) || defined(GWQMP698811)
{
@@ -116,7 +116,7 @@ IICSensorBase::Creator registerQMP6988(GwApi *api,IICSensorList &sensors){
}
#else
IICSensorBase::Creator registerQMP6988(GwApi *api){
return IICSensorBase::Creator();
SensorBase::Creator registerQMP6988(GwApi *api){
return SensorBase::Creator();
}
#endif

View File

@@ -16,5 +16,5 @@
#ifdef _GWQMP6988
#include "QMP6988.h"
#endif
IICSensorBase::Creator registerQMP6988(GwApi *api);
SensorBase::Creator registerQMP6988(GwApi *api);
#endif

View File

@@ -106,10 +106,10 @@ class SHT3XConfig : public IICSensorBase{
intv*=1000;
}
};
IICSensorBase::Creator creator=[](GwApi *api,const String &prfx){
SensorBase::Creator creator=[](GwApi *api,const String &prfx){
return new SHT3XConfig(api,prfx);
};
IICSensorBase::Creator registerSHT3X(GwApi *api){
SensorBase::Creator registerSHT3X(GwApi *api){
GwLog *logger=api->getLogger();
#if defined(GWSHT3X) || defined (GWSHT3X11)
{
@@ -143,8 +143,8 @@ IICSensorBase::Creator registerSHT3X(GwApi *api){
};
#else
IICSensorBase::Creator registerSHT3X(GwApi *api){
return IICSensorBase::Creator();
SensorBase::Creator registerSHT3X(GwApi *api){
return SensorBase::Creator();
}
#endif

View File

@@ -16,5 +16,5 @@
#ifdef _GWSHT3X
#include "SHT3X.h"
#endif
IICSensorBase::Creator registerSHT3X(GwApi *api);
SensorBase::Creator registerSHT3X(GwApi *api);
#endif