diff --git a/esphome/components/ds248x/ds248x.h b/esphome/components/ds248x/ds248x.h index 4e0f73b4f6..7a555c69cf 100644 --- a/esphome/components/ds248x/ds248x.h +++ b/esphome/components/ds248x/ds248x.h @@ -9,132 +9,133 @@ static const uint8_t NBR_CHANNELS = 8; namespace esphome { - namespace ds248x { +namespace ds248x { - enum class DS248xType : int { - DS2482_100 = 0, - DS2482_800 = 1, - }; +enum class DS248xType : int { + DS2482_100 = 0, + DS2482_800 = 1, +}; - class DS248xTemperatureSensor; +class DS248xTemperatureSensor; - class DS248xComponent : public PollingComponent, public i2c::I2CDevice { - friend class DS248xTemperatureSensor; - public: - void setup() override; - void dump_config() override; - void update() override; - float get_setup_priority() const override; +class DS248xComponent : public PollingComponent, public i2c::I2CDevice { + friend class DS248xTemperatureSensor; - void set_sleep_pin(InternalGPIOPin *pin) { sleep_pin_ = pin; } + public: + void setup() override; + void dump_config() override; + void update() override; + float get_setup_priority() const override; - void set_ds248x_type(const DS248xType type) { ds248x_type_ = type; } - void set_bus_sleep(bool enabled) { enable_bus_sleep_ = enabled; } - void set_hub_sleep(bool enabled) { enable_hub_sleep_ = enabled; } - void set_active_pullup(bool enabled) { enable_active_pullup_ = enabled; } - void set_strong_pullup(bool enabled) { enable_strong_pullup_ = enabled; } + void set_sleep_pin(InternalGPIOPin *pin) { sleep_pin_ = pin; } - void register_sensor(DS248xTemperatureSensor *sensor); + void set_ds248x_type(const DS248xType type) { ds248x_type_ = type; } + void set_bus_sleep(bool enabled) { enable_bus_sleep_ = enabled; } + void set_hub_sleep(bool enabled) { enable_hub_sleep_ = enabled; } + void set_active_pullup(bool enabled) { enable_active_pullup_ = enabled; } + void set_strong_pullup(bool enabled) { enable_strong_pullup_ = enabled; } - protected: - uint32_t readIdx; - uint64_t searchAddress; - uint8_t searchLastDiscrepancy; - uint8_t channel = 0; - bool last_device_found; + void register_sensor(DS248xTemperatureSensor *sensor); - InternalGPIOPin *sleep_pin_; + protected: + uint32_t readIdx; + uint64_t searchAddress; + uint8_t searchLastDiscrepancy; + uint8_t channel = 0; + bool last_device_found; - DS248xType ds248x_type_ = DS248xType::DS2482_100; - bool enable_bus_sleep_ = false; - bool enable_hub_sleep_ = false; - bool enable_active_pullup_ = false; - bool enable_strong_pullup_ = false; + InternalGPIOPin *sleep_pin_; - std::vector found_sensors_; - std::vector found_channel_sensors_; + DS248xType ds248x_type_ = DS248xType::DS2482_100; + bool enable_bus_sleep_ = false; + bool enable_hub_sleep_ = false; + bool enable_active_pullup_ = false; + bool enable_strong_pullup_ = false; - std::vector channel_sensors_[NBR_CHANNELS]; - std::vector sensors_; + std::vector found_sensors_; + std::vector found_channel_sensors_; - uint8_t read_config(); - void write_config(uint8_t cfg); + std::vector channel_sensors_[NBR_CHANNELS]; + std::vector sensors_; - uint8_t wait_while_busy(); + uint8_t read_config(); + void write_config(uint8_t cfg); - void reset_hub(); - bool set_channel(uint8_t channel); - uint8_t get_channel(); + uint8_t wait_while_busy(); - bool reset_devices(); + void reset_hub(); + bool set_channel(uint8_t channel); + uint8_t get_channel(); - void write_command(uint8_t command, uint8_t data); + bool reset_devices(); - void select(uint64_t address); + void write_command(uint8_t command, uint8_t data); - void write_to_wire(uint8_t data); + void select(uint64_t address); - uint8_t read_from_wire(); + void write_to_wire(uint8_t data); - bool search(uint64_t *address); - }; + uint8_t read_from_wire(); - class DS248xTemperatureSensor : public sensor::Sensor { - public: - void set_parent(DS248xComponent *parent) { parent_ = parent; } + bool search(uint64_t *address); +}; - // Helper to get a pointer to the address as uint8_t. - uint8_t *get_address8(); +class DS248xTemperatureSensor : public sensor::Sensor { + public: + void set_parent(DS248xComponent *parent) { parent_ = parent; } - // Helper to create (and cache) the name for this sensor. For example "0xfe0000031f1eaf29". - const std::string &get_address_name(); + // Helper to get a pointer to the address as uint8_t. + uint8_t *get_address8(); - // Set the 64-bit unsigned address for this sensor. - void set_address(uint64_t address); + // Helper to create (and cache) the name for this sensor. For example "0xfe0000031f1eaf29". + const std::string &get_address_name(); - // Set the channel of the 1-Wire bus for this sensor. - void set_channel(uint8_t channel); + // Set the 64-bit unsigned address for this sensor. + void set_address(uint64_t address); - // Get the channel of 1-Wire bus for this sensor. - uint8_t get_channel() const; + // Set the channel of the 1-Wire bus for this sensor. + void set_channel(uint8_t channel); - // Get the index of this sensor. (0 if using address.) - optional get_index() const; + // Get the channel of 1-Wire bus for this sensor. + uint8_t get_channel() const; - // Set the index of this sensor. If using index, address will be set after setup. - void set_index(uint8_t index); + // Get the index of this sensor. (0 if using address.) + optional get_index() const; - // Get the set resolution for this sensor. - uint8_t get_resolution() const; + // Set the index of this sensor. If using index, address will be set after setup. + void set_index(uint8_t index); - // Set the resolution for this sensor. - void set_resolution(uint8_t resolution); + // Get the set resolution for this sensor. + uint8_t get_resolution() const; - // Get the number of milliseconds we have to wait for the conversion phase. - uint16_t millis_to_wait_for_conversion() const; + // Set the resolution for this sensor. + void set_resolution(uint8_t resolution); - bool setup_sensor(); - bool read_scratch_pad(); + // Get the number of milliseconds we have to wait for the conversion phase. + uint16_t millis_to_wait_for_conversion() const; - bool check_scratch_pad(); + bool setup_sensor(); + bool read_scratch_pad(); - float get_temp_c(); + bool check_scratch_pad(); - std::string unique_id() override; + float get_temp_c(); - protected: - DS248xComponent *parent_; - uint64_t address_; - optional index_; + std::string unique_id() override; - uint8_t resolution_; - uint8_t channel_ = 0; - std::string address_name_; - uint8_t scratch_pad_[9] = { - 0, - }; - }; + protected: + DS248xComponent *parent_; + uint64_t address_; + optional index_; - } // namespace ds248x + uint8_t resolution_; + uint8_t channel_ = 0; + std::string address_name_; + uint8_t scratch_pad_[9] = { + 0, + }; +}; + +} // namespace ds248x } // namespace esphome