1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-15 07:08:20 +00:00

Update ds248x.h

check clang
This commit is contained in:
Iron Man 2024-04-23 19:53:35 +02:00 committed by GitHub
parent 996f453589
commit 858f5eafcd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

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