MHZ19: Allow enable and disable of ABC

This commit is contained in:
andrethomas 2019-02-01 18:46:37 +02:00
parent de41a88bec
commit 7e56dc538d
2 changed files with 41 additions and 13 deletions

View File

@ -163,6 +163,20 @@ typedef union {
};
} 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 {
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)
Mcp230xxCfg mcp230xx_config[16]; // 6F6
uint8_t mcp230xx_int_prio; // 716
uint8_t free_717[1]; // 717
SensorCfg1 SensorBits1; // 717 On/Off settings used by Sensor Commands
uint16_t mcp230xx_int_timer; // 718
uint8_t rgbwwTable[5]; // 71A

View File

@ -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
*
* 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
* 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.
\*********************************************************************************************/
#define MHZ19_ABC_ENABLE 1 // Automatic Baseline Correction (0 = off, 1 = on (default))
/*********************************************************************************************/
#include <TasmotaSerial.h>
#ifndef CO2_LOW
@ -72,6 +71,9 @@ TasmotaSerial *MhzSerial;
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 };
const uint8_t kMhzCommands[][4] PROGMEM = {
// 2 3 6 7
@ -88,7 +90,6 @@ const uint8_t kMhzCommands[][4] PROGMEM = {
uint8_t mhz_type = 1;
uint16_t mhz_last_ppm = 0;
uint8_t mhz_filter = MHZ19_FILTER_OPTION;
bool mhz_abc_enable = MHZ19_ABC_ENABLE;
bool mhz_abc_must_apply = false;
float mhz_temperature = 0;
@ -218,7 +219,7 @@ void MhzEverySecond(void)
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 (!mhz_abc_enable) {
if (Settings.SensorBits1.mhz19b_abc_disable) {
// After bootup of the sensor the ABC will be enabled.
// Thus only actively disable after bootup.
mhz_abc_must_apply = true;
@ -235,7 +236,7 @@ void MhzEverySecond(void)
if (0 == s || 64 == s) { // Reading is stable.
if (mhz_abc_must_apply) {
mhz_abc_must_apply = false;
if (mhz_abc_enable) {
if (!Settings.SensorBits1.mhz19b_abc_disable) {
MhzSendCmd(MHZ_CMND_ABCENABLE);
} else {
MhzSendCmd(MHZ_CMND_ABCDISABLE);
@ -252,8 +253,8 @@ void MhzEverySecond(void)
/*********************************************************************************************\
* Command Sensor15
*
* 0 - (Not implemented) ABC Off
* 1 - (Not implemented) ABC On
* 0 - ABC Off
* 1 - ABC On (Default)
* 2 - Manual start = ABC Off
* 3 - (Not implemented) Optional filter settings
* 9 - Reset
@ -273,6 +274,16 @@ bool MhzCommandSensor(void)
bool serviced = true;
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:
MhzSendCmd(MHZ_CMND_ZEROPOINT);
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);
break;
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;