ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
honeywellabp.cpp
Go to the documentation of this file.
1#include "honeywellabp.h"
2#include "esphome/core/log.h"
3
5
6static const char *const TAG = "honeywellabp";
7
8const float MIN_COUNT = 1638.4; // 1638 counts (10% of 2^14 counts or 0x0666)
9const float MAX_COUNT = 14745.6; // 14745 counts (90% of 2^14 counts or 0x3999)
10
12
14 // Polls the sensor for new data.
15 // transfer 4 bytes (the last two are temperature only used by some sensors)
16 this->enable();
17 buf_[0] = this->read_byte();
18 buf_[1] = this->read_byte();
19 buf_[2] = this->read_byte();
20 buf_[3] = this->read_byte();
21 this->disable();
22
23 // Check the status codes:
24 // status = 0 : normal operation
25 // status = 1 : device in command mode
26 // status = 2 : stale data
27 // status = 3 : diagnostic condition
28 status_ = buf_[0] >> 6 & 0x3;
29 ESP_LOGV(TAG, "Sensor status %d", status_);
30
31 // if device is normal and there is new data, bitmask and save the raw data
32 if (status_ == 0) {
33 // 14 - bit pressure is the last 6 bits of byte 0 (high bits) & all of byte 1 (lowest 8 bits)
34 pressure_count_ = ((uint16_t) (buf_[0]) << 8 & 0x3F00) | ((uint16_t) (buf_[1]) & 0xFF);
35 // 11 - bit temperature is all of byte 2 (lowest 8 bits) and the first three bits of byte 3
36 temperature_count_ = (((uint16_t) (buf_[2]) << 3) & 0x7F8) | (((uint16_t) (buf_[3]) >> 5) & 0x7);
37 ESP_LOGV(TAG, "Sensor pressure_count_ %d, temperature_count_ %d", pressure_count_, temperature_count_);
38 }
39 return status_;
40}
41
42// returns status
44
45// The pressure value from the most recent reading in raw counts
47
48// The temperature value from the most recent reading in raw counts
50
51// Converts a digital pressure measurement in counts to pressure measured
52float HONEYWELLABPSensor::countstopressure_(const int counts, const float min_pressure, const float max_pressure) {
53 return ((((float) counts - MIN_COUNT) * (max_pressure - min_pressure)) / (MAX_COUNT - MIN_COUNT)) + min_pressure;
54}
55
56// Converts a digital temperature measurement in counts to temperature in C
57// This will be invalid if sensore daoes not have temperature measurement capability
58float HONEYWELLABPSensor::countstotemperatures_(const int counts) { return (((float) counts / 2047.0) * 200.0) - 50.0; }
59
60// Pressure value from the most recent reading in units
64
65// Temperature value from the most recent reading in degrees C
67
69 ESP_LOGV(TAG, "Update Honeywell ABP Sensor");
70 if (readsensor_() == 0) {
71 if (this->pressure_sensor_ != nullptr)
73 if (this->temperature_sensor_ != nullptr)
75 }
76}
77
79
81 // LOG_SENSOR("", "HONEYWELLABP", this);
82 LOG_PIN(" CS Pin: ", this->cs_);
83 ESP_LOGCONFIG(TAG,
84 " Min Pressure Range: %0.1f\n"
85 " Max Pressure Range: %0.1f",
87 LOG_UPDATE_INTERVAL(this);
88}
89
91 this->honeywellabp_min_pressure_ = min_pressure;
92}
93
95 this->honeywellabp_max_pressure_ = max_pressure;
96}
97
98} // namespace esphome::honeywellabp
float countstopressure_(int counts, float min_pressure, float max_pressure)
void set_honeywellabp_min_pressure(float min_pressure)
void set_honeywellabp_max_pressure(float max_pressure)
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:68
constexpr float LATE
For components that should be initialized at the very end of the setup process.
Definition component.h:57