ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
tmp1075.h
Go to the documentation of this file.
1#pragma once
2
6
7namespace esphome::tmp1075 {
8
10 bool oneshot{false}; // One-shot conversion mode. Writing 1, starts a single temperature
11 // conversion. Read returns 0.
12
13 uint8_t rate{0}; // Conversion rate setting when device is in continuous conversion mode.
14 // 00: 27.5 ms conversion rate
15 // 01: 55 ms conversion rate
16 // 10: 110 ms conversion rate
17 // 11: 220 ms conversion rate (35 ms TMP1075N)
18
19 uint8_t faults{0}; // Consecutive fault measurements to trigger the alert function.
20 // 00: 1 fault
21 // 01: 2 faults
22 // 10: 3 faults (4 faults TMP1075N)
23 // 11: 4 faults (6 faults TMP1075N)
24
25 bool polarity{false}; // Polarity of the output pin.
26 // 0: Active low ALERT pin
27 // 1: Active high ALERT pin
28
29 bool alert_mode{false}; // Selects the function of the ALERT pin.
30 // 0: ALERT pin functions in comparator mode
31 // 1: ALERT pin functions in interrupt mode
32
33 bool shutdown{false}; // Sets the device in shutdown mode to conserve power.
34 // 0: Device is in continuous conversion
35 // 1: Device is in shutdown mode
36
37 // Upper byte of the configuration register: OS R1 R0 F1 F0 POL TM SD
38 uint8_t to_byte() const {
39 return (this->oneshot << 7) | ((this->rate & 0x03) << 5) | ((this->faults & 0x03) << 3) | (this->polarity << 2) |
40 (this->alert_mode << 1) | this->shutdown;
41 }
42};
43
50
55
56class TMP1075Sensor final : public PollingComponent, public sensor::Sensor, public i2c::I2CDevice {
57 public:
58 void setup() override;
59 void update() override;
60
61 void dump_config() override;
62
63 // Call write_config() after calling any of these to send the new config to
64 // the IC. The setup() function also does this.
65 void set_alert_limit_low(const float temp) { this->alert_limit_low_ = temp; }
66 void set_alert_limit_high(const float temp) { this->alert_limit_high_ = temp; }
67 void set_oneshot(const bool oneshot) { this->config_.oneshot = oneshot; }
68 void set_conversion_rate(const enum EConversionRate rate) { this->config_.rate = rate; }
69 void set_alert_polarity(const bool polarity) { this->config_.polarity = polarity; }
70 void set_alert_function(const enum EAlertFunction function) { this->config_.alert_mode = function; }
71 void set_fault_count(int faults);
72
73 void write_config();
74
75 protected:
77
78 // Disable the alert pin by default.
79 float alert_limit_low_ = -128.0f;
80 float alert_limit_high_ = 127.9375f;
81
84 void send_config_();
85 void log_config_();
86};
87
88} // namespace esphome::tmp1075
This class simplifies creating components that periodically check a state.
Definition component.h:519
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:144
Base-class for all sensors.
Definition sensor.h:47
void set_alert_limit_high(const float temp)
Definition tmp1075.h:66
void set_alert_function(const enum EAlertFunction function)
Definition tmp1075.h:70
void set_alert_polarity(const bool polarity)
Definition tmp1075.h:69
void set_conversion_rate(const enum EConversionRate rate)
Definition tmp1075.h:68
void set_oneshot(const bool oneshot)
Definition tmp1075.h:67
void set_fault_count(int faults)
Definition tmp1075.cpp:58
void set_alert_limit_low(const float temp)
Definition tmp1075.h:65