mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Add function to set SDS011 sensor in sleeping state (#1416)
Co-authored-by: aurelien <aurelien.antunes@gmail.com>
This commit is contained in:
		| @@ -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_); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user