mirror of https://github.com/arendst/Tasmota.git
Merge pull request #4616 from Staars/development
possibility to change measurement range for MHZ-19b
This commit is contained in:
commit
26e84a139e
|
@ -72,13 +72,18 @@ TasmotaSerial *MhzSerial;
|
||||||
|
|
||||||
const char kMhzTypes[] PROGMEM = "MHZ19|MHZ19B";
|
const char kMhzTypes[] PROGMEM = "MHZ19|MHZ19B";
|
||||||
|
|
||||||
enum MhzCommands { MHZ_CMND_READPPM, MHZ_CMND_ABCENABLE, MHZ_CMND_ABCDISABLE, MHZ_CMND_ZEROPOINT, MHZ_CMND_RESET };
|
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[][2] PROGMEM = {
|
const uint8_t kMhzCommands[][4] PROGMEM = {
|
||||||
{0x86,0x00}, // mhz_cmnd_read_ppm
|
// 2 3 6 7
|
||||||
{0x79,0xA0}, // mhz_cmnd_abc_enable
|
{0x86,0x00,0x00,0x00}, // mhz_cmnd_read_ppm
|
||||||
{0x79,0x00}, // mhz_cmnd_abc_disable
|
{0x79,0xA0,0x00,0x00}, // mhz_cmnd_abc_enable
|
||||||
{0x87,0x00}, // mhz_cmnd_zeropoint
|
{0x79,0x00,0x00,0x00}, // mhz_cmnd_abc_disable
|
||||||
{0x8D,0x00}}; // mhz_cmnd_reset
|
{0x87,0x00,0x00,0x00}, // mhz_cmnd_zeropoint
|
||||||
|
{0x8D,0x00,0x00,0x00}, // mhz_cmnd_reset
|
||||||
|
{0x99,0x00,0x03,0xE8}, // mhz_cmnd_set_range_1000
|
||||||
|
{0x99,0x00,0x07,0xD0}, // mhz_cmnd_set_range_2000
|
||||||
|
{0x99,0x00,0x0B,0xB8}, // mhz_cmnd_set_range_3000
|
||||||
|
{0x99,0x00,0x13,0x88}}; // mhz_cmnd_set_range_5000
|
||||||
|
|
||||||
uint8_t mhz_type = 1;
|
uint8_t mhz_type = 1;
|
||||||
uint16_t mhz_last_ppm = 0;
|
uint16_t mhz_last_ppm = 0;
|
||||||
|
@ -110,15 +115,17 @@ size_t MhzSendCmd(byte command_id)
|
||||||
|
|
||||||
mhz_send[0] = 0xFF; // Start byte, fixed
|
mhz_send[0] = 0xFF; // Start byte, fixed
|
||||||
mhz_send[1] = 0x01; // Sensor number, 0x01 by default
|
mhz_send[1] = 0x01; // Sensor number, 0x01 by default
|
||||||
memcpy_P(&mhz_send[2], kMhzCommands[command_id], sizeof(kMhzCommands[0]));
|
memcpy_P(&mhz_send[2], kMhzCommands[command_id], sizeof(uint16_t));
|
||||||
/*
|
/*
|
||||||
mhz_send[4] = 0x00;
|
mhz_send[4] = 0x00;
|
||||||
mhz_send[5] = 0x00;
|
mhz_send[5] = 0x00;
|
||||||
mhz_send[6] = 0x00;
|
|
||||||
mhz_send[7] = 0x00;
|
|
||||||
*/
|
*/
|
||||||
|
memcpy_P(&mhz_send[6], kMhzCommands[command_id] + sizeof(uint16_t), sizeof(uint16_t));
|
||||||
mhz_send[8] = MhzCalculateChecksum(mhz_send);
|
mhz_send[8] = MhzCalculateChecksum(mhz_send);
|
||||||
|
|
||||||
|
snprintf_P(log_data, sizeof(log_data), PSTR("Final MhzCommand: %x %x %x %x %x %x %x %x %x"),mhz_send[0],mhz_send[1],mhz_send[2],mhz_send[3],mhz_send[4],mhz_send[5],mhz_send[6],mhz_send[7],mhz_send[8]);
|
||||||
|
AddLog(LOG_LEVEL_DEBUG);
|
||||||
|
|
||||||
return MhzSerial->write(mhz_send, sizeof(mhz_send));
|
return MhzSerial->write(mhz_send, sizeof(mhz_send));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,13 +253,22 @@ void MhzEverySecond(void)
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* Command Sensor15
|
* Command Sensor15
|
||||||
*
|
*
|
||||||
* 0 - (Not implemented) ABC Off
|
* 0 - (Not implemented) ABC Off
|
||||||
* 1 - (Not implemented) ABC On
|
* 1 - (Not implemented) ABC On
|
||||||
* 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
|
||||||
|
* 1000 - Range
|
||||||
|
* 2000 - Range
|
||||||
|
* 3000 - Range
|
||||||
|
* 5000 - Range
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
|
#define D_JSON_RANGE_1000 "1000 ppm range"
|
||||||
|
#define D_JSON_RANGE_2000 "2000 ppm range"
|
||||||
|
#define D_JSON_RANGE_3000 "3000 ppm range"
|
||||||
|
#define D_JSON_RANGE_5000 "5000 ppm range"
|
||||||
|
|
||||||
bool MhzCommandSensor(void)
|
bool MhzCommandSensor(void)
|
||||||
{
|
{
|
||||||
boolean serviced = true;
|
boolean serviced = true;
|
||||||
|
@ -266,6 +282,22 @@ bool MhzCommandSensor(void)
|
||||||
MhzSendCmd(MHZ_CMND_RESET);
|
MhzSendCmd(MHZ_CMND_RESET);
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RESET);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RESET);
|
||||||
break;
|
break;
|
||||||
|
case 1000:
|
||||||
|
MhzSendCmd(MHZ_CMND_RANGE_1000);
|
||||||
|
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RANGE_1000);
|
||||||
|
break;
|
||||||
|
case 2000:
|
||||||
|
MhzSendCmd(MHZ_CMND_RANGE_2000);
|
||||||
|
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RANGE_2000);
|
||||||
|
break;
|
||||||
|
case 3000:
|
||||||
|
MhzSendCmd(MHZ_CMND_RANGE_3000);
|
||||||
|
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RANGE_3000);
|
||||||
|
break;
|
||||||
|
case 5000:
|
||||||
|
MhzSendCmd(MHZ_CMND_RANGE_5000);
|
||||||
|
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RANGE_5000);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
serviced = false;
|
serviced = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue