mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2026-03-28 18:06:37 +01:00
Integrate many changes from master
This commit is contained in:
@@ -23,6 +23,7 @@ class BME280Config : public IICSensorBase{
|
||||
bool prAct=true;
|
||||
bool tmAct=true;
|
||||
bool huAct=true;
|
||||
bool sEnv=true;
|
||||
tN2kTempSource tmSrc=tN2kTempSource::N2kts_InsideTemperature;
|
||||
tN2kHumiditySource huSrc=tN2kHumiditySource::N2khs_InsideHumidity;
|
||||
tN2kPressureSource prSrc=tN2kPressureSource::N2kps_Atmospheric;
|
||||
@@ -152,6 +153,7 @@ SensorBase::Creator registerBME280(GwApi *api){
|
||||
CFG_SGET(s, prNam, prefix); \
|
||||
CFG_SGET(s, tmOff, prefix); \
|
||||
CFG_SGET(s, prOff, prefix); \
|
||||
CFG_SGET(s, sEnv, prefix); \
|
||||
s->busId = bus; \
|
||||
s->addr = baddr; \
|
||||
s->ok = true; \
|
||||
|
||||
@@ -29,6 +29,7 @@ class BMP280Config : public IICSensorBase{
|
||||
public:
|
||||
bool prAct=true;
|
||||
bool tmAct=true;
|
||||
bool sEnv=true;
|
||||
tN2kTempSource tmSrc=tN2kTempSource::N2kts_InsideTemperature;
|
||||
tN2kPressureSource prSrc=tN2kPressureSource::N2kps_Atmospheric;
|
||||
tN2kHumiditySource huSrc=tN2kHumiditySource::N2khs_Undef;
|
||||
@@ -150,6 +151,7 @@ SensorBase::Creator registerBMP280(GwApi *api){
|
||||
CFG_SGET(s, prNam, prefix); \
|
||||
CFG_SGET(s, tmOff, prefix); \
|
||||
CFG_SGET(s, prOff, prefix); \
|
||||
CFG_SGET(s, sEnv,prefix); \
|
||||
s->busId = bus; \
|
||||
s->addr = baddr; \
|
||||
s->ok = true; \
|
||||
|
||||
@@ -104,12 +104,19 @@ void sendN2kTemperature(GwApi *api,CFG &cfg,double value, int counterId){
|
||||
|
||||
template <class CFG>
|
||||
void sendN2kEnvironmentalParameters(GwApi *api,CFG &cfg,double tmValue, double huValue, double prValue, int counterId){
|
||||
if (! cfg.sEnv) return;
|
||||
tN2kMsg msg;
|
||||
SetN2kEnvironmentalParameters(msg,1,cfg.tmSrc,tmValue,cfg.huSrc,huValue,prValue);
|
||||
api->sendN2kMessage(msg);
|
||||
api->increment(counterId,cfg.prefix+String("hum"));
|
||||
api->increment(counterId,cfg.prefix+String("press"));
|
||||
api->increment(counterId,cfg.prefix+String("temp"));
|
||||
if (huValue != N2kDoubleNA){
|
||||
api->increment(counterId,cfg.prefix+String("ehum"));
|
||||
}
|
||||
if (prValue != N2kDoubleNA){
|
||||
api->increment(counterId,cfg.prefix+String("epress"));
|
||||
}
|
||||
if (tmValue != N2kDoubleNA){
|
||||
api->increment(counterId,cfg.prefix+String("etemp"));
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef _GWI_IIC1
|
||||
|
||||
@@ -23,7 +23,7 @@ static std::vector<IICGrove> iicGroveList;
|
||||
#include "GwBME280.h"
|
||||
#include "GwBMP280.h"
|
||||
#include "GwQMP6988.h"
|
||||
#include "GwSHT3X.h"
|
||||
#include "GwSHTXX.h"
|
||||
#include <map>
|
||||
|
||||
#include "GwTimer.h"
|
||||
@@ -91,6 +91,7 @@ void initIicTask(GwApi *api){
|
||||
GwConfigHandler *config=api->getConfig();
|
||||
std::vector<SensorBase::Creator> creators;
|
||||
creators.push_back(registerSHT3X(api));
|
||||
creators.push_back(registerSHT4X(api));
|
||||
creators.push_back(registerQMP6988(api));
|
||||
creators.push_back(registerBME280(api));
|
||||
creators.push_back(registerBMP280(api));
|
||||
@@ -147,13 +148,13 @@ bool initWire(GwLog *logger, TwoWire &wire, int num){
|
||||
#ifdef _GWI_IIC1
|
||||
return initWireDo(logger,wire,num,_GWI_IIC1);
|
||||
#endif
|
||||
return initWireDo(logger,wire,num,"",GWIIC_SDA,GWIIC_SCL);
|
||||
return initWireDo(logger,wire,num,"",GWIIC_SCL,GWIIC_SDA);
|
||||
}
|
||||
if (num == 2){
|
||||
#ifdef _GWI_IIC2
|
||||
return initWireDo(logger,wire,num,_GWI_IIC2);
|
||||
#endif
|
||||
return initWireDo(logger,wire,num,"",GWIIC_SDA2,GWIIC_SCL2);
|
||||
return initWireDo(logger,wire,num,"",GWIIC_SCL2,GWIIC_SDA2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ class QMP6988Config : public IICSensorBase{
|
||||
public:
|
||||
String prNam="Pressure";
|
||||
bool prAct=true;
|
||||
bool sEnv=true;
|
||||
tN2kTempSource tmSrc=tN2kTempSource::N2kts_InsideTemperature;
|
||||
tN2kHumiditySource huSrc=tN2kHumiditySource::N2khs_Undef;
|
||||
tN2kPressureSource prSrc=tN2kPressureSource::N2kps_Atmospheric;
|
||||
float prOff=0;
|
||||
QMP6988 *device=nullptr;
|
||||
@@ -39,6 +42,7 @@ class QMP6988Config : public IICSensorBase{
|
||||
float computed=pressure+prOff;
|
||||
LOG_DEBUG(GwLog::DEBUG,"%s measure %2.0fPa, computed %2.0fPa",prefix.c_str(), pressure,computed);
|
||||
sendN2kPressure(api,*this,computed,counterId);
|
||||
sendN2kEnvironmentalParameters(api,*this,N2kDoubleNA,N2kDoubleNA,computed,counterId);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +94,7 @@ SensorBase::Creator registerQMP6988(GwApi *api){
|
||||
CFG_SGET(s,prAct,prefix); \
|
||||
CFG_SGET(s,intv,prefix); \
|
||||
CFG_SGET(s,prOff,prefix); \
|
||||
CFG_SGET(s,sEnv,prefix); \
|
||||
s->busId = bus; \
|
||||
s->addr = baddr; \
|
||||
s->ok = true; \
|
||||
@@ -108,4 +113,4 @@ SC6988(QMP698822,2,112);
|
||||
SensorBase::Creator registerQMP6988(GwApi *api){
|
||||
return SensorBase::Creator();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,138 +0,0 @@
|
||||
#include "GwSHT3X.h"
|
||||
#ifdef _GWSHT3X
|
||||
class SHT3XConfig;
|
||||
static GwSensorConfigInitializerList<SHT3XConfig> configs;
|
||||
class SHT3XConfig : public IICSensorBase{
|
||||
public:
|
||||
String tmNam;
|
||||
String huNam;
|
||||
bool tmAct=false;
|
||||
bool huAct=false;
|
||||
tN2kHumiditySource huSrc;
|
||||
tN2kTempSource tmSrc;
|
||||
SHT3X *device=nullptr;
|
||||
using IICSensorBase::IICSensorBase;
|
||||
virtual bool isActive(){
|
||||
return tmAct || huAct;
|
||||
}
|
||||
virtual bool initDevice(GwApi * api,TwoWire *wire){
|
||||
if (! isActive()) return false;
|
||||
device=new SHT3X();
|
||||
device->init(addr,wire);
|
||||
GwLog *logger=api->getLogger();
|
||||
LOG_DEBUG(GwLog::LOG,"initialized %s at address %d, intv %ld",prefix.c_str(),(int)addr,intv);
|
||||
return true;
|
||||
}
|
||||
virtual bool preinit(GwApi * api){
|
||||
GwLog *logger=api->getLogger();
|
||||
LOG_DEBUG(GwLog::LOG,"%s configured",prefix.c_str());
|
||||
addHumidXdr(api,*this);
|
||||
addTempXdr(api,*this);
|
||||
return isActive();
|
||||
}
|
||||
virtual void measure(GwApi * api,TwoWire *wire, int counterId)
|
||||
{
|
||||
if (!device)
|
||||
return;
|
||||
GwLog *logger=api->getLogger();
|
||||
int rt = 0;
|
||||
if ((rt = device->get()) == 0)
|
||||
{
|
||||
double temp = device->cTemp;
|
||||
temp = CToKelvin(temp);
|
||||
double humid = device->humidity;
|
||||
LOG_DEBUG(GwLog::DEBUG, "%s measure temp=%2.1f, humid=%2.0f",prefix.c_str(), (float)temp, (float)humid);
|
||||
if (huAct)
|
||||
{
|
||||
sendN2kHumidity(api, *this, humid, counterId);
|
||||
}
|
||||
if (tmAct)
|
||||
{
|
||||
sendN2kTemperature(api, *this, temp, counterId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_DEBUG(GwLog::DEBUG, "unable to query %s: %d",prefix.c_str(), rt);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void readConfig(GwConfigHandler *cfg){
|
||||
if (ok) return;
|
||||
configs.readConfig(this,cfg);
|
||||
return;
|
||||
}
|
||||
};
|
||||
SensorBase::Creator creator=[](GwApi *api,const String &prfx)-> SensorBase*{
|
||||
if (! configs.knowsPrefix(prfx)) return nullptr;
|
||||
return new SHT3XConfig(api,prfx);
|
||||
};
|
||||
SensorBase::Creator registerSHT3X(GwApi *api){
|
||||
GwLog *logger=api->getLogger();
|
||||
#if defined(GWSHT3X) || defined (GWSHT3X11)
|
||||
{
|
||||
api->addSensor(creator(api,"SHT3X11"));
|
||||
CHECK_IIC1();
|
||||
#pragma message "GWSHT3X11 defined"
|
||||
}
|
||||
#endif
|
||||
#if defined(GWSHT3X12)
|
||||
{
|
||||
api->addSensor(creator(api,"SHT3X12"));
|
||||
CHECK_IIC1();
|
||||
#pragma message "GWSHT3X12 defined"
|
||||
}
|
||||
#endif
|
||||
#if defined(GWSHT3X21)
|
||||
{
|
||||
api->addSensor(creator(api,"SHT3X21"));
|
||||
CHECK_IIC2();
|
||||
#pragma message "GWSHT3X21 defined"
|
||||
}
|
||||
#endif
|
||||
#if defined(GWSHT3X22)
|
||||
{
|
||||
api->addSensor(creator(api,"SHT3X22"));
|
||||
CHECK_IIC2();
|
||||
#pragma message "GWSHT3X22 defined"
|
||||
}
|
||||
#endif
|
||||
return creator;
|
||||
};
|
||||
|
||||
/**
|
||||
* we do not dynamically compute the config names
|
||||
* 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); \
|
||||
s->busId = bus; \
|
||||
s->addr = baddr; \
|
||||
s->ok = true; \
|
||||
s->intv *= 1000;
|
||||
|
||||
#define SCSHT3X(prefix, bus, addr) \
|
||||
GWSENSORDEF(configs, SHT3XConfig, CFGSHT3X, prefix, bus, addr)
|
||||
|
||||
SCSHT3X(SHT3X11, 1, 0x44);
|
||||
SCSHT3X(SHT3X12, 1, 0x45);
|
||||
SCSHT3X(SHT3X21, 2, 0x44);
|
||||
SCSHT3X(SHT3X22, 2, 0x45);
|
||||
|
||||
#else
|
||||
SensorBase::Creator registerSHT3X(GwApi *api){
|
||||
return SensorBase::Creator();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
254
lib/iictask/GwSHTXX.cpp
Normal file
254
lib/iictask/GwSHTXX.cpp
Normal file
@@ -0,0 +1,254 @@
|
||||
#include "GwSHTXX.h"
|
||||
#if defined(_GWSHT3X) || defined(_GWSHT4X)
|
||||
class SHTXXConfig : public IICSensorBase{
|
||||
public:
|
||||
String tmNam;
|
||||
String huNam;
|
||||
bool tmAct=false;
|
||||
bool huAct=false;
|
||||
bool sEnv=true;
|
||||
tN2kHumiditySource huSrc;
|
||||
tN2kTempSource tmSrc;
|
||||
using IICSensorBase::IICSensorBase;
|
||||
virtual bool isActive(){
|
||||
return tmAct || huAct;
|
||||
}
|
||||
virtual bool preinit(GwApi * api){
|
||||
GwLog *logger=api->getLogger();
|
||||
LOG_DEBUG(GwLog::LOG,"%s configured",prefix.c_str());
|
||||
addHumidXdr(api,*this);
|
||||
addTempXdr(api,*this);
|
||||
return isActive();
|
||||
}
|
||||
virtual bool doMeasure(GwApi * api,double &temp, double &humid){
|
||||
return false;
|
||||
}
|
||||
virtual void measure(GwApi * api,TwoWire *wire, int counterId) override
|
||||
{
|
||||
GwLog *logger=api->getLogger();
|
||||
double temp = N2kDoubleNA;
|
||||
double humid = N2kDoubleNA;
|
||||
if (doMeasure(api,temp,humid)){
|
||||
temp = CToKelvin(temp);
|
||||
LOG_DEBUG(GwLog::DEBUG, "%s measure temp=%2.1f, humid=%2.0f",prefix.c_str(), (float)temp, (float)humid);
|
||||
if (huAct)
|
||||
{
|
||||
sendN2kHumidity(api, *this, humid, counterId);
|
||||
}
|
||||
if (tmAct)
|
||||
{
|
||||
sendN2kTemperature(api, *this, temp, counterId);
|
||||
}
|
||||
if (huAct || tmAct){
|
||||
sendN2kEnvironmentalParameters(api,*this,temp,humid,N2kDoubleNA,counterId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* we do not dynamically compute the config names
|
||||
* just to get compile time errors if something does not fit
|
||||
* correctly
|
||||
*/
|
||||
#define INITSHTXX(type,prefix,bus,baddr) \
|
||||
[] (type *s ,GwConfigHandler *cfg) { \
|
||||
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); \
|
||||
CFG_SGET(s, sEnv,prefix); \
|
||||
s->busId = bus; \
|
||||
s->addr = baddr; \
|
||||
s->ok = true; \
|
||||
s->intv *= 1000; \
|
||||
}
|
||||
|
||||
#if defined(_GWSHT3X)
|
||||
class SHT3XConfig;
|
||||
static GwSensorConfigInitializerList<SHT3XConfig> configs3;
|
||||
class SHT3XConfig : public SHTXXConfig{
|
||||
SHT3X *device=nullptr;
|
||||
public:
|
||||
using SHTXXConfig::SHTXXConfig;
|
||||
virtual bool initDevice(GwApi * api,TwoWire *wire)override{
|
||||
if (! isActive()) return false;
|
||||
device=new SHT3X();
|
||||
device->init(addr,wire);
|
||||
GwLog *logger=api->getLogger();
|
||||
LOG_DEBUG(GwLog::LOG,"initialized %s at address %d, intv %ld",prefix.c_str(),(int)addr,intv);
|
||||
return true;
|
||||
}
|
||||
virtual bool doMeasure(GwApi *api,double &temp, double &humid) override{
|
||||
if (!device)
|
||||
return false;
|
||||
int rt=0;
|
||||
GwLog *logger=api->getLogger();
|
||||
if ((rt = device->get()) == 0)
|
||||
{
|
||||
temp = device->cTemp;
|
||||
humid = device->humidity;
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
LOG_DEBUG(GwLog::DEBUG, "unable to query %s: %d",prefix.c_str(), rt);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
virtual void readConfig(GwConfigHandler *cfg) override{
|
||||
if (ok) return;
|
||||
configs3.readConfig(this,cfg);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
SensorBase::Creator creator3=[](GwApi *api,const String &prfx)-> SensorBase*{
|
||||
if (! configs3.knowsPrefix(prfx)) return nullptr;
|
||||
return new SHT3XConfig(api,prfx);
|
||||
};
|
||||
SensorBase::Creator registerSHT3X(GwApi *api){
|
||||
GwLog *logger=api->getLogger();
|
||||
#if defined(GWSHT3X) || defined (GWSHT3X11)
|
||||
{
|
||||
api->addSensor(creator3(api,"SHT3X11"));
|
||||
CHECK_IIC1();
|
||||
#pragma message "GWSHT3X11 defined"
|
||||
}
|
||||
#endif
|
||||
#if defined(GWSHT3X12)
|
||||
{
|
||||
api->addSensor(creator3(api,"SHT3X12"));
|
||||
CHECK_IIC1();
|
||||
#pragma message "GWSHT3X12 defined"
|
||||
}
|
||||
#endif
|
||||
#if defined(GWSHT3X21)
|
||||
{
|
||||
api->addSensor(creator3(api,"SHT3X21"));
|
||||
CHECK_IIC2();
|
||||
#pragma message "GWSHT3X21 defined"
|
||||
}
|
||||
#endif
|
||||
#if defined(GWSHT3X22)
|
||||
{
|
||||
api->addSensor(creator3(api,"SHT3X22"));
|
||||
CHECK_IIC2();
|
||||
#pragma message "GWSHT3X22 defined"
|
||||
}
|
||||
#endif
|
||||
return creator3;
|
||||
};
|
||||
|
||||
|
||||
#define SCSHT3X(prefix, bus, addr) \
|
||||
GwSensorConfigInitializer<SHT3XConfig> __initCFGSHT3X ## prefix \
|
||||
(configs3,GwSensorConfig<SHT3XConfig>(#prefix,INITSHTXX(SHT3XConfig,prefix,bus,addr)));
|
||||
|
||||
SCSHT3X(SHT3X11, 1, 0x44);
|
||||
SCSHT3X(SHT3X12, 1, 0x45);
|
||||
SCSHT3X(SHT3X21, 2, 0x44);
|
||||
SCSHT3X(SHT3X22, 2, 0x45);
|
||||
|
||||
#endif
|
||||
#if defined(_GWSHT4X)
|
||||
class SHT4XConfig;
|
||||
static GwSensorConfigInitializerList<SHT4XConfig> configs4;
|
||||
class SHT4XConfig : public SHTXXConfig{
|
||||
SHT4X *device=nullptr;
|
||||
public:
|
||||
using SHTXXConfig::SHTXXConfig;
|
||||
virtual bool initDevice(GwApi * api,TwoWire *wire)override{
|
||||
if (! isActive()) return false;
|
||||
device=new SHT4X();
|
||||
device->begin(wire,addr);
|
||||
GwLog *logger=api->getLogger();
|
||||
LOG_DEBUG(GwLog::LOG,"initialized %s at address %d, intv %ld",prefix.c_str(),(int)addr,intv);
|
||||
return true;
|
||||
}
|
||||
virtual bool doMeasure(GwApi *api,double &temp, double &humid) override{
|
||||
if (!device)
|
||||
return false;
|
||||
GwLog *logger=api->getLogger();
|
||||
if (device->update())
|
||||
{
|
||||
temp = device->cTemp;
|
||||
humid = device->humidity;
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
LOG_DEBUG(GwLog::DEBUG, "unable to query %s",prefix.c_str());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
virtual void readConfig(GwConfigHandler *cfg) override{
|
||||
if (ok) return;
|
||||
configs4.readConfig(this,cfg);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
SensorBase::Creator creator4=[](GwApi *api,const String &prfx)-> SensorBase*{
|
||||
if (! configs4.knowsPrefix(prfx)) return nullptr;
|
||||
return new SHT4XConfig(api,prfx);
|
||||
};
|
||||
SensorBase::Creator registerSHT4X(GwApi *api){
|
||||
GwLog *logger=api->getLogger();
|
||||
#if defined(GWSHT4X) || defined (GWSHT4X11)
|
||||
{
|
||||
api->addSensor(creator3(api,"SHT4X11"));
|
||||
CHECK_IIC1();
|
||||
#pragma message "GWSHT4X11 defined"
|
||||
}
|
||||
#endif
|
||||
#if defined(GWSHT4X12)
|
||||
{
|
||||
api->addSensor(creator3(api,"SHT4X12"));
|
||||
CHECK_IIC1();
|
||||
#pragma message "GWSHT4X12 defined"
|
||||
}
|
||||
#endif
|
||||
#if defined(GWSHT4X21)
|
||||
{
|
||||
api->addSensor(creator3(api,"SHT4X21"));
|
||||
CHECK_IIC2();
|
||||
#pragma message "GWSHT4X21 defined"
|
||||
}
|
||||
#endif
|
||||
#if defined(GWSHT4X22)
|
||||
{
|
||||
api->addSensor(creator3(api,"SHT4X22"));
|
||||
CHECK_IIC2();
|
||||
#pragma message "GWSHT4X22 defined"
|
||||
}
|
||||
#endif
|
||||
return creator4;
|
||||
};
|
||||
|
||||
|
||||
#define SCSHT4X(prefix, bus, addr) \
|
||||
GwSensorConfigInitializer<SHT4XConfig> __initCFGSHT4X ## prefix \
|
||||
(configs4,GwSensorConfig<SHT4XConfig>(#prefix,INITSHTXX(SHT4XConfig,prefix,bus,addr)));
|
||||
|
||||
SCSHT4X(SHT4X11, 1, 0x44);
|
||||
SCSHT4X(SHT4X12, 1, 0x45);
|
||||
SCSHT4X(SHT4X21, 2, 0x44);
|
||||
SCSHT4X(SHT4X22, 2, 0x45);
|
||||
#endif
|
||||
#endif
|
||||
#ifndef _GWSHT3X
|
||||
SensorBase::Creator registerSHT3X(GwApi *api){
|
||||
return SensorBase::Creator();
|
||||
}
|
||||
#endif
|
||||
#ifndef _GWSHT4X
|
||||
SensorBase::Creator registerSHT4X(GwApi *api){
|
||||
return SensorBase::Creator();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
#ifndef _GWSHT3X_H
|
||||
#define _GWSHT3X_H
|
||||
#ifndef _GWSHTXX_H
|
||||
#define _GWSHTXX_H
|
||||
#include "GwIicSensors.h"
|
||||
#ifdef _GWIIC
|
||||
#if defined(GWSHT3X) || defined(GWSHT3X11) || defined(GWSHT3X12) || defined(GWSHT3X21) || defined(GWSHT3X22)
|
||||
#define _GWSHT3X
|
||||
#endif
|
||||
#if defined(GWSHT4X) || defined(GWSHT4X11) || defined(GWSHT4X12) || defined(GWSHT4X21) || defined(GWSHT4X22)
|
||||
#define _GWSHT4X
|
||||
#endif
|
||||
#else
|
||||
#undef _GWSHT3X
|
||||
#undef GWSHT3X
|
||||
@@ -12,9 +15,19 @@
|
||||
#undef GWSHT3X12
|
||||
#undef GWSHT3X21
|
||||
#undef GWSHT3X22
|
||||
#undef _GWSHT4X
|
||||
#undef GWSHT4X
|
||||
#undef GWSHT4X11
|
||||
#undef GWSHT4X12
|
||||
#undef GWSHT4X21
|
||||
#undef GWSHT4X22
|
||||
#endif
|
||||
#ifdef _GWSHT3X
|
||||
#include "SHT3X.h"
|
||||
#endif
|
||||
#ifdef _GWSHT4X
|
||||
#include "SHT4X.h"
|
||||
#endif
|
||||
SensorBase::Creator registerSHT3X(GwApi *api);
|
||||
SensorBase::Creator registerSHT4X(GwApi *api);
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "GwSHT3X.h"
|
||||
#include "GwSHTXX.h"
|
||||
#ifdef _GWSHT3X
|
||||
|
||||
bool SHT3X::init(uint8_t slave_addr_in, TwoWire* wire_in)
|
||||
@@ -44,4 +44,4 @@ byte SHT3X::get()
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
131
lib/iictask/SHT4X.cpp
Normal file
131
lib/iictask/SHT4X.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
#include "GwSHTXX.h"
|
||||
#ifdef _GWSHT4X
|
||||
|
||||
uint8_t crc8(const uint8_t *data, int len) {
|
||||
/*
|
||||
*
|
||||
* CRC-8 formula from page 14 of SHT spec pdf
|
||||
*
|
||||
* Test data 0xBE, 0xEF should yield 0x92
|
||||
*
|
||||
* Initialization data 0xFF
|
||||
* Polynomial 0x31 (x8 + x5 +x4 +1)
|
||||
* Final XOR 0x00
|
||||
*/
|
||||
|
||||
const uint8_t POLYNOMIAL(0x31);
|
||||
uint8_t crc(0xFF);
|
||||
|
||||
for (int j = len; j; --j) {
|
||||
crc ^= *data++;
|
||||
|
||||
for (int i = 8; i; --i) {
|
||||
crc = (crc & 0x80) ? (crc << 1) ^ POLYNOMIAL : (crc << 1);
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
bool SHT4X::begin(TwoWire* wire, uint8_t addr) {
|
||||
_addr = addr;
|
||||
_wire = wire;
|
||||
int error;
|
||||
_wire->beginTransmission(addr);
|
||||
error = _wire->endTransmission();
|
||||
if (error == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SHT4X::update() {
|
||||
uint8_t readbuffer[6];
|
||||
uint8_t cmd = SHT4x_NOHEAT_HIGHPRECISION;
|
||||
uint16_t duration = 10;
|
||||
|
||||
if (_heater == SHT4X_NO_HEATER) {
|
||||
if (_precision == SHT4X_HIGH_PRECISION) {
|
||||
cmd = SHT4x_NOHEAT_HIGHPRECISION;
|
||||
duration = 10;
|
||||
}
|
||||
if (_precision == SHT4X_MED_PRECISION) {
|
||||
cmd = SHT4x_NOHEAT_MEDPRECISION;
|
||||
duration = 5;
|
||||
}
|
||||
if (_precision == SHT4X_LOW_PRECISION) {
|
||||
cmd = SHT4x_NOHEAT_LOWPRECISION;
|
||||
duration = 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (_heater == SHT4X_HIGH_HEATER_1S) {
|
||||
cmd = SHT4x_HIGHHEAT_1S;
|
||||
duration = 1100;
|
||||
}
|
||||
if (_heater == SHT4X_HIGH_HEATER_100MS) {
|
||||
cmd = SHT4x_HIGHHEAT_100MS;
|
||||
duration = 110;
|
||||
}
|
||||
|
||||
if (_heater == SHT4X_MED_HEATER_1S) {
|
||||
cmd = SHT4x_MEDHEAT_1S;
|
||||
duration = 1100;
|
||||
}
|
||||
if (_heater == SHT4X_MED_HEATER_100MS) {
|
||||
cmd = SHT4x_MEDHEAT_100MS;
|
||||
duration = 110;
|
||||
}
|
||||
|
||||
if (_heater == SHT4X_LOW_HEATER_1S) {
|
||||
cmd = SHT4x_LOWHEAT_1S;
|
||||
duration = 1100;
|
||||
}
|
||||
if (_heater == SHT4X_LOW_HEATER_100MS) {
|
||||
cmd = SHT4x_LOWHEAT_100MS;
|
||||
duration = 110;
|
||||
}
|
||||
// _i2c.writeByte(_addr, cmd, 1);
|
||||
_wire->beginTransmission(_addr);
|
||||
_wire->write(cmd);
|
||||
_wire->write(1);
|
||||
_wire->endTransmission();
|
||||
|
||||
|
||||
delay(duration);
|
||||
|
||||
_wire->requestFrom(_addr, (uint8_t)6);
|
||||
|
||||
for (uint16_t i = 0; i < 6; i++) {
|
||||
readbuffer[i] = _wire->read();
|
||||
}
|
||||
|
||||
if (readbuffer[2] != crc8(readbuffer, 2) ||
|
||||
readbuffer[5] != crc8(readbuffer + 3, 2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
float t_ticks = (uint16_t)readbuffer[0] * 256 + (uint16_t)readbuffer[1];
|
||||
float rh_ticks = (uint16_t)readbuffer[3] * 256 + (uint16_t)readbuffer[4];
|
||||
|
||||
cTemp = -45 + 175 * t_ticks / 65535;
|
||||
humidity = -6 + 125 * rh_ticks / 65535;
|
||||
humidity = min(max(humidity, (float)0.0), (float)100.0);
|
||||
return true;
|
||||
}
|
||||
|
||||
void SHT4X::setPrecision(sht4x_precision_t prec) {
|
||||
_precision = prec;
|
||||
}
|
||||
|
||||
sht4x_precision_t SHT4X::getPrecision(void) {
|
||||
return _precision;
|
||||
}
|
||||
|
||||
void SHT4X::setHeater(sht4x_heater_t heat) {
|
||||
_heater = heat;
|
||||
}
|
||||
|
||||
sht4x_heater_t SHT4X::getHeater(void) {
|
||||
return _heater;
|
||||
}
|
||||
#endif
|
||||
76
lib/iictask/SHT4X.h
Normal file
76
lib/iictask/SHT4X.h
Normal file
@@ -0,0 +1,76 @@
|
||||
#ifndef __SHT4X_H_
|
||||
#define __SHT4X_H_
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
|
||||
#define SHT40_I2C_ADDR_44 0x44
|
||||
#define SHT40_I2C_ADDR_45 0x45
|
||||
#define SHT41_I2C_ADDR_44 0x44
|
||||
#define SHT41_I2C_ADDR_45 0x45
|
||||
#define SHT45_I2C_ADDR_44 0x44
|
||||
#define SHT45_I2C_ADDR_45 0x45
|
||||
|
||||
#define SHT4x_DEFAULT_ADDR 0x44 /**< SHT4x I2C Address */
|
||||
#define SHT4x_NOHEAT_HIGHPRECISION \
|
||||
0xFD /**< High precision measurement, no heater */
|
||||
#define SHT4x_NOHEAT_MEDPRECISION \
|
||||
0xF6 /**< Medium precision measurement, no heater */
|
||||
#define SHT4x_NOHEAT_LOWPRECISION \
|
||||
0xE0 /**< Low precision measurement, no heater */
|
||||
|
||||
#define SHT4x_HIGHHEAT_1S \
|
||||
0x39 /**< High precision measurement, high heat for 1 sec */
|
||||
#define SHT4x_HIGHHEAT_100MS \
|
||||
0x32 /**< High precision measurement, high heat for 0.1 sec */
|
||||
#define SHT4x_MEDHEAT_1S \
|
||||
0x2F /**< High precision measurement, med heat for 1 sec */
|
||||
#define SHT4x_MEDHEAT_100MS \
|
||||
0x24 /**< High precision measurement, med heat for 0.1 sec */
|
||||
#define SHT4x_LOWHEAT_1S \
|
||||
0x1E /**< High precision measurement, low heat for 1 sec */
|
||||
#define SHT4x_LOWHEAT_100MS \
|
||||
0x15 /**< High precision measurement, low heat for 0.1 sec */
|
||||
|
||||
#define SHT4x_READSERIAL 0x89 /**< Read Out of Serial Register */
|
||||
#define SHT4x_SOFTRESET 0x94 /**< Soft Reset */
|
||||
|
||||
typedef enum {
|
||||
SHT4X_HIGH_PRECISION,
|
||||
SHT4X_MED_PRECISION,
|
||||
SHT4X_LOW_PRECISION,
|
||||
} sht4x_precision_t;
|
||||
|
||||
/** Optional pre-heater configuration setting */
|
||||
typedef enum {
|
||||
SHT4X_NO_HEATER,
|
||||
SHT4X_HIGH_HEATER_1S,
|
||||
SHT4X_HIGH_HEATER_100MS,
|
||||
SHT4X_MED_HEATER_1S,
|
||||
SHT4X_MED_HEATER_100MS,
|
||||
SHT4X_LOW_HEATER_1S,
|
||||
SHT4X_LOW_HEATER_100MS,
|
||||
} sht4x_heater_t;
|
||||
|
||||
class SHT4X {
|
||||
public:
|
||||
bool begin(TwoWire* wire = &Wire, uint8_t addr = SHT40_I2C_ADDR_44);
|
||||
bool update(void);
|
||||
|
||||
float cTemp = 0;
|
||||
float humidity = 0;
|
||||
|
||||
void setPrecision(sht4x_precision_t prec);
|
||||
sht4x_precision_t getPrecision(void);
|
||||
void setHeater(sht4x_heater_t heat);
|
||||
sht4x_heater_t getHeater(void);
|
||||
|
||||
private:
|
||||
TwoWire* _wire;
|
||||
uint8_t _addr;
|
||||
|
||||
sht4x_precision_t _precision = SHT4X_HIGH_PRECISION;
|
||||
sht4x_heater_t _heater = SHT4X_NO_HEATER;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,49 +1,77 @@
|
||||
[
|
||||
{
|
||||
"type": "array",
|
||||
"name": "SHT3X",
|
||||
"name": "SHTXX",
|
||||
"replace": [
|
||||
{
|
||||
"b": "1",
|
||||
"i": "11",
|
||||
"n": "99"
|
||||
"n": "99",
|
||||
"x": "3"
|
||||
},
|
||||
{
|
||||
"b": "1",
|
||||
"i": "12",
|
||||
"n": "98"
|
||||
"n": "98",
|
||||
"x": "3"
|
||||
},
|
||||
{
|
||||
"b": "2",
|
||||
"i": "21",
|
||||
"n": "109"
|
||||
"n": "109",
|
||||
"x": "3"
|
||||
},
|
||||
{
|
||||
"b": "2",
|
||||
"i": "22",
|
||||
"n": "108"
|
||||
"n": "108",
|
||||
"x": "3"
|
||||
},
|
||||
{
|
||||
"b": "1",
|
||||
"i": "11",
|
||||
"n": "119",
|
||||
"x": "4"
|
||||
},
|
||||
{
|
||||
"b": "1",
|
||||
"i": "12",
|
||||
"n": "118",
|
||||
"x": "4"
|
||||
},
|
||||
{
|
||||
"b": "2",
|
||||
"i": "21",
|
||||
"n": "129",
|
||||
"x": "4"
|
||||
},
|
||||
{
|
||||
"b": "2",
|
||||
"i": "22",
|
||||
"n": "128",
|
||||
"x": "4"
|
||||
}
|
||||
|
||||
|
||||
],
|
||||
"children": [
|
||||
{
|
||||
"name": "SHT3X$itmAct",
|
||||
"label": "SHT3X$i Temp",
|
||||
"name": "SHT$xX$itmAct",
|
||||
"label": "SHT$xX$i Temp",
|
||||
"type": "boolean",
|
||||
"default": "true",
|
||||
"description": "Enable the $i. I2C SHT3x temp sensor (bus $b)",
|
||||
"description": "Enable the $i. I2C SHT$xX temp sensor (bus $b)",
|
||||
"category": "iicsensors$b",
|
||||
"capabilities": {
|
||||
"SHT3X$i": "true"
|
||||
"SHT$xX$i": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "SHT3X$itmSrc",
|
||||
"label": "SHT3X$i Temp Type",
|
||||
"name": "SHT$xX$itmSrc",
|
||||
"label": "SHT$xX$i Temp Type",
|
||||
"type": "list",
|
||||
"default": "2",
|
||||
"description": "the NMEA2000 source type for the temperature",
|
||||
"description": "the NMEA2000 source type for the temperature (PGN 130312,130311)",
|
||||
"list": [
|
||||
{
|
||||
"l": "SeaTemperature",
|
||||
@@ -112,23 +140,23 @@
|
||||
],
|
||||
"category": "iicsensors$b",
|
||||
"capabilities": {
|
||||
"SHT3X$i": "true"
|
||||
"SHT$xX$i": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "SHT3X$ihuAct",
|
||||
"label": "SHT3X$i Humidity",
|
||||
"name": "SHT$xX$ihuAct",
|
||||
"label": "SHT$xX$i Humidity",
|
||||
"type": "boolean",
|
||||
"default": "true",
|
||||
"description": "Enable the $i. I2C SHT3x humidity sensor (bus $b)",
|
||||
"description": "Enable the $i. I2C SHT$xX humidity sensor (bus $b)",
|
||||
"category": "iicsensors$b",
|
||||
"capabilities": {
|
||||
"SHT3X$i": "true"
|
||||
"SHT$xX$i": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "SHT3X$ihuSrc",
|
||||
"label": "SHT3X$i Humid Type",
|
||||
"name": "SHT$xX$ihuSrc",
|
||||
"label": "SHT$xX$i Humid Type",
|
||||
"list": [
|
||||
{
|
||||
"l": "OutsideHumidity",
|
||||
@@ -141,57 +169,68 @@
|
||||
],
|
||||
"category": "iicsensors$b",
|
||||
"capabilities": {
|
||||
"SHT3X": "true"
|
||||
"SHT$xX": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "SHT3X$iiid",
|
||||
"label": "SHT3X$i N2K iid",
|
||||
"name": "SHT$xX$iiid",
|
||||
"label": "SHT$xX$i N2K iid",
|
||||
"type": "number",
|
||||
"default": "$n",
|
||||
"description": "the N2K instance id for the $i. SHT3X Temperature and Humidity ",
|
||||
"description": "the N2K instance id for the $i. SHT$xX Temperature and Humidity (PGN 130312,130311) ",
|
||||
"category": "iicsensors$b",
|
||||
"min": 0,
|
||||
"max": 253,
|
||||
"check": "checkMinMax",
|
||||
"capabilities": {
|
||||
"SHT3X$i": "true"
|
||||
"SHT$xX$i": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "SHT3X$iintv",
|
||||
"label": "SHT3X$i Interval",
|
||||
"name": "SHT$xX$isEnv",
|
||||
"label": "SHT$xX$i send Env",
|
||||
"type": "boolean",
|
||||
"default": "true",
|
||||
"description": "also send PGN 130311",
|
||||
"category": "iicsensors$b",
|
||||
"capabilities": {
|
||||
"SHT$xX$i": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "SHT$xX$iintv",
|
||||
"label": "SHT$xX$i Interval",
|
||||
"type": "number",
|
||||
"default": 2,
|
||||
"description": "Interval(s) to query SHT3X Temperature and Humidity (1...300)",
|
||||
"description": "Interval(s) to query SHT$xX Temperature and Humidity (1...300)",
|
||||
"category": "iicsensors$b",
|
||||
"min": 1,
|
||||
"max": 300,
|
||||
"check": "checkMinMax",
|
||||
"capabilities": {
|
||||
"SHT3X$i": "true"
|
||||
"SHT$xX$i": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "SHT3X$itmNam",
|
||||
"label": "SHT3X$i Temp XDR",
|
||||
"name": "SHT$xX$itmNam",
|
||||
"label": "SHT$xX$i Temp XDR",
|
||||
"type": "String",
|
||||
"default": "Temp$i",
|
||||
"description": "set the XDR transducer name for the $i. SHT3X Temperature, leave empty to disable NMEA0183 XDR ",
|
||||
"description": "set the XDR transducer name for the $i. SHT$xX Temperature, leave empty to disable NMEA0183 XDR ",
|
||||
"category": "iicsensors$b",
|
||||
"capabilities": {
|
||||
"SHT3X$i": "true"
|
||||
"SHT$xX$i": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "SHT3X$ihuNam",
|
||||
"label": "SHT3X$i Humid XDR",
|
||||
"name": "SHT$xX$ihuNam",
|
||||
"label": "SHT$xX$i Humid XDR",
|
||||
"type": "String",
|
||||
"default": "Humidity$i",
|
||||
"description": "set the XDR transducer name for the $i. SHT3X Humidity, leave empty to disable NMEA0183 XDR",
|
||||
"description": "set the XDR transducer name for the $i. SHT$xX Humidity, leave empty to disable NMEA0183 XDR",
|
||||
"category": "iicsensors$b",
|
||||
"capabilities": {
|
||||
"SHT3X$i": "true"
|
||||
"SHT$xX$i": "true"
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -247,6 +286,17 @@
|
||||
"QMP6988$i": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "QMP6988$isEnv",
|
||||
"label": "QMP6988$i send Env",
|
||||
"type": "boolean",
|
||||
"default": "true",
|
||||
"description": "also send PGN 130311",
|
||||
"category": "iicsensors$b",
|
||||
"capabilities": {
|
||||
"QMP6988$i": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "QMP6988$iintv",
|
||||
"label": "QMP6988-$i Interval",
|
||||
@@ -473,7 +523,7 @@
|
||||
"label": "BME280-$i N2K iid",
|
||||
"type": "number",
|
||||
"default": "$n",
|
||||
"description": "the N2K instance id for the BME280 Temperature and Humidity ",
|
||||
"description": "the N2K instance id for the BME280 Temperature, Humidity, Pressure (PGN 130312,130313, 130314) ",
|
||||
"category": "iicsensors$b",
|
||||
"min": 0,
|
||||
"max": 253,
|
||||
@@ -482,6 +532,17 @@
|
||||
"BME280$i": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "BME280$isEnv",
|
||||
"label": "BME280$i send Env",
|
||||
"type": "boolean",
|
||||
"default": "true",
|
||||
"description": "also send PGN 130311",
|
||||
"category": "iicsensors$b",
|
||||
"capabilities": {
|
||||
"BME280$i": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "BME280$iintv",
|
||||
"label": "BME280-$i Interval",
|
||||
@@ -683,7 +744,7 @@
|
||||
"label": "BMP280-$i N2K iid",
|
||||
"type": "number",
|
||||
"default": "$n",
|
||||
"description": "the N2K instance id for the BMP280 Temperature",
|
||||
"description": "the N2K instance id for the BMP280 Temperature/Pressure (PGN 130312,130314)",
|
||||
"category": "iicsensors$b",
|
||||
"min": 0,
|
||||
"max": 253,
|
||||
@@ -692,6 +753,17 @@
|
||||
"BMP280$i": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "BMP280$isEnv",
|
||||
"label": "BMP280$i send Env",
|
||||
"type": "boolean",
|
||||
"default": "true",
|
||||
"description": "also send PGN 130311",
|
||||
"category": "iicsensors$b",
|
||||
"capabilities": {
|
||||
"BMP280$i": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "BMP280$iintv",
|
||||
"label": "BMP280-$i Interval",
|
||||
|
||||
@@ -11,6 +11,17 @@ build_flags=
|
||||
-D M5_CAN_KIT
|
||||
${env.build_flags}
|
||||
|
||||
[env:m5stack-atom-env4]
|
||||
extends = sensors
|
||||
board = m5stack-atom
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
${sensors.lib_deps}
|
||||
build_flags=
|
||||
-D M5_ENV4
|
||||
-D M5_CAN_KIT
|
||||
${env.build_flags}
|
||||
|
||||
|
||||
[env:m5stack-atom-bme280]
|
||||
extends = sensors
|
||||
|
||||
Reference in New Issue
Block a user