improve logging for sensors, correct bus assigment

This commit is contained in:
andreas 2023-11-04 19:50:26 +01:00
parent 685a5c6a1f
commit 1202b6d81f
3 changed files with 20 additions and 12 deletions

View File

@ -1,6 +1,6 @@
#include "GwBME280.h" #include "GwBME280.h"
#ifdef _GWIIC #ifdef _GWIIC
#if defined(GWBME280) || defined(GWBME2801) || defined(GWBME2802)|| defined(GWBME2803)|| defined(GWBME2804) #if defined(GWBME280) || defined(GWBME28011) || defined(GWBME28012)|| defined(GWBME28021)|| defined(GWBME28022)
#define _GWBME280 #define _GWBME280
#else #else
#undef _GWBME280 #undef _GWBME280
@ -19,8 +19,8 @@
#ifdef _GWBME280 #ifdef _GWBME280
#define PRFX1 "BME28011" #define PRFX1 "BME28011"
#define PRFX2 "BME28012" #define PRFX2 "BME28012"
#define PRFX3 "BME28013" #define PRFX3 "BME28021"
#define PRFX4 "BME28014" #define PRFX4 "BME28022"
class BME280Config : public SensorBase{ class BME280Config : public SensorBase{
public: public:
bool prAct=true; bool prAct=true;
@ -154,7 +154,7 @@ class BME280Config : public SensorBase{
} }
if (prefix == PRFX4) if (prefix == PRFX4)
{ {
busId = 1; busId = 2;
addr = 0x77; addr = 0x77;
#undef CG #undef CG
#define CG(name) CFG_GET(name, BME28022) #define CG(name) CFG_GET(name, BME28022)
@ -181,24 +181,28 @@ void registerBME280(GwApi *api,SensorList &sensors){
{ {
BME280Config *cfg=new BME280Config(api,PRFX1); BME280Config *cfg=new BME280Config(api,PRFX1);
sensors.add(api,cfg); sensors.add(api,cfg);
#pragma message "GWBME28011 defined"
} }
#endif #endif
#if defined(GWBME28012) #if defined(GWBME28012)
{ {
BME280Config *cfg=new BME280Config(api,PRFX2); BME280Config *cfg=new BME280Config(api,PRFX2);
sensors.add(api,cfg); sensors.add(api,cfg);
#pragma message "GWBME28012 defined"
} }
#endif #endif
#if defined(GWBME28021) #if defined(GWBME28021)
{ {
BME280Config *cfg=new BME280Config(api,PRFX3); BME280Config *cfg=new BME280Config(api,PRFX3);
sensors.add(api,cfg); sensors.add(api,cfg);
#pragma message "GWBME28021 defined"
} }
#endif #endif
#if defined(GWBME28022) #if defined(GWBME28022)
{ {
BME280Config *cfg=new BME280Config(api,PRFX4); BME280Config *cfg=new BME280Config(api,PRFX4);
sensors.add(api,cfg); sensors.add(api,cfg);
#pragma message "GWBME28022 defined"
} }
#endif #endif
} }

View File

@ -69,7 +69,7 @@ void runIicTask(GwApi *api){
{ {
if (GWIIC_SDA < 0 || GWIIC_SCL < 0) if (GWIIC_SDA < 0 || GWIIC_SCL < 0)
{ {
LOG_DEBUG(GwLog::ERROR, "IIC 1 invalid config %d,%d", LOG_DEBUG(GwLog::ERROR, "IIC 1 invalid config sda=%d,scl=%d",
(int)GWIIC_SDA, (int)GWIIC_SCL); (int)GWIIC_SDA, (int)GWIIC_SCL);
} }
else else
@ -77,12 +77,14 @@ void runIicTask(GwApi *api){
bool rt = Wire.begin(GWIIC_SDA, GWIIC_SCL); bool rt = Wire.begin(GWIIC_SDA, GWIIC_SCL);
if (!rt) if (!rt)
{ {
LOG_DEBUG(GwLog::ERROR, "unable to initialize IIC 1 at %d,%d", LOG_DEBUG(GwLog::ERROR, "unable to initialize IIC 1 at sad=%d,scl=%d",
(int)GWIIC_SDA, (int)GWIIC_SCL); (int)GWIIC_SDA, (int)GWIIC_SCL);
} }
else else
{ {
buses[busId] = &Wire; buses[busId] = &Wire;
LOG_DEBUG(GwLog::ERROR, "initialized IIC 1 at sda=%d,scl=%d",
(int)GWIIC_SDA, (int)GWIIC_SCL);
} }
} }
} }
@ -91,7 +93,7 @@ void runIicTask(GwApi *api){
{ {
if (GWIIC_SDA2 < 0 || GWIIC_SCL2 < 0) if (GWIIC_SDA2 < 0 || GWIIC_SCL2 < 0)
{ {
LOG_DEBUG(GwLog::ERROR, "IIC 2 invalid config %d,%d", LOG_DEBUG(GwLog::ERROR, "IIC 2 invalid config sda=%d,scl=%d",
(int)GWIIC_SDA2, (int)GWIIC_SCL2); (int)GWIIC_SDA2, (int)GWIIC_SCL2);
} }
else else
@ -100,12 +102,14 @@ void runIicTask(GwApi *api){
bool rt = Wire1.begin(GWIIC_SDA2, GWIIC_SCL2); bool rt = Wire1.begin(GWIIC_SDA2, GWIIC_SCL2);
if (!rt) if (!rt)
{ {
LOG_DEBUG(GwLog::ERROR, "unable to initialize IIC 2 at %d,%d", LOG_DEBUG(GwLog::ERROR, "unable to initialize IIC 2 at sda=%d,scl=%d",
(int)GWIIC_SDA2, (int)GWIIC_SCL2); (int)GWIIC_SDA2, (int)GWIIC_SCL2);
} }
else else
{ {
buses[busId] = &Wire1; buses[busId] = &Wire1;
LOG_DEBUG(GwLog::LOG, "initialized IIC 2 at sda=%d,scl=%d",
(int)GWIIC_SDA2, (int)GWIIC_SCL2);
} }
} }
} }
@ -129,7 +133,7 @@ void runIicTask(GwApi *api){
continue; continue;
} }
TwoWire *wire=bus->second; TwoWire *wire=bus->second;
bool rt=cfg->initDevice(api,&Wire); bool rt=cfg->initDevice(api,wire);
if (rt){ if (rt){
runLoop=true; runLoop=true;
timers.addAction(cfg->intv,[wire,api,cfg,counterId](){ timers.addAction(cfg->intv,[wire,api,cfg,counterId](){

View File

@ -29,7 +29,7 @@ class SHT3XConfig : public SensorBase{
} }
virtual bool preinit(GwApi * api){ virtual bool preinit(GwApi * api){
GwLog *logger=api->getLogger(); GwLog *logger=api->getLogger();
LOG_DEBUG(GwLog::LOG,"SHT3X configured"); LOG_DEBUG(GwLog::LOG,"%s configured",prefix.c_str());
api->addCapability(prefix,"true"); api->addCapability(prefix,"true");
addHumidXdr(api,*this); addHumidXdr(api,*this);
addTempXdr(api,*this); addTempXdr(api,*this);
@ -46,7 +46,7 @@ class SHT3XConfig : public SensorBase{
double temp = device->cTemp; double temp = device->cTemp;
temp = CToKelvin(temp); temp = CToKelvin(temp);
double humid = device->humidity; double humid = device->humidity;
LOG_DEBUG(GwLog::DEBUG, "SHT3X measure temp=%2.1f, humid=%2.0f", (float)temp, (float)humid); LOG_DEBUG(GwLog::DEBUG, "%s measure temp=%2.1f, humid=%2.0f",prefix.c_str(), (float)temp, (float)humid);
if (huAct) if (huAct)
{ {
sendN2kHumidity(api, *this, humid, counterId); sendN2kHumidity(api, *this, humid, counterId);
@ -58,7 +58,7 @@ class SHT3XConfig : public SensorBase{
} }
else else
{ {
LOG_DEBUG(GwLog::DEBUG, "unable to query SHT3X: %d", rt); LOG_DEBUG(GwLog::DEBUG, "unable to query %s: %d",prefix.c_str(), rt);
} }
} }
/** /**