ESPHome  2024.5.2
tmp1075.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace tmp1075 {
9 
10 struct TMP1075Config {
11  union {
12  struct {
13  uint8_t oneshot : 1; // One-shot conversion mode. Writing 1, starts a single temperature
14  // conversion. Read returns 0.
15 
16  uint8_t rate : 2; // Conversion rate setting when device is in continuous conversion mode.
17  // 00: 27.5 ms conversion rate
18  // 01: 55 ms conversion rate
19  // 10: 110 ms conversion rate
20  // 11: 220 ms conversion rate (35 ms TMP1075N)
21 
22  uint8_t faults : 2; // Consecutive fault measurements to trigger the alert function.
23  // 00: 1 fault
24  // 01: 2 faults
25  // 10: 3 faults (4 faults TMP1075N)
26  // 11: 4 faults (6 faults TMP1075N)
27 
28  uint8_t polarity : 1; // Polarity of the output pin.
29  // 0: Active low ALERT pin
30  // 1: Active high ALERT pin
31 
32  uint8_t alert_mode : 1; // Selects the function of the ALERT pin.
33  // 0: ALERT pin functions in comparator mode
34  // 1: ALERT pin functions in interrupt mode
35 
36  uint8_t shutdown : 1; // Sets the device in shutdown mode to conserve power.
37  // 0: Device is in continuous conversion
38  // 1: Device is in shutdown mode
39  uint8_t unused : 8;
40  } fields;
41  uint16_t regvalue;
42  };
43 };
44 
50 };
51 
55 };
56 
58  public:
59  void setup() override;
60  void update() override;
61 
62  float get_setup_priority() const override { return setup_priority::DATA; }
63 
64  void dump_config() override;
65 
66  // Call write_config() after calling any of these to send the new config to
67  // the IC. The setup() function also does this.
68  void set_alert_limit_low(const float temp) { this->alert_limit_low_ = temp; }
69  void set_alert_limit_high(const float temp) { this->alert_limit_high_ = temp; }
70  void set_oneshot(const bool oneshot) { config_.fields.oneshot = oneshot; }
71  void set_conversion_rate(const enum EConversionRate rate) { config_.fields.rate = rate; }
72  void set_alert_polarity(const bool polarity) { config_.fields.polarity = polarity; }
73  void set_alert_function(const enum EAlertFunction function) { config_.fields.alert_mode = function; }
74  void set_fault_count(int faults);
75 
76  void write_config();
77 
78  protected:
79  TMP1075Config config_ = {};
80 
81  // Disable the alert pin by default.
82  float alert_limit_low_ = -128.0f;
83  float alert_limit_high_ = 127.9375f;
84 
85  void send_alert_limit_low_();
86  void send_alert_limit_high_();
87  void send_config_();
88  void log_config_();
89 };
90 
91 } // namespace tmp1075
92 } // namespace esphome
void setup()
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
void set_alert_limit_low(const float temp)
Definition: tmp1075.h:68
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_alert_polarity(const bool polarity)
Definition: tmp1075.h:72
void set_conversion_rate(const enum EConversionRate rate)
Definition: tmp1075.h:71
void set_alert_limit_high(const float temp)
Definition: tmp1075.h:69
void set_alert_function(const enum EAlertFunction function)
Definition: tmp1075.h:73
float get_setup_priority() const override
Definition: tmp1075.h:62
struct esphome::tmp1075::TMP1075Config::@105::@107 fields
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
void set_oneshot(const bool oneshot)
Definition: tmp1075.h:70
Base-class for all sensors.
Definition: sensor.h:57
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133