mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
Add function to set SDS011 sensor in sleeping state (#1416)
Co-authored-by: aurelien <aurelien.antunes@gmail.com>
This commit is contained in:
parent
1e46b4073f
commit
5dc40049be
2 changed files with 16 additions and 0 deletions
|
@ -50,6 +50,21 @@ void SDS011Component::setup() {
|
||||||
this->sds011_write_command_(command_data);
|
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() {
|
void SDS011Component::dump_config() {
|
||||||
ESP_LOGCONFIG(TAG, "SDS011:");
|
ESP_LOGCONFIG(TAG, "SDS011:");
|
||||||
ESP_LOGCONFIG(TAG, " Update Interval: %u min", this->update_interval_min_);
|
ESP_LOGCONFIG(TAG, " Update Interval: %u min", this->update_interval_min_);
|
||||||
|
|
|
@ -25,6 +25,7 @@ class SDS011Component : public Component, public uart::UARTDevice {
|
||||||
void set_update_interval(uint32_t val) { /* ignore */
|
void set_update_interval(uint32_t val) { /* ignore */
|
||||||
}
|
}
|
||||||
void set_update_interval_min(uint8_t update_interval_min);
|
void set_update_interval_min(uint8_t update_interval_min);
|
||||||
|
void set_working_state(bool working_state);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void sds011_write_command_(const uint8_t *command);
|
void sds011_write_command_(const uint8_t *command);
|
||||||
|
|
Loading…
Reference in a new issue