mirror of
https://github.com/esphome/esphome.git
synced 2025-10-30 06:33:51 +00:00
Add support for TMP1075 temperature sensor (#4776)
* Add support for TMP1075 temperature sensor TMP1075 is a temperature sensor with I2C interface in industry standard LM75 form factor and pinout. https://www.ti.com/product/TMP1075 Example YAML: ```yaml sensor: - platform: tmp1075 name: TMP1075 Temperature id: radiator_temp update_interval: 10s i2c_id: i2c_bus_1 conversion_rate: 27.5ms alert: limit_low: 50 limit_high: 75 fault_count: 1 polarity: active_high ``` * Add myself as codeowner of the TMP1075 component * Include '°C' unit when logging low/high limit setting * Reformat No functional changes. * Fix logging: use %.4f for temperatures, not %d * Fix config initialisation * Use relative include for `tmp1075.h` * Apply formatting changes suggested by script/clang-tidy for ESP32 * Add YAML to test1.yaml * Fix test1.yaml by giving TMP1075 a name * Less verbose logging (debug -> verbose level) * Schema: reduce accuracy_decimals to 2 * I2C address as hexadecimal * Proper name for enum in Python The enum on the C++ side was renamed (clang-tidy) but I forgot to take that into account in the Python code. * Expose 'alert function' to the code generator/YAML params and remove 'shutdown' Shutdown mode doesn't work the way I expect it, so remove it until someone actually asks for it. Also 'alert mode' was renamed to 'alert function' for clarity. * Move simple setters to header file * Remove `load_config_();` function
This commit is contained in:
92
esphome/components/tmp1075/tmp1075.h
Normal file
92
esphome/components/tmp1075/tmp1075.h
Normal file
@@ -0,0 +1,92 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/i2c/i2c.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace tmp1075 {
|
||||
|
||||
struct TMP1075Config {
|
||||
union {
|
||||
struct {
|
||||
uint8_t oneshot : 1; // One-shot conversion mode. Writing 1, starts a single temperature
|
||||
// conversion. Read returns 0.
|
||||
|
||||
uint8_t rate : 2; // Conversion rate setting when device is in continuous conversion mode.
|
||||
// 00: 27.5 ms conversion rate
|
||||
// 01: 55 ms conversion rate
|
||||
// 10: 110 ms conversion rate
|
||||
// 11: 220 ms conversion rate (35 ms TMP1075N)
|
||||
|
||||
uint8_t faults : 2; // Consecutive fault measurements to trigger the alert function.
|
||||
// 00: 1 fault
|
||||
// 01: 2 faults
|
||||
// 10: 3 faults (4 faults TMP1075N)
|
||||
// 11: 4 faults (6 faults TMP1075N)
|
||||
|
||||
uint8_t polarity : 1; // Polarity of the output pin.
|
||||
// 0: Active low ALERT pin
|
||||
// 1: Active high ALERT pin
|
||||
|
||||
uint8_t alert_mode : 1; // Selects the function of the ALERT pin.
|
||||
// 0: ALERT pin functions in comparator mode
|
||||
// 1: ALERT pin functions in interrupt mode
|
||||
|
||||
uint8_t shutdown : 1; // Sets the device in shutdown mode to conserve power.
|
||||
// 0: Device is in continuous conversion
|
||||
// 1: Device is in shutdown mode
|
||||
uint8_t unused : 8;
|
||||
} fields;
|
||||
uint16_t regvalue;
|
||||
};
|
||||
};
|
||||
|
||||
enum EConversionRate {
|
||||
CONV_RATE_27_5_MS,
|
||||
CONV_RATE_55_MS,
|
||||
CONV_RATE_110_MS,
|
||||
CONV_RATE_220_MS,
|
||||
};
|
||||
|
||||
enum EAlertFunction {
|
||||
ALERT_COMPARATOR = 0,
|
||||
ALERT_INTERRUPT = 1,
|
||||
};
|
||||
|
||||
class TMP1075Sensor : public PollingComponent, public sensor::Sensor, public i2c::I2CDevice {
|
||||
public:
|
||||
void setup() override;
|
||||
void update() override;
|
||||
|
||||
float get_setup_priority() const override { return setup_priority::DATA; }
|
||||
|
||||
void dump_config() override;
|
||||
|
||||
// Call write_config() after calling any of these to send the new config to
|
||||
// the IC. The setup() function also does this.
|
||||
void set_alert_limit_low(const float temp) { this->alert_limit_low_ = temp; }
|
||||
void set_alert_limit_high(const float temp) { this->alert_limit_high_ = temp; }
|
||||
void set_oneshot(const bool oneshot) { config_.fields.oneshot = oneshot; }
|
||||
void set_conversion_rate(const enum EConversionRate rate) { config_.fields.rate = rate; }
|
||||
void set_alert_polarity(const bool polarity) { config_.fields.polarity = polarity; }
|
||||
void set_alert_function(const enum EAlertFunction function) { config_.fields.alert_mode = function; }
|
||||
void set_fault_count(int faults);
|
||||
|
||||
void write_config();
|
||||
|
||||
protected:
|
||||
TMP1075Config config_ = {};
|
||||
|
||||
// Disable the alert pin by default.
|
||||
float alert_limit_low_ = -128.0f;
|
||||
float alert_limit_high_ = 127.9375f;
|
||||
|
||||
void send_alert_limit_low_();
|
||||
void send_alert_limit_high_();
|
||||
void send_config_();
|
||||
void log_config_();
|
||||
};
|
||||
|
||||
} // namespace tmp1075
|
||||
} // namespace esphome
|
||||
Reference in New Issue
Block a user