restructure SSI sensor
This commit is contained in:
parent
d5a1c9c4ae
commit
38acd5a30b
|
@ -55,7 +55,6 @@ class BME280Config : public IICSensorBase{
|
||||||
virtual bool preinit(GwApi * api){
|
virtual bool preinit(GwApi * api){
|
||||||
GwLog *logger=api->getLogger();
|
GwLog *logger=api->getLogger();
|
||||||
LOG_DEBUG(GwLog::LOG,"%s configured",prefix.c_str());
|
LOG_DEBUG(GwLog::LOG,"%s configured",prefix.c_str());
|
||||||
api->addCapability(prefix,"true");
|
|
||||||
addPressureXdr(api,*this);
|
addPressureXdr(api,*this);
|
||||||
addTempXdr(api,*this);
|
addTempXdr(api,*this);
|
||||||
addHumidXdr(api,*this);
|
addHumidXdr(api,*this);
|
||||||
|
|
|
@ -56,7 +56,6 @@ class BMP280Config : public IICSensorBase{
|
||||||
virtual bool preinit(GwApi * api){
|
virtual bool preinit(GwApi * api){
|
||||||
GwLog *logger=api->getLogger();
|
GwLog *logger=api->getLogger();
|
||||||
LOG_DEBUG(GwLog::LOG,"%s configured",prefix.c_str());
|
LOG_DEBUG(GwLog::LOG,"%s configured",prefix.c_str());
|
||||||
api->addCapability(prefix,"true");
|
|
||||||
addPressureXdr(api,*this);
|
addPressureXdr(api,*this);
|
||||||
addTempXdr(api,*this);
|
addTempXdr(api,*this);
|
||||||
return isActive();
|
return isActive();
|
||||||
|
|
|
@ -30,7 +30,6 @@ class QMP6988Config : public IICSensorBase{
|
||||||
virtual bool preinit(GwApi * api){
|
virtual bool preinit(GwApi * api){
|
||||||
GwLog *logger=api->getLogger();
|
GwLog *logger=api->getLogger();
|
||||||
LOG_DEBUG(GwLog::LOG,"QMP6988 configured");
|
LOG_DEBUG(GwLog::LOG,"QMP6988 configured");
|
||||||
api->addCapability(prefix,"true");
|
|
||||||
addPressureXdr(api,*this);
|
addPressureXdr(api,*this);
|
||||||
return isActive();
|
return isActive();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ class SHT3XConfig : public IICSensorBase{
|
||||||
virtual bool preinit(GwApi * api){
|
virtual bool preinit(GwApi * api){
|
||||||
GwLog *logger=api->getLogger();
|
GwLog *logger=api->getLogger();
|
||||||
LOG_DEBUG(GwLog::LOG,"%s configured",prefix.c_str());
|
LOG_DEBUG(GwLog::LOG,"%s configured",prefix.c_str());
|
||||||
api->addCapability(prefix,"true");
|
|
||||||
addHumidXdr(api,*this);
|
addHumidXdr(api,*this);
|
||||||
addTempXdr(api,*this);
|
addTempXdr(api,*this);
|
||||||
return isActive();
|
return isActive();
|
||||||
|
|
|
@ -21,76 +21,23 @@
|
||||||
#define CHECK_BUS(BUS) \
|
#define CHECK_BUS(BUS) \
|
||||||
checkDef("missing config for " #BUS,GW ## BUS ## _CLK ,GW ## BUS ## _MISO);
|
checkDef("missing config for " #BUS,GW ## BUS ## _CLK ,GW ## BUS ## _MISO);
|
||||||
|
|
||||||
#define ADD22B(PRFX,BUS) \
|
|
||||||
{\
|
|
||||||
CHECK_BUS(BUS); \
|
|
||||||
GWDMS22B *dms=new GWDMS22B(api,#PRFX,GW ## BUS ## _HOST);\
|
|
||||||
api->addSensor(dms,true); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef GWDMS22B11
|
|
||||||
#define ADD22B11 ADD22B(DMS22B11,SPI1)
|
|
||||||
#ifndef GWDMS22B11_CS
|
|
||||||
#define GWDMS22B11_CS -1
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define GWDMS22B11_CS -1
|
|
||||||
#define ADD22B11
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GWDMS22B12
|
|
||||||
#define ADD22B12 ADD22B(DMS22B12,SPI1)
|
|
||||||
#ifndef GWDMS22B12_CS
|
|
||||||
#error "you need to define GWDMS22B12_CS"
|
|
||||||
#endif
|
|
||||||
#if GWDMS22B11_CS == -1
|
|
||||||
#error "multiple devices on one SPI bus need chip select defines - GWDMS22B11_CS is unset"
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define GWDMS22B12_CS -1
|
|
||||||
#define ADD22B12
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef GWDMS22B21
|
|
||||||
#define ADD22B21 ADD22B(DMS22B21,SPI2)
|
|
||||||
#ifndef GWDMS22B21_CS
|
|
||||||
#define GWDMS22B21_CS -1
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define GWDMS22B21_CS -1
|
|
||||||
#define ADD22B21
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GWDMS22B22
|
|
||||||
#define ADD22B22 ADD22B(DMS22B22,SPI2)
|
|
||||||
#ifndef GWDMS22B22_CS
|
|
||||||
#error "you need to define GWDMS22B22_CS"
|
|
||||||
#endif
|
|
||||||
#if GWDMS22B21_CS == -1
|
|
||||||
#error "multiple devices on one SPI bus need chip select defines - GWDMS22B21_CS is unset"
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define GWDMS22B22_CS -1
|
|
||||||
#define ADD22B22
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
class GWDMS22B;
|
||||||
|
static GwSensorConfigInitializerList<GWDMS22B> configs;
|
||||||
|
|
||||||
|
|
||||||
class GWDMS22B : public SSISensor{
|
class GWDMS22B : public SSISensor{
|
||||||
|
public:
|
||||||
int zero=2047;
|
int zero=2047;
|
||||||
bool invt=false;
|
bool invt=false;
|
||||||
String zeroConfigName;
|
String zeroConfigName;
|
||||||
public:
|
GWDMS22B(GwApi *api,const String &prfx):SSISensor(api,prfx){}
|
||||||
GWDMS22B(GwApi *api,const String &prfx, int host):SSISensor(api,prfx,host){}
|
|
||||||
virtual bool preinit(GwApi * api){
|
virtual bool preinit(GwApi * api){
|
||||||
GwLog *logger=api->getLogger();
|
GwLog *logger=api->getLogger();
|
||||||
LOG_DEBUG(GwLog::LOG,"DMS22B configured, prefix=%s, intv=%f, active=%d",prefix.c_str(),fintv,(int)act);
|
LOG_DEBUG(GwLog::LOG,"DMS22B configured, prefix=%s, intv=%f, active=%d",prefix.c_str(),fintv,(int)act);
|
||||||
api->addCapability(prefix,"true");
|
|
||||||
return act;
|
return act;
|
||||||
}
|
}
|
||||||
virtual void measure(GwApi * api,BusType *bus, int counterId){
|
virtual void measure(GwApi * api,BUSTYPE *bus, int counterId){
|
||||||
GwLog *logger=api->getLogger();
|
GwLog *logger=api->getLogger();
|
||||||
uint32_t value=0;
|
uint32_t value=0;
|
||||||
esp_err_t res=readData(value);
|
esp_err_t res=readData(value);
|
||||||
|
@ -106,34 +53,84 @@ class GWDMS22B : public SSISensor{
|
||||||
api->increment(counterId,prefix);
|
api->increment(counterId,prefix);
|
||||||
api->setCalibrationValue(zeroConfigName,(double)value);
|
api->setCalibrationValue(zeroConfigName,(double)value);
|
||||||
}
|
}
|
||||||
#define DMS22B(PRFX,...) \
|
|
||||||
if (prefix == #PRFX) {\
|
|
||||||
CFG_GET(act,PRFX); \
|
|
||||||
CFG_GET(iid,PRFX); \
|
|
||||||
CFG_GET(fintv,PRFX); \
|
|
||||||
CFG_GET(zero,PRFX); \
|
|
||||||
zeroConfigName=GwConfigDefinitions::PRFX ## zero;\
|
|
||||||
CFG_GET(invt,PRFX); \
|
|
||||||
bits=12; \
|
|
||||||
clock=500000; \
|
|
||||||
cs=GW ## PRFX ## _CS; \
|
|
||||||
__VA_ARGS__ \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
virtual void readConfig(GwConfigHandler *cfg){
|
virtual void readConfig(GwConfigHandler *cfg){
|
||||||
DMS22B(DMS22B11);
|
if (ok) return;
|
||||||
DMS22B(DMS22B12);
|
configs.readConfig(this,cfg);
|
||||||
DMS22B(DMS22B21);
|
|
||||||
DMS22B(DMS22B22);
|
|
||||||
intv=1000*fintv;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void registerDMS22B(GwApi *api){
|
#define ADD22B(PRFX,BUS) \
|
||||||
ADD22B11
|
{\
|
||||||
ADD22B12
|
CHECK_BUS(BUS); \
|
||||||
ADD22B21
|
GWDMS22B *dms=new GWDMS22B(api,#PRFX);\
|
||||||
ADD22B22
|
api->addSensor(dms,true); \
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void registerDMS22B(GwApi *api){
|
||||||
|
#ifdef GWDMS22B11
|
||||||
|
ADD22B(DMS22B11,SPI1)
|
||||||
|
#ifndef GWDMS22B11_CS
|
||||||
|
#define GWDMS22B11_CS -1
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define GWDMS22B11_CS -1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GWDMS22B12
|
||||||
|
ADD22B(DMS22B12,SPI1)
|
||||||
|
#ifndef GWDMS22B12_CS
|
||||||
|
#error "you need to define GWDMS22B12_CS"
|
||||||
|
#endif
|
||||||
|
#if GWDMS22B11_CS == -1
|
||||||
|
#error "multiple devices on one SPI bus need chip select defines - GWDMS22B11_CS is unset"
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define GWDMS22B12_CS -1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef GWDMS22B21
|
||||||
|
ADD22B(DMS22B21,SPI2)
|
||||||
|
#ifndef GWDMS22B21_CS
|
||||||
|
#define GWDMS22B21_CS -1
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define GWDMS22B21_CS -1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GWDMS22B22
|
||||||
|
ADD22B(DMS22B22,SPI2)
|
||||||
|
#ifndef GWDMS22B22_CS
|
||||||
|
#error "you need to define GWDMS22B22_CS"
|
||||||
|
#endif
|
||||||
|
#if GWDMS22B21_CS == -1
|
||||||
|
#error "multiple devices on one SPI bus need chip select defines - GWDMS22B21_CS is unset"
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define GWDMS22B22_CS -1
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define CFGDMS22B(s,PRFX,bus,csv) \
|
||||||
|
CFG_SGET(s,act,PRFX); \
|
||||||
|
CFG_SGET(s,iid,PRFX); \
|
||||||
|
CFG_SGET(s,fintv,PRFX); \
|
||||||
|
CFG_SGET(s,zero,PRFX); \
|
||||||
|
s->zeroConfigName=GwConfigDefinitions::PRFX ## zero;\
|
||||||
|
CFG_SGET(s,invt,PRFX); \
|
||||||
|
s->bits=12; \
|
||||||
|
s->clock=500000; \
|
||||||
|
s->cs=csv; \
|
||||||
|
s->busId=bus; \
|
||||||
|
s->intv=1000*s->fintv; \
|
||||||
|
s->ok=true;
|
||||||
|
|
||||||
|
#define SCDMS22B(prefix,bus) \
|
||||||
|
GWSENSORDEF(configs,GWDMS22B,CFGDMS22B,prefix,GW ## bus ## _HOST,GW ## prefix ## _CS)
|
||||||
|
|
||||||
|
SCDMS22B(DMS22B11,SPI1);
|
||||||
|
SCDMS22B(DMS22B12,SPI1);
|
||||||
|
SCDMS22B(DMS22B21,SPI2);
|
||||||
|
SCDMS22B(DMS22B22,SPI2);
|
||||||
|
|
|
@ -92,13 +92,14 @@ class SSIDevice{
|
||||||
|
|
||||||
class SSISensor : public SensorTemplate<BUSTYPE,SensorBase::SPI>{
|
class SSISensor : public SensorTemplate<BUSTYPE,SensorBase::SPI>{
|
||||||
std::unique_ptr<SSIDevice> device;
|
std::unique_ptr<SSIDevice> device;
|
||||||
protected:
|
public:
|
||||||
int bits=12;
|
int bits=12;
|
||||||
int mask=0xffff;
|
int mask=0xffff;
|
||||||
int cs=-1;
|
int cs=-1;
|
||||||
int clock=0;
|
int clock=0;
|
||||||
bool act=false;
|
bool act=false;
|
||||||
float fintv=0;
|
float fintv=0;
|
||||||
|
protected:
|
||||||
virtual bool initSSI(GwLog*logger,const SPIBus *bus,
|
virtual bool initSSI(GwLog*logger,const SPIBus *bus,
|
||||||
int clock,int cs, int bits){
|
int clock,int cs, int bits){
|
||||||
mask= (1 << bits)-1;
|
mask= (1 << bits)-1;
|
||||||
|
@ -125,9 +126,8 @@ class SSISensor : public SensorTemplate<BUSTYPE,SensorBase::SPI>{
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SSISensor(GwApi *api,const String &prfx, int host):SensorTemplate<BUSTYPE,SensorBase::SPI>(api,prfx)
|
SSISensor(GwApi *api,const String &prfx):SensorTemplate<BUSTYPE,SensorBase::SPI>(api,prfx)
|
||||||
{
|
{
|
||||||
busId=host;
|
|
||||||
}
|
}
|
||||||
virtual bool isActive(){return act;};
|
virtual bool isActive(){return act;};
|
||||||
virtual bool initDevice(GwApi *api,BUSTYPE *bus){
|
virtual bool initDevice(GwApi *api,BUSTYPE *bus){
|
||||||
|
|
Loading…
Reference in New Issue