mirror of
https://github.com/esphome/esphome.git
synced 2025-03-14 14:48:18 +00:00
mhz19: add detection of B sensor revision
it will allow to report exact sensor type in dump config and later will be used for turning off autocalibration. Signed-off-by: Igor Mammedov <imammedo@redhat.com>
This commit is contained in:
parent
568da66e04
commit
886f84af29
@ -25,7 +25,29 @@ const char *dump_data_buf(const uint8_t *data) {
|
||||
return hex_buf;
|
||||
}
|
||||
|
||||
static bool setup_done;
|
||||
|
||||
void MHZ19Component::setup() {
|
||||
uint8_t response[MHZ19_PDU_LENGTH];
|
||||
while (!this->mhz19_write_command_(MHZ19_COMMAND_GET_PPM, response)) {
|
||||
delay(500);
|
||||
}
|
||||
|
||||
/* MH-Z19B(s == 0) and MH-Z19(s != 0) */
|
||||
uint8_t s = response[5];
|
||||
if (response[5] == 0 && this->model_b_ == false) {
|
||||
ESP_LOGD(TAG, "MH-Z19B detected");
|
||||
this->model_b_ = true;
|
||||
}
|
||||
|
||||
setup_done = true;
|
||||
}
|
||||
|
||||
void MHZ19Component::update() {
|
||||
if (!setup_done) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t response[MHZ19_PDU_LENGTH];
|
||||
if (!this->mhz19_write_command_(MHZ19_COMMAND_GET_PPM, response)) {
|
||||
ESP_LOGW(TAG, "Reading data from MHZ19 failed!");
|
||||
@ -100,7 +122,7 @@ bool MHZ19Component::mhz19_write_command_(const uint8_t *command, uint8_t *respo
|
||||
}
|
||||
float MHZ19Component::get_setup_priority() const { return setup_priority::DATA; }
|
||||
void MHZ19Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "MH-Z19:");
|
||||
ESP_LOGCONFIG(TAG, "MH-Z19%s:", this->model_b_ ? "B" : "");
|
||||
LOG_SENSOR(" ", "CO2", this->co2_sensor_);
|
||||
LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ class MHZ19Component : public PollingComponent, public uart::UARTDevice {
|
||||
public:
|
||||
float get_setup_priority() const override;
|
||||
|
||||
void setup() override;
|
||||
void update() override;
|
||||
void dump_config() override;
|
||||
|
||||
@ -22,6 +23,7 @@ class MHZ19Component : public PollingComponent, public uart::UARTDevice {
|
||||
|
||||
sensor::Sensor *temperature_sensor_{nullptr};
|
||||
sensor::Sensor *co2_sensor_{nullptr};
|
||||
bool model_b_;
|
||||
};
|
||||
|
||||
} // namespace mhz19
|
||||
|
Loading…
x
Reference in New Issue
Block a user