Add function to set SDS011 sensor in sleeping state (#1416)

Co-authored-by: aurelien <aurelien.antunes@gmail.com>
This commit is contained in:
onde2rock 2021-05-12 06:38:29 +02:00 committed by GitHub
parent 1e46b4073f
commit 5dc40049be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View file

@ -50,6 +50,21 @@ void SDS011Component::setup() {
this->sds011_write_command_(command_data);
}
void SDS011Component::set_working_state(bool working_state) {
if (this->rx_mode_only_) {
// In RX-only mode we do not setup the sensor, it is assumed to be setup
// already
return;
}
uint8_t command_data[SDS011_DATA_REQUEST_LENGTH] = {0};
command_data[0] = SDS011_COMMAND_SLEEP;
command_data[1] = SDS011_SET_MODE;
command_data[2] = working_state ? SDS011_MODE_WORK : SDS011_MODE_SLEEP;
command_data[13] = 0xff;
command_data[14] = 0xff;
this->sds011_write_command_(command_data);
}
void SDS011Component::dump_config() {
ESP_LOGCONFIG(TAG, "SDS011:");
ESP_LOGCONFIG(TAG, " Update Interval: %u min", this->update_interval_min_);

View file

@ -25,6 +25,7 @@ class SDS011Component : public Component, public uart::UARTDevice {
void set_update_interval(uint32_t val) { /* ignore */
}
void set_update_interval_min(uint8_t update_interval_min);
void set_working_state(bool working_state);
protected:
void sds011_write_command_(const uint8_t *command);