Merge pull request #9627 from tichris0/development

Cleanup the EZO devices
This commit is contained in:
Theo Arends 2020-10-26 09:31:21 +01:00 committed by GitHub
commit 05b19062d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 70 additions and 105 deletions

View File

@ -567,7 +567,7 @@
// #define USE_EZORTD // [I2cDriver55] Enable support for EZO's RTD sensor (+0k2 code) - Shared EZO code required for any EZO device (+1k2 code)
// #define USE_EZOHUM // [I2cDriver55] Enable support for EZO's HUM sensor (+0k3 code) - Shared EZO code required for any EZO device (+1k2 code)
// #define USE_EZOEC // [I2cDriver55] Enable support for EZO's EC sensor (+0k3 code) - Shared EZO code required for any EZO device (+1k2 code)
// #define USE_EZOCO2 // [I2cDriver55] Enable support for EZO's CO2 sensor (+0k3 code) - Shared EZO code required for any EZO device (+1k2 code)
// #define USE_EZOCO2 // [I2cDriver55] Enable support for EZO's CO2 sensor (+0k2 code) - Shared EZO code required for any EZO device (+1k2 code)
// #define USE_DISPLAY // Add I2C Display Support (+2k code)
#define USE_DISPLAY_MODES1TO5 // Enable display mode 1 to 5 in addition to mode 0

View File

@ -132,7 +132,7 @@
//#define USE_EZORTD // [I2cDriver55] Enable support for EZO's RTD sensor (+0k2 code) - Shared EZO code required for any EZO device (+1k2 code)
//#define USE_EZOHUM // [I2cDriver55] Enable support for EZO's HUM sensor (+0k3 code) - Shared EZO code required for any EZO device (+1k2 code)
//#define USE_EZOEC // [I2cDriver55] Enable support for EZO's EC sensor (+0k3 code) - Shared EZO code required for any EZO device (+1k2 code)
//#define USE_EZOCO2 // [I2cDriver55] Enable support for EZO's CO2 sensor (+0k3 code) - Shared EZO code required for any EZO device (+1k2 code)
//#define USE_EZOCO2 // [I2cDriver55] Enable support for EZO's CO2 sensor (+0k2 code) - Shared EZO code required for any EZO device (+1k2 code)
#define USE_MHZ19 // Add support for MH-Z19 CO2 sensor (+2k code)
#define USE_SENSEAIR // Add support for SenseAir K30, K70 and S8 CO2 sensor (+2k3 code)

View File

@ -80,6 +80,8 @@ struct EZOStruct {
virtual void ProcessMeasurement(void);
virtual void Show(bool json, const char *name);
static const char id[] PROGMEM;
protected:
void ProcessMeasurement(char *const data, const uint32_t len, const uint32_t latency)
{
@ -108,7 +110,7 @@ protected:
uint32_t lastRead;
};
const char EZOStruct::id[] PROGMEM = "";
#endif // USE_EZO
#endif // USE_I2C

View File

@ -49,9 +49,13 @@ struct EZOCO2 : public EZOStruct {
}
}
static const char id[] PROGMEM;
private:
uint16_t CO2;
};
const char EZOCO2::id[] PROGMEM = "CO2";
#endif // USE_EZOCO2
#endif // USE_I2C

View File

