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

make SensorBase more generic

This commit is contained in:
andreas
2024-03-01 15:13:11 +01:00
parent 8a5bdd710e
commit b3d065abd1
10 changed files with 68 additions and 41 deletions

View File

@@ -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)