continue restructuring sensors, test env3
This commit is contained in:
parent
243c20c468
commit
7a7068e77c
|
@ -15,11 +15,9 @@
|
|||
#include <Adafruit_BME280.h>
|
||||
#endif
|
||||
#ifdef _GWBME280
|
||||
#define TYPE "BME280"
|
||||
#define PRFX1 TYPE "11"
|
||||
#define PRFX2 TYPE "12"
|
||||
#define PRFX3 TYPE "21"
|
||||
#define PRFX4 TYPE "22"
|
||||
|
||||
class BME280Config;
|
||||
static GwSensorConfigInitializerList<BME280Config> configs;
|
||||
class BME280Config : public IICSensorBase{
|
||||
public:
|
||||
bool prAct=true;
|
||||
|
@ -97,89 +95,77 @@ class BME280Config : public IICSensorBase{
|
|||
sendN2kEnvironmentalParameters(api, *this, temperature, humidity, computed,counterId);
|
||||
}
|
||||
}
|
||||
#define CFG280(prefix) \
|
||||
CFG_GET(prAct,prefix); \
|
||||
CFG_GET(tmAct,prefix);\
|
||||
CFG_GET(huAct,prefix);\
|
||||
CFG_GET(tmSrc,prefix);\
|
||||
CFG_GET(huSrc,prefix);\
|
||||
CFG_GET(iid,prefix);\
|
||||
CFG_GET(intv,prefix);\
|
||||
CFG_GET(tmNam,prefix);\
|
||||
CFG_GET(huNam,prefix);\
|
||||
CFG_GET(prNam,prefix);\
|
||||
CFG_GET(tmOff,prefix);\
|
||||
CFG_GET(prOff,prefix);
|
||||
|
||||
|
||||
virtual void readConfig(GwConfigHandler *cfg) override
|
||||
{
|
||||
if (ok) return;
|
||||
if (prefix == PRFX1)
|
||||
{
|
||||
busId = 1;
|
||||
addr = 0x76;
|
||||
CFG280(BME28011);
|
||||
ok=true;
|
||||
}
|
||||
if (prefix == PRFX2)
|
||||
{
|
||||
busId = 1;
|
||||
addr = 0x77;
|
||||
CFG280(BME28012);
|
||||
ok=true;
|
||||
}
|
||||
if (prefix == PRFX3)
|
||||
{
|
||||
busId = 2;
|
||||
addr = 0x76;
|
||||
CFG280(BME28021);
|
||||
ok=true;
|
||||
}
|
||||
if (prefix == PRFX4)
|
||||
{
|
||||
busId = 2;
|
||||
addr = 0x77;
|
||||
CFG280(BME28022);
|
||||
ok=true;
|
||||
}
|
||||
intv *= 1000;
|
||||
configs.readConfig(this,cfg);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static SensorBase::Creator creator([](GwApi *api, const String &prfx){
|
||||
return new BME280Config(api,prfx);
|
||||
});
|
||||
SensorBase::Creator registerBME280(GwApi *api){
|
||||
#if defined(GWBME280) || defined(GWBME28011)
|
||||
#if defined(GWBME280) || defined(GWBME28011)
|
||||
{
|
||||
api->addSensor(creator(api,PRFX1));
|
||||
api->addSensor(creator(api,"BME28011"));
|
||||
CHECK_IIC1();
|
||||
#pragma message "GWBME28011 defined"
|
||||
}
|
||||
#endif
|
||||
#if defined(GWBME28012)
|
||||
#endif
|
||||
#if defined(GWBME28012)
|
||||
{
|
||||
api->addSensor(creator(api,PRFX2));
|
||||
api->addSensor(creator(api,"BME28012"));
|
||||
CHECK_IIC1();
|
||||
#pragma message "GWBME28012 defined"
|
||||
}
|
||||
#endif
|
||||
#if defined(GWBME28021)
|
||||
#endif
|
||||
#if defined(GWBME28021)
|
||||
{
|
||||
api->addSensor(creator(api,PRFX3));
|
||||
api->addSensor(creator(api,"BME28021"));
|
||||
CHECK_IIC2();
|
||||
#pragma message "GWBME28021 defined"
|
||||
}
|
||||
#endif
|
||||
#if defined(GWBME28022)
|
||||
#endif
|
||||
#if defined(GWBME28022)
|
||||
{
|
||||
api->addSensor(creator(api,PRFX4));
|
||||
api->addSensor(creator(api,"BME28022"));
|
||||
CHECK_IIC1();
|
||||
#pragma message "GWBME28022 defined"
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return creator;
|
||||
}
|
||||
|
||||
#define CFG280(s, prefix, bus, baddr) \
|
||||
CFG_SGET(s, prAct, prefix); \
|
||||
CFG_SGET(s, tmAct, prefix); \
|
||||
CFG_SGET(s, huAct, prefix); \
|
||||
CFG_SGET(s, tmSrc, prefix); \
|
||||
CFG_SGET(s, huSrc, prefix); \
|
||||
CFG_SGET(s, iid, prefix); \
|
||||
CFG_SGET(s, intv, prefix); \
|
||||
CFG_SGET(s, tmNam, prefix); \
|
||||
CFG_SGET(s, huNam, prefix); \
|
||||
CFG_SGET(s, prNam, prefix); \
|
||||
CFG_SGET(s, tmOff, prefix); \
|
||||
CFG_SGET(s, prOff, prefix); \
|
||||
s->busId = bus; \
|
||||
s->addr = baddr; \
|
||||
s->ok = true; \
|
||||
s->intv *= 1000;
|
||||
|
||||
#define SCBME280(list, prefix, bus, addr) \
|
||||
GWSENSORCONFIG(list, BME280Config, prefix, [](BME280Config *s, GwConfigHandler *cfg) { CFG280(s, prefix, bus, addr); });
|
||||
|
||||
SCBME280(configs,BME28011,1,0x76);
|
||||
SCBME280(configs,BME28012,1,0x77);
|
||||
SCBME280(configs,BME28021,2,0x76);
|
||||
SCBME280(configs,BME28022,2,0x77);
|
||||
|
||||
#else
|
||||
SensorBase::Creator registerBME280(GwApi *api){
|
||||
return SensorBase::Creator();
|
||||
|
|
|
@ -105,7 +105,10 @@ void initIicTask(GwApi *api){
|
|||
ConfiguredSensors sensorList=api->taskInterfaces()->get<ConfiguredSensors>(res);
|
||||
for (auto &&it: sensorList.sensors){
|
||||
if (it->busType != SensorBase::IIC) continue;
|
||||
if (it->preinit(api)) addTask=true;
|
||||
if (it->preinit(api)) {
|
||||
addTask=true;
|
||||
api->addCapability(it->prefix,"true");
|
||||
}
|
||||
}
|
||||
if (addTask){
|
||||
api->addUserTask(runIicTask,"iicTask",4000);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -106,27 +106,27 @@ SensorBase::Creator registerSHT3X(GwApi *api){
|
|||
* just to get compile time errors if something does not fit
|
||||
* correctly
|
||||
*/
|
||||
#define CFGSHT3X(s,prefix,bus,baddr) \
|
||||
CFG_SGET(s,tmNam,prefix); \
|
||||
CFG_SGET(s,huNam,prefix); \
|
||||
CFG_SGET(s,iid,prefix); \
|
||||
CFG_SGET(s,tmAct,prefix); \
|
||||
CFG_SGET(s,huAct,prefix); \
|
||||
CFG_SGET(s,intv,prefix); \
|
||||
CFG_SGET(s,huSrc,prefix); \
|
||||
CFG_SGET(s,tmSrc,prefix); \
|
||||
#define CFGSHT3X(s, prefix, bus, baddr) \
|
||||
CFG_SGET(s, tmNam, prefix); \
|
||||
CFG_SGET(s, huNam, prefix); \
|
||||
CFG_SGET(s, iid, prefix); \
|
||||
CFG_SGET(s, tmAct, prefix); \
|
||||
CFG_SGET(s, huAct, prefix); \
|
||||
CFG_SGET(s, intv, prefix); \
|
||||
CFG_SGET(s, huSrc, prefix); \
|
||||
CFG_SGET(s, tmSrc, prefix); \
|
||||
s->busId = bus; \
|
||||
s->addr = baddr; \
|
||||
s->ok = true; \
|
||||
s->intv*=1000;
|
||||
s->intv *= 1000;
|
||||
|
||||
#define SCSHT3X(list, prefix, bus, addr) \
|
||||
GWSENSORCONFIG(list, SHT3XConfig, prefix, [](SHT3XConfig *s, GwConfigHandler *cfg) { CFGSHT3X(s, prefix, bus, addr); });
|
||||
#define SCSHT3X(prefix, bus, addr) \
|
||||
GWSENSORDEF(configs, SHT3XConfig, CFGSHT3X, prefix, bus, addr)
|
||||
|
||||
SCSHT3X(configs, SHT3X11,1, 0x44);
|
||||
SCSHT3X(configs, SHT3X12,1, 0x45);
|
||||
SCSHT3X(configs, SHT3X21,2, 0x44);
|
||||
SCSHT3X(configs, SHT3X22,2, 0x45);
|
||||
SCSHT3X(SHT3X11, 1, 0x44);
|
||||
SCSHT3X(SHT3X12, 1, 0x45);
|
||||
SCSHT3X(SHT3X21, 2, 0x44);
|
||||
SCSHT3X(SHT3X22, 2, 0x45);
|
||||
|
||||
#else
|
||||
SensorBase::Creator registerSHT3X(GwApi *api){
|
||||
|
|
|
@ -61,6 +61,8 @@ class SensorTemplate : public SensorBase{
|
|||
if (busType != bt) return;
|
||||
measure(api,(BUS*)bus,counterId);
|
||||
};
|
||||
protected:
|
||||
virtual void measure(GwApi *api,BUS *bus, int counterId)=0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -124,7 +126,8 @@ class GwSensorConfigInitializerList : public GwInitializer<GwSensorConfig<T>>::L
|
|||
|
||||
#define GWSENSORCONFIG(list,type,prefix,initFunction) \
|
||||
GwSensorConfigInitializer<type> __init ## type ## prefix(list,GwSensorConfig<type>(#prefix,initFunction));
|
||||
|
||||
#define GWSENSORDEF(list,type,init,prefix,bus,baddr) \
|
||||
GWSENSORCONFIG(list, type, prefix, [](type *s, GwConfigHandler *cfg) { init(s, prefix, bus, baddr); });
|
||||
|
||||
|
||||
#define CFG_GET(name,prefix) \
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
{\
|
||||
CHECK_BUS(BUS); \
|
||||
GWDMS22B *dms=new GWDMS22B(api,#PRFX,GW ## BUS ## _HOST);\
|
||||
sensors.add(api,dms); \
|
||||
api->addSensor(dms,true); \
|
||||
}
|
||||
|
||||
#ifdef GWDMS22B11
|
||||
|
@ -130,7 +130,7 @@ class GWDMS22B : public SSISensor{
|
|||
}
|
||||
};
|
||||
|
||||
void registerDMS22B(GwApi *api,SpiSensorList &sensors){
|
||||
void registerDMS22B(GwApi *api){
|
||||
ADD22B11
|
||||
ADD22B12
|
||||
ADD22B21
|
||||
|
|
|
@ -18,5 +18,5 @@ SSI sensor DMS22B - https://www.mouser.de/datasheet/2/54/bour_s_a0011704065_1-22
|
|||
#ifndef _GWDMS22B_H
|
||||
#define _GWDMS22B_H
|
||||
#include "GwSpiSensor.h"
|
||||
void registerDMS22B(GwApi *api,SpiSensorList &sensors);
|
||||
void registerDMS22B(GwApi *api);
|
||||
#endif
|
|
@ -21,8 +21,6 @@
|
|||
static SPIBus bus1(GWSPI1_HOST);
|
||||
static SPIBus bus2(GWSPI2_HOST);
|
||||
|
||||
static SpiSensorList sensors;
|
||||
|
||||
#ifdef GWSPI1_CLK
|
||||
static const int spi1clk=GWSPI1_CLK;
|
||||
#else
|
||||
|
@ -57,8 +55,11 @@ static const int spi2mosi=-1;
|
|||
|
||||
void runSpiTask(GwApi *api){
|
||||
GwLog *logger=api->getLogger();
|
||||
int res=-1;
|
||||
ConfiguredSensors sensorList=api->taskInterfaces()->get<ConfiguredSensors>(res);
|
||||
std::map<int,SPIBus *> buses;
|
||||
for (auto && sensor:sensors){
|
||||
for (auto && sensor: sensorList.sensors){
|
||||
if (sensor->busType != SensorBase::BusType::SPI) continue;
|
||||
int busId=sensor->busId;
|
||||
auto bus=buses.find(busId);
|
||||
if (bus == buses.end()){
|
||||
|
@ -93,7 +94,7 @@ void runSpiTask(GwApi *api){
|
|||
bool runLoop=false;
|
||||
GwIntervalRunner timers;
|
||||
int counterId=api->addCounter("spisensors");
|
||||
for (auto && sensor:sensors){
|
||||
for (auto && sensor: sensorList.sensors){
|
||||
if (!sensor->isActive()) continue;
|
||||
auto bus=buses.find(sensor->busId);
|
||||
if (bus == buses.end()){
|
||||
|
@ -122,10 +123,16 @@ void runSpiTask(GwApi *api){
|
|||
|
||||
void initSpiTask(GwApi *api){
|
||||
GwLog *logger=api->getLogger();
|
||||
registerDMS22B(api,sensors);
|
||||
int res=-1;
|
||||
registerDMS22B(api);
|
||||
ConfiguredSensors sensorList=api->taskInterfaces()->get<ConfiguredSensors>(res);
|
||||
bool addTask=false;
|
||||
for (auto && sensor:sensors){
|
||||
if (sensor->preinit(api)) addTask=true;
|
||||
for (auto && sensor:sensorList.sensors){
|
||||
if (sensor->busType != SensorBase::BusType::SPI) continue;
|
||||
if (sensor->preinit(api)) {
|
||||
api->addCapability(sensor->prefix,"true");
|
||||
addTask=true;
|
||||
}
|
||||
}
|
||||
if (addTask){
|
||||
api->addUserTask(runSpiTask,"spiTask",3000);
|
||||
|
|
|
@ -161,7 +161,6 @@ class TaskApi : public GwApiInternal
|
|||
GwApiInternal *api=nullptr;
|
||||
int sourceId;
|
||||
SemaphoreHandle_t mainLock;
|
||||
SemaphoreHandle_t mainLock;
|
||||
SemaphoreHandle_t localLock;
|
||||
std::map<int,GwCounter<String>> counter;
|
||||
std::map<String,GwApi::HandlerFunction> webHandlers;
|
||||
|
|
Loading…
Reference in New Issue