@ -1,5 +1,5 @@
/*
xsns_78_ezoph.ino - EZO EC I2C EC sensor support for Tasmota
xsns_78_ezoec.ino - EZO EC I2C EC sensor support for Tasmota
Copyright (C) 2020 Christopher Tremblay
@ -35,8 +35,8 @@ struct EZOEC : public EZOStruct {
virtual void Show(bool json, const char *name)
{
char str[6];
dtostrfd(EC, 2, str);
char str[10];
dtostrfd(EC, 3, str);
if (json) {
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_EC "\":%s}" ), name, str);
@ -48,9 +48,13 @@ struct EZOEC : public EZOStruct {
}
}
static const char id[] PROGMEM;
private:
float EC;
};
const char EZOEC::id[] PROGMEM = "EC";
#endif // USE_EZOEC
#endif // USE_I2C

View File

@ -52,10 +52,14 @@ struct EZOHUM : public EZOStruct {
}
}
static const char id[] PROGMEM;
private:
float humidity;
float temperature;
};
const char EZOHUM::id[] PROGMEM = "HUM";
#endif // USE_EZOHUM
#endif // USE_I2C

View File

@ -35,8 +35,8 @@ struct EZOORP : public EZOStruct {
virtual void Show(bool json, const char *name)
{
char str[6];
dtostrfd(ORP, 0, str);
char str[8];
dtostrfd(ORP, 2, str);
if (json) {
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_ORP "\":%s}" ), name, str);
@ -48,11 +48,13 @@ struct EZOORP : public EZOStruct {
}
}
static const char id[] PROGMEM;
private:
float ORP;
};
const char EZOORP::id[] PROGMEM = "ORP";
#endif // USE_EZOORP
#endif // USE_I2C

View File

@ -22,8 +22,8 @@
#define EZO_PH_READ_LATENCY 900
struct EZOpH : public EZOStruct {
EZOpH(uint32_t addr) : EZOStruct(addr), pH(NAN) {}
struct EZOPH : public EZOStruct {
EZOPH(uint32_t addr) : EZOStruct(addr), pH(NAN) {}
virtual void ProcessMeasurement(void)
{
@ -48,9 +48,13 @@ struct EZOpH : public EZOStruct {
}
}
static const char id[] PROGMEM;
private:
float pH;
};
const char EZOPH::id[] PROGMEM = "pH";
#endif // USE_EZOPH
#endif // USE_I2C

View File

@ -34,7 +34,7 @@ struct EZORTD : public EZOStruct {
}
virtual void Show(bool json, const char *name)
{
{
char str[10];
dtostrfd(ConvertTemp(temperature), Settings.flag2.temperature_resolution, str);
@ -46,11 +46,15 @@ struct EZORTD : public EZOStruct {
WSContentSend_PD(HTTP_SNS_TEMP, name, str, TempUnit());
#endif // USE_WEBSERVER
}
}
}
static const char id[] PROGMEM;
private:
float temperature;
};
const char EZORTD::id[] PROGMEM = "RTD";
#endif // USE_EZORTD
#endif // USE_I2C

View File

@ -28,7 +28,6 @@
// List of known EZO devices and their default address
enum {
EZO_DO = 0x61, // D.O.
EZO_ORP = 0x62, // ORP
@ -49,83 +48,37 @@ enum {
};
const char EZO_EMPTY[] PROGMEM = "";
//const char EZO_DO_NAME[] PROGMEM = "DO";
#ifdef USE_EZOORP
const char EZO_ORP_NAME[] PROGMEM = "ORP";
#endif
#ifdef USE_EZOPH
const char EZO_PH_NAME[] PROGMEM = "pH";
#endif
#ifdef USE_EZOEC
const char EZO_EC_NAME[] PROGMEM = "EC";
#endif
#ifdef USE_EZORTD
const char EZO_RTD_NAME[] PROGMEM = "RTD";
#endif
//const char EZO_PMP_NAME[] PROGMEM = "PMP";
//const char EZO_FLO_NAME[] PROGMEM = "FLO";
const char EZO_CO2_NAME[] PROGMEM = "CO2";
//const char EZO_PRS_NAME[] PROGMEM = "PRS";
//const char EZO_O2_NAME[] PROGMEM = "O2";
#ifdef USE_EZOHUM
const char EZO_HUM_NAME[] PROGMEM = "HUM";
#endif
//const char EZO_RGB_NAME[] PROGMEM = "RGB";
// Creates a complex preprocessor macro to fetch a specified class OR EZOStruct if it wasn't defined
template <class T, class = void> struct IsComplete : std::false_type {};
template <class T> struct IsComplete< T, decltype(void(sizeof(T))) > : std::true_type {};
#define GET_EZO_CLASS(CLASS) std::conditional<IsComplete<CLASS>::value, CLASS, EZOStruct>::type
// The order of the EZO devices must map with the enum declared above
const char *const EZOSupport[EZO_ADDR_n] PROGMEM = {
EZO_EMPTY,
#ifdef USE_EZOORP
EZO_ORP_NAME,
#else
EZO_EMPTY,
#endif
#ifdef USE_EZOPH
EZO_PH_NAME,
#else
EZO_EMPTY,
#endif
#ifdef USE_EZOEC
EZO_EC_NAME,
#else
EZO_EMPTY,
#endif
EZO_EMPTY,
#ifdef USE_EZORTD
EZO_RTD_NAME,
#else
EZO_EMPTY,
#endif
EZO_EMPTY,
EZO_EMPTY,
#ifdef USE_EZOCO2
EZO_CO2_NAME,
#else
EZO_EMPTY,
#endif
EZO_EMPTY,
EZO_EMPTY,
EZO_EMPTY,
EZO_EMPTY,
EZO_EMPTY,
#ifdef USE_EZOHUM
EZO_HUM_NAME,
#else
EZO_EMPTY,
#endif
EZO_EMPTY,
EZOStruct::id, // "DO"
GET_EZO_CLASS(EZOORP)::id,
GET_EZO_CLASS(EZOPH)::id,
GET_EZO_CLASS(EZOEC)::id,
EZOStruct::id,
GET_EZO_CLASS(EZORTD)::id,
EZOStruct::id, // "PMP"
EZOStruct::id, // "FLO"
GET_EZO_CLASS(EZOCO2)::id,
EZOStruct::id, // "PRS"
EZOStruct::id,
EZOStruct::id, // "O2"
EZOStruct::id,
EZOStruct::id,
GET_EZO_CLASS(EZOHUM)::id,
EZOStruct::id, // "RGB"
};
#define CREATE_EZO_CLASS(CLASS) \
case EZO_ ## CLASS: \
sensor[count] = new EZO ## CLASS(addr); \
break;
struct EZOManager {
@ -252,34 +205,22 @@ private:
// We use switch intead of virtual function to save RAM
switch (j + EZO_ADDR_0) {
#ifdef USE_EZOORP
case EZO_ORP:
sensor[count] = new EZOORP(addr);
break;
CREATE_EZO_CLASS(ORP)
#endif
#ifdef USE_EZOPH
case EZO_PH:
sensor[count] = new EZOpH(addr);
break;
CREATE_EZO_CLASS(PH)
#endif
#ifdef USE_EZOEC
case EZO_EC:
sensor[count] = new EZOEC(addr);
break;
CREATE_EZO_CLASS(EC)
#endif
#ifdef USE_EZORTD
case EZO_RTD:
sensor[count] = new EZORTD(addr);
break;
CREATE_EZO_CLASS(RTD)
#endif
#ifdef USE_EZOCO2
case EZO_CO2:
sensor[count] = new EZOCO2(addr);
break;
CREATE_EZO_CLASS(CO2)
#endif
#ifdef USE_EZOHUM
case EZO_HUM:
sensor[count] = new EZOHUM(addr);
break;
CREATE_EZO_CLASS(HUM)
#endif
}