ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
honeywellabp2.cpp
Go to the documentation of this file.
1#include "honeywellabp2.h"
3#include "esphome/core/log.h"
4
6
7static const uint8_t STATUS_BIT_POWER = 6;
8static const uint8_t STATUS_BIT_BUSY = 5;
9static const uint8_t STATUS_BIT_ERROR = 2;
10static const uint8_t STATUS_MATH_SAT = 0;
11
12static const char *const TAG = "honeywellabp2";
13
15 if (this->read(raw_data_, 7) != i2c::ERROR_OK) {
16 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
17 this->status_set_warning(LOG_STR("couldn't read sensor data"));
18 return;
19 }
20 float press_counts = encode_uint24(raw_data_[1], raw_data_[2], raw_data_[3]); // calculate digital pressure counts
21 float temp_counts = encode_uint24(raw_data_[4], raw_data_[5], raw_data_[6]); // calculate digital temperature counts
22
23 this->last_pressure_ = (((press_counts - this->min_count_) / (this->max_count_ - this->min_count_)) *
24 (this->max_pressure_ - this->min_pressure_)) +
25 this->min_pressure_;
26 this->last_temperature_ = (temp_counts * 200 / 16777215) - 50;
28}
29
31 if (this->write(i2c_cmd_, 3) != i2c::ERROR_OK) {
32 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
33 this->status_set_warning(LOG_STR("couldn't start measurement"));
34 return;
35 }
36 this->measurement_running_ = true;
37}
38
40 if (this->read(raw_data_, 1) != i2c::ERROR_OK) {
41 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
42 this->status_set_warning(LOG_STR("couldn't check measurement"));
43 return false;
44 }
45 if ((raw_data_[0] & (0x1 << STATUS_BIT_BUSY)) > 0) {
46 return false;
47 }
48 this->measurement_running_ = false;
49 return true;
50}
51
53 ESP_LOGE(TAG, "Timeout!");
54 this->measurement_running_ = false;
55 this->status_set_warning(LOG_STR("measurement timed out"));
56}
57
59
61
63 if (this->measurement_running_) {
64 if (this->is_measurement_ready()) {
65 this->cancel_timeout("meas_timeout");
66
67 this->read_sensor_data();
68 if (pressure_sensor_ != nullptr) {
70 }
71 if (temperature_sensor_ != nullptr) {
73 }
74 }
75 }
76}
77
79 ESP_LOGV(TAG, "Update Honeywell ABP2 Sensor");
80
81 this->start_measurement();
82 this->set_timeout("meas_timeout", 100, [this] { this->measurement_timeout(); });
83}
84
86 ESP_LOGCONFIG(TAG,
87 " Min Pressure Range: %0.1f\n"
88 " Max Pressure Range: %0.1f",
89 this->min_pressure_, this->max_pressure_);
91 ESP_LOGCONFIG(TAG, " Transfer function A");
92 } else {
93 ESP_LOGCONFIG(TAG, " Transfer function B");
94 }
95 LOG_UPDATE_INTERVAL(this);
96}
97
99 this->transfer_function_ = transfer_function;
101 this->max_count_ = this->max_count_b_;
102 this->min_count_ = this->min_count_b_;
103 } else {
104 this->max_count_ = this->max_count_a_;
105 this->min_count_ = this->min_count_a_;
106 }
107}
108
109} // namespace esphome::honeywellabp2_i2c
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_timeout(const std voi set_timeout)(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
Definition component.h:493
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") bool cancel_timeout(const std boo cancel_timeout)(const char *name)
Cancel a timeout function.
Definition component.h:515
void status_clear_warning()
Definition component.h:289
void set_transfer_function(ABP2TRANFERFUNCTION transfer_function)
ErrorCode write(const uint8_t *data, size_t len) const
writes an array of bytes to a device using an I2CBus
Definition i2c.h:183
ErrorCode read(uint8_t *data, size_t len) const
reads an array of bytes from the device using an I2CBus
Definition i2c.h:163
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:68
@ ERROR_OK
No error found during execution of method.
Definition i2c_bus.h:14
constexpr uint32_t encode_uint24(uint8_t byte1, uint8_t byte2, uint8_t byte3)
Encode a 24-bit value given three bytes in most to least significant byte order.
Definition helpers.h:863