mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-16 07:23:07 +01:00
continue restructuring sensors, test env3
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
#define _IIC_GROOVE_LIST
|
||||
#include "GwQMP6988.h"
|
||||
#ifdef _GWQMP6988
|
||||
#define TYPE "QMP6988"
|
||||
#define PRFX1 TYPE "11"
|
||||
#define PRFX2 TYPE "12"
|
||||
#define PRFX3 TYPE "21"
|
||||
#define PRFX4 TYPE "22"
|
||||
|
||||
class QMP6988Config;
|
||||
static GwSensorConfigInitializerList<QMP6988Config> configs;
|
||||
|
||||
class QMP6988Config : public IICSensorBase{
|
||||
public:
|
||||
String prNam="Pressure";
|
||||
@@ -13,7 +12,7 @@ class QMP6988Config : public IICSensorBase{
|
||||
tN2kPressureSource prSrc=tN2kPressureSource::N2kps_Atmospheric;
|
||||
float prOff=0;
|
||||
QMP6988 *device=nullptr;
|
||||
QMP6988Config(GwApi* api,const String &prefix):SensorBase(TYPE,api,prefix){}
|
||||
QMP6988Config(GwApi* api,const String &prefix):IICSensorBase(api,prefix){}
|
||||
virtual bool isActive(){return prAct;};
|
||||
virtual bool initDevice(GwApi *api,TwoWire *wire){
|
||||
if (!isActive()) return false;
|
||||
@@ -42,72 +41,43 @@ class QMP6988Config : public IICSensorBase{
|
||||
LOG_DEBUG(GwLog::DEBUG,"%s measure %2.0fPa, computed %2.0fPa",prefix.c_str(), pressure,computed);
|
||||
sendN2kPressure(api,*this,computed,counterId);
|
||||
}
|
||||
#define CFG6988(prefix)\
|
||||
CFG_GET(prNam,prefix); \
|
||||
CFG_GET(iid,prefix); \
|
||||
CFG_GET(prAct,prefix); \
|
||||
CFG_GET(intv,prefix); \
|
||||
CFG_GET(prOff,prefix);
|
||||
|
||||
|
||||
virtual void readConfig(GwConfigHandler *cfg){
|
||||
if (ok) return;
|
||||
if (prefix == PRFX1){
|
||||
busId=1;
|
||||
addr=86;
|
||||
CFG6988(QMP698811);
|
||||
ok=true;
|
||||
}
|
||||
if (prefix == PRFX2){
|
||||
busId=1;
|
||||
addr=112;
|
||||
CFG6988(QMP698812);
|
||||
ok=true;
|
||||
}
|
||||
if (prefix == PRFX3){
|
||||
busId=2;
|
||||
addr=86;
|
||||
CFG6988(QMP698821);
|
||||
ok=true;
|
||||
}
|
||||
if (prefix == PRFX4){
|
||||
busId=2;
|
||||
addr=112;
|
||||
CFG6988(QMP698822);
|
||||
ok=true;
|
||||
}
|
||||
intv*=1000;
|
||||
|
||||
configs.readConfig(this,cfg);
|
||||
}
|
||||
};
|
||||
static SensorBase::Creator creator=[](GwApi *api,const String &prfx){
|
||||
static SensorBase::Creator creator=[](GwApi *api,const String &prfx)-> SensorBase*{
|
||||
if (! configs.knowsPrefix(prfx)) return nullptr;
|
||||
return new QMP6988Config(api,prfx);
|
||||
};
|
||||
SensorBase::Creator registerQMP6988(GwApi *api,IICSensorList &sensors){
|
||||
SensorBase::Creator registerQMP6988(GwApi *api){
|
||||
GwLog *logger=api->getLogger();
|
||||
#if defined(GWQMP6988) || defined(GWQMP698811)
|
||||
{
|
||||
api->addSensor(new QMP6988Config(api,PRFX1));
|
||||
api->addSensor(new QMP6988Config(api,"QMP698811"));
|
||||
CHECK_IIC1();
|
||||
#pragma message "GWQMP698811 defined"
|
||||
}
|
||||
#endif
|
||||
#if defined(GWQMP698812)
|
||||
{
|
||||
api->addSensor(new QMP6988Config(api,PRFX2));
|
||||
api->addSensor(new QMP6988Config(api,"QMP698812"));
|
||||
CHECK_IIC1();
|
||||
#pragma message "GWQMP698812 defined"
|
||||
}
|
||||
#endif
|
||||
#if defined(GWQMP698821)
|
||||
{
|
||||
api->addSensor(new QMP6988Config(api,PRFX3));
|
||||
api->addSensor(new QMP6988Config(api,"QMP698821"));
|
||||
CHECK_IIC2();
|
||||
#pragma message "GWQMP698821 defined"
|
||||
}
|
||||
#endif
|
||||
#if defined(GWQMP698822)
|
||||
{
|
||||
api->addSensor(new QMP6988Config(api,PRFX4));
|
||||
api->addSensor(new QMP6988Config(api,"QMP698822"));
|
||||
CHECK_IIC2();
|
||||
#pragma message "GWQMP698822 defined"
|
||||
}
|
||||
@@ -115,6 +85,26 @@ SensorBase::Creator registerQMP6988(GwApi *api,IICSensorList &sensors){
|
||||
return creator;
|
||||
}
|
||||
|
||||
#define CFG6988(s,prefix,bus,baddr)\
|
||||
CFG_SGET(s,prNam,prefix); \
|
||||
CFG_SGET(s,iid,prefix); \
|
||||
CFG_SGET(s,prAct,prefix); \
|
||||
CFG_SGET(s,intv,prefix); \
|
||||
CFG_SGET(s,prOff,prefix); \
|
||||
s->busId = bus; \
|
||||
s->addr = baddr; \
|
||||
s->ok = true; \
|
||||
s->intv*=1000;
|
||||
|
||||
|
||||
#define SC6988(prefix,bus,addr) \
|
||||
GWSENSORDEF(configs,QMP6988Config,CFG6988,prefix,bus,addr)
|
||||
|
||||
SC6988(QMP698811,1,86);
|
||||
SC6988(QMP698812,1,112);
|
||||
SC6988(QMP698821,2,86);
|
||||
SC6988(QMP698822,2,112);
|
||||
|
||||
#else
|
||||
SensorBase::Creator registerQMP6988(GwApi *api){
|
||||
return SensorBase::Creator();
|
||||
|
||||
Reference in New Issue
Block a user