mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-31 06:36:33 +00:00
Merge pull request #5088 from andrethomas/development
MHZ19: Allow enable and disable of ABC
This commit is contained in:
commit
91e5a82e98
@ -163,6 +163,20 @@ typedef union {
|
|||||||
};
|
};
|
||||||
} Mcp230xxCfg;
|
} Mcp230xxCfg;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
uint8_t data;
|
||||||
|
struct {
|
||||||
|
uint8_t spare0 : 1;
|
||||||
|
uint8_t spare1 : 1;
|
||||||
|
uint8_t spare2 : 1;
|
||||||
|
uint8_t spare3 : 1;
|
||||||
|
uint8_t spare4 : 1;
|
||||||
|
uint8_t spare5 : 1;
|
||||||
|
uint8_t spare6 : 1;
|
||||||
|
uint8_t mhz19b_abc_disable : 1; // Disable ABC (Automatic Baseline Correction for MHZ19(B) (0 = Enabled (default), 1 = Disabled with Sensor15 command)
|
||||||
|
};
|
||||||
|
} SensorCfg1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
struct SYSCFG {
|
struct SYSCFG {
|
||||||
unsigned long cfg_holder; // 000 Pre v6 header
|
unsigned long cfg_holder; // 000 Pre v6 header
|
||||||
@ -311,8 +325,7 @@ struct SYSCFG {
|
|||||||
uint8_t knx_CB_param[MAX_KNX_CB]; // 6EC Type of Output (set relay, toggle relay, reply sensor value)
|
uint8_t knx_CB_param[MAX_KNX_CB]; // 6EC Type of Output (set relay, toggle relay, reply sensor value)
|
||||||
Mcp230xxCfg mcp230xx_config[16]; // 6F6
|
Mcp230xxCfg mcp230xx_config[16]; // 6F6
|
||||||
uint8_t mcp230xx_int_prio; // 716
|
uint8_t mcp230xx_int_prio; // 716
|
||||||
|
SensorCfg1 SensorBits1; // 717 On/Off settings used by Sensor Commands
|
||||||
uint8_t free_717[1]; // 717
|
|
||||||
|
|
||||||
uint16_t mcp230xx_int_timer; // 718
|
uint16_t mcp230xx_int_timer; // 718
|
||||||
uint8_t rgbwwTable[5]; // 71A
|
uint8_t rgbwwTable[5]; // 71A
|
||||||
|
@ -39,7 +39,10 @@ enum MhzFilterOptions {MHZ19_FILTER_OFF, MHZ19_FILTER_OFF_ALLSAMPLES, MHZ19_FILT
|
|||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* Source: http://www.winsen-sensor.com/d/files/infrared-gas-sensor/mh-z19b-co2-ver1_0.pdf
|
* Source: http://www.winsen-sensor.com/d/files/infrared-gas-sensor/mh-z19b-co2-ver1_0.pdf
|
||||||
*
|
*
|
||||||
* Automatic Baseline Correction (ABC logic function)
|
* Automatic Baseline Correction (ABC logic function) is enabled by default but may be disabled with command
|
||||||
|
* Sensor15 0
|
||||||
|
* and enabled again with command
|
||||||
|
* Sensor15 1
|
||||||
*
|
*
|
||||||
* ABC logic function refers to that sensor itself do zero point judgment and automatic calibration procedure
|
* ABC logic function refers to that sensor itself do zero point judgment and automatic calibration procedure
|
||||||
* intelligently after a continuous operation period. The automatic calibration cycle is every 24 hours after powered on.
|
* intelligently after a continuous operation period. The automatic calibration cycle is every 24 hours after powered on.
|
||||||
@ -52,10 +55,6 @@ enum MhzFilterOptions {MHZ19_FILTER_OFF, MHZ19_FILTER_OFF_ALLSAMPLES, MHZ19_FILT
|
|||||||
* Please do zero calibration timely, such as manual or commend calibration.
|
* Please do zero calibration timely, such as manual or commend calibration.
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
#define MHZ19_ABC_ENABLE 1 // Automatic Baseline Correction (0 = off, 1 = on (default))
|
|
||||||
|
|
||||||
/*********************************************************************************************/
|
|
||||||
|
|
||||||
#include <TasmotaSerial.h>
|
#include <TasmotaSerial.h>
|
||||||
|
|
||||||
#ifndef CO2_LOW
|
#ifndef CO2_LOW
|
||||||
@ -72,6 +71,9 @@ TasmotaSerial *MhzSerial;
|
|||||||
|
|
||||||
const char kMhzModels[] PROGMEM = "|B";
|
const char kMhzModels[] PROGMEM = "|B";
|
||||||
|
|
||||||
|
const char ABC_ENABLED[] PROGMEM = "ABC is Enabled";
|
||||||
|
const char ABC_DISABLED[] PROGMEM = "ABC is Enabled";
|
||||||
|
|
||||||
enum MhzCommands { MHZ_CMND_READPPM, MHZ_CMND_ABCENABLE, MHZ_CMND_ABCDISABLE, MHZ_CMND_ZEROPOINT, MHZ_CMND_RESET, MHZ_CMND_RANGE_1000, MHZ_CMND_RANGE_2000, MHZ_CMND_RANGE_3000, MHZ_CMND_RANGE_5000 };
|
enum MhzCommands { MHZ_CMND_READPPM, MHZ_CMND_ABCENABLE, MHZ_CMND_ABCDISABLE, MHZ_CMND_ZEROPOINT, MHZ_CMND_RESET, MHZ_CMND_RANGE_1000, MHZ_CMND_RANGE_2000, MHZ_CMND_RANGE_3000, MHZ_CMND_RANGE_5000 };
|
||||||
const uint8_t kMhzCommands[][4] PROGMEM = {
|
const uint8_t kMhzCommands[][4] PROGMEM = {
|
||||||
// 2 3 6 7
|
// 2 3 6 7
|
||||||
@ -88,7 +90,6 @@ const uint8_t kMhzCommands[][4] PROGMEM = {
|
|||||||
uint8_t mhz_type = 1;
|
uint8_t mhz_type = 1;
|
||||||
uint16_t mhz_last_ppm = 0;
|
uint16_t mhz_last_ppm = 0;
|
||||||
uint8_t mhz_filter = MHZ19_FILTER_OPTION;
|
uint8_t mhz_filter = MHZ19_FILTER_OPTION;
|
||||||
bool mhz_abc_enable = MHZ19_ABC_ENABLE;
|
|
||||||
bool mhz_abc_must_apply = false;
|
bool mhz_abc_must_apply = false;
|
||||||
|
|
||||||
float mhz_temperature = 0;
|
float mhz_temperature = 0;
|
||||||
@ -218,7 +219,7 @@ void MhzEverySecond(void)
|
|||||||
|
|
||||||
uint16_t u = (mhz_response[6] << 8) | mhz_response[7];
|
uint16_t u = (mhz_response[6] << 8) | mhz_response[7];
|
||||||
if (15000 == u) { // During (and only ever at) sensor boot, 'u' is reported as 15000
|
if (15000 == u) { // During (and only ever at) sensor boot, 'u' is reported as 15000
|
||||||
if (!mhz_abc_enable) {
|
if (Settings.SensorBits1.mhz19b_abc_disable) {
|
||||||
// After bootup of the sensor the ABC will be enabled.
|
// After bootup of the sensor the ABC will be enabled.
|
||||||
// Thus only actively disable after bootup.
|
// Thus only actively disable after bootup.
|
||||||
mhz_abc_must_apply = true;
|
mhz_abc_must_apply = true;
|
||||||
@ -235,7 +236,7 @@ void MhzEverySecond(void)
|
|||||||
if (0 == s || 64 == s) { // Reading is stable.
|
if (0 == s || 64 == s) { // Reading is stable.
|
||||||
if (mhz_abc_must_apply) {
|
if (mhz_abc_must_apply) {
|
||||||
mhz_abc_must_apply = false;
|
mhz_abc_must_apply = false;
|
||||||
if (mhz_abc_enable) {
|
if (!Settings.SensorBits1.mhz19b_abc_disable) {
|
||||||
MhzSendCmd(MHZ_CMND_ABCENABLE);
|
MhzSendCmd(MHZ_CMND_ABCENABLE);
|
||||||
} else {
|
} else {
|
||||||
MhzSendCmd(MHZ_CMND_ABCDISABLE);
|
MhzSendCmd(MHZ_CMND_ABCDISABLE);
|
||||||
@ -252,8 +253,8 @@ void MhzEverySecond(void)
|
|||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* Command Sensor15
|
* Command Sensor15
|
||||||
*
|
*
|
||||||
* 0 - (Not implemented) ABC Off
|
* 0 - ABC Off
|
||||||
* 1 - (Not implemented) ABC On
|
* 1 - ABC On (Default)
|
||||||
* 2 - Manual start = ABC Off
|
* 2 - Manual start = ABC Off
|
||||||
* 3 - (Not implemented) Optional filter settings
|
* 3 - (Not implemented) Optional filter settings
|
||||||
* 9 - Reset
|
* 9 - Reset
|
||||||
@ -273,6 +274,16 @@ bool MhzCommandSensor(void)
|
|||||||
bool serviced = true;
|
bool serviced = true;
|
||||||
|
|
||||||
switch (XdrvMailbox.payload) {
|
switch (XdrvMailbox.payload) {
|
||||||
|
case 0:
|
||||||
|
Settings.SensorBits1.mhz19b_abc_disable = true;
|
||||||
|
MhzSendCmd(MHZ_CMND_ABCDISABLE);
|
||||||
|
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, ABC_DISABLED);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Settings.SensorBits1.mhz19b_abc_disable = false;
|
||||||
|
MhzSendCmd(MHZ_CMND_ABCENABLE);
|
||||||
|
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, ABC_ENABLED);
|
||||||
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
MhzSendCmd(MHZ_CMND_ZEROPOINT);
|
MhzSendCmd(MHZ_CMND_ZEROPOINT);
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_ZERO_POINT_CALIBRATION);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_ZERO_POINT_CALIBRATION);
|
||||||
@ -298,7 +309,11 @@ bool MhzCommandSensor(void)
|
|||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RANGE_5000);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RANGE_5000);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
serviced = false;
|
if (!Settings.SensorBits1.mhz19b_abc_disable) {
|
||||||
|
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, ABC_ENABLED);
|
||||||
|
} else {
|
||||||
|
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, ABC_DISABLED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return serviced;
|
return serviced;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user