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