mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-14 06:23:07 +01:00
make SensorBase more generic
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
#define PRFX2 "BME28012"
|
||||
#define PRFX3 "BME28021"
|
||||
#define PRFX4 "BME28022"
|
||||
class BME280Config : public SensorBase{
|
||||
class BME280Config : public IICSensorBase{
|
||||
public:
|
||||
bool prAct=true;
|
||||
bool tmAct=true;
|
||||
@@ -138,7 +138,7 @@ class BME280Config : public SensorBase{
|
||||
};
|
||||
|
||||
|
||||
void registerBME280(GwApi *api,SensorList &sensors){
|
||||
void registerBME280(GwApi *api,IICSensorList &sensors){
|
||||
#if defined(GWBME280) || defined(GWBME28011)
|
||||
{
|
||||
BME280Config *cfg=new BME280Config(api,PRFX1);
|
||||
@@ -173,7 +173,7 @@ void registerBME280(GwApi *api,SensorList &sensors){
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
void registerBME280(GwApi *api,SensorList &sensors){
|
||||
void registerBME280(GwApi *api,IICSensorList &sensors){
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef _GWBME280_H
|
||||
#define _GWBME280_H
|
||||
#include "GwIicSensors.h"
|
||||
void registerBME280(GwApi *api,SensorList &sensors);
|
||||
void registerBME280(GwApi *api,IICSensorList &sensors);
|
||||
#endif
|
||||
@@ -4,12 +4,16 @@
|
||||
#include "N2kMessages.h"
|
||||
#include "GwXdrTypeMappings.h"
|
||||
#include "GwHardware.h"
|
||||
#include "GwSensor.h"
|
||||
#ifdef _GWIIC
|
||||
#include <Wire.h>
|
||||
#else
|
||||
class TwoWire;
|
||||
#endif
|
||||
|
||||
using BusType=TwoWire;
|
||||
using IICSensorList=SensorList<BusType>;
|
||||
using IICSensorBase=SensorBase<BusType>;
|
||||
#define CFG_GET(name,prefix) \
|
||||
cfg->getValue(name, GwConfigDefinitions::prefix ## name)
|
||||
|
||||
@@ -100,33 +104,6 @@ void sendN2kTemperature(GwApi *api,CFG &cfg,double value, int counterId){
|
||||
}
|
||||
|
||||
|
||||
class SensorBase{
|
||||
public:
|
||||
int busId=0;
|
||||
int iid=99; //N2K instanceId
|
||||
int addr=-1;
|
||||
String prefix;
|
||||
long intv=0;
|
||||
bool ok=false;
|
||||
virtual void readConfig(GwConfigHandler *cfg)=0;
|
||||
SensorBase(GwApi *api,const String &prfx):prefix(prfx){
|
||||
}
|
||||
virtual bool isActive(){return false;};
|
||||
virtual bool initDevice(GwApi *api,TwoWire *wire){return false;};
|
||||
virtual bool preinit(GwApi * api){return false;}
|
||||
virtual void measure(GwApi * api,TwoWire *wire, int counterId){};
|
||||
virtual ~SensorBase(){}
|
||||
};
|
||||
|
||||
class SensorList : public std::vector<SensorBase*>{
|
||||
public:
|
||||
void add(GwApi *api, SensorBase *sensor){
|
||||
sensor->readConfig(api->getConfig());
|
||||
api->getLogger()->logDebug(GwLog::LOG,"configured sensor %s, status %d",sensor->prefix.c_str(),(int)sensor->ok);
|
||||
push_back(sensor);
|
||||
}
|
||||
using std::vector<SensorBase*>::vector;
|
||||
};
|
||||
|
||||
#define CHECK_IIC1() checkDef(GWIIC_SCL,GWIIC_SDA)
|
||||
#define CHECK_IIC2() checkDef(GWIIC_SCL2,GWIIC_SDA2)
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
void runIicTask(GwApi *api);
|
||||
|
||||
static SensorList sensors;
|
||||
static IICSensorList sensors;
|
||||
|
||||
void initIicTask(GwApi *api){
|
||||
GwLog *logger=api->getLogger();
|
||||
@@ -124,7 +124,7 @@ void runIicTask(GwApi *api){
|
||||
GwIntervalRunner timers;
|
||||
int counterId=api->addCounter("iicsensors");
|
||||
for (auto it=sensors.begin();it != sensors.end();it++){
|
||||
SensorBase *cfg=*it;
|
||||
IICSensorBase *cfg=*it;
|
||||
auto bus=buses.find(cfg->busId);
|
||||
if (! cfg->isActive()) continue;
|
||||
if (bus == buses.end()){
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define PRFX2 "QMP698812"
|
||||
#define PRFX3 "QMP698821"
|
||||
#define PRFX4 "QMP698822"
|
||||
class QMP6988Config : public SensorBase{
|
||||
class QMP6988Config : public IICSensorBase{
|
||||
public:
|
||||
String prNam="Pressure";
|
||||
bool prAct=true;
|
||||
@@ -76,7 +76,7 @@ class QMP6988Config : public SensorBase{
|
||||
|
||||
}
|
||||
};
|
||||
void registerQMP6988(GwApi *api,SensorList &sensors){
|
||||
void registerQMP6988(GwApi *api,IICSensorList &sensors){
|
||||
GwLog *logger=api->getLogger();
|
||||
#if defined(GWQMP6988) || defined(GWQMP698811)
|
||||
{
|
||||
@@ -113,5 +113,5 @@ void registerQMP6988(GwApi *api,SensorList &sensors){
|
||||
}
|
||||
|
||||
#else
|
||||
void registerQMP6988(GwApi *api,SensorList &sensors){}
|
||||
void registerQMP6988(GwApi *api,IICSensorList &sensors){}
|
||||
#endif
|
||||
@@ -18,5 +18,5 @@
|
||||
#ifdef _GWQMP6988
|
||||
#include "QMP6988.h"
|
||||
#endif
|
||||
void registerQMP6988(GwApi *api,SensorList &sensors);
|
||||
void registerQMP6988(GwApi *api,IICSensorList &sensors);
|
||||
#endif
|
||||
@@ -5,7 +5,7 @@
|
||||
#define PRFX2 "SHT3X12"
|
||||
#define PRFX3 "SHT3X21"
|
||||
#define PRFX4 "SHT3X22"
|
||||
class SHT3XConfig : public SensorBase{
|
||||
class SHT3XConfig : public IICSensorBase{
|
||||
public:
|
||||
String tmNam;
|
||||
String huNam;
|
||||
@@ -104,7 +104,7 @@ class SHT3XConfig : public SensorBase{
|
||||
intv*=1000;
|
||||
}
|
||||
};
|
||||
void registerSHT3X(GwApi *api,SensorList &sensors){
|
||||
void registerSHT3X(GwApi *api,IICSensorList &sensors){
|
||||
GwLog *logger=api->getLogger();
|
||||
#if defined(GWSHT3X) || defined (GWSHT3X11)
|
||||
{
|
||||
@@ -140,7 +140,7 @@ void registerSHT3X(GwApi *api,SensorList &sensors){
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
void registerSHT3X(GwApi *api,SensorList &sensors){
|
||||
void registerSHT3X(GwApi *api,IICSensorList &sensors){
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,5 +18,5 @@
|
||||
#ifdef _GWSHT3X
|
||||
#include "SHT3X.h"
|
||||
#endif
|
||||
void registerSHT3X(GwApi *api,SensorList &sensors);
|
||||
void registerSHT3X(GwApi *api,IICSensorList &sensors);
|
||||
#endif
|
||||
Reference in New Issue
Block a user