ESPHome 2025.9.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
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, "Sensor pressure_count_ %d", pressure_count_);
39 ESP_LOGV(TAG, "Sensor temperature_count_ %d", temperature_count_);
40 }
41 return status_;
42}
43
44// returns status
46
47// The pressure value from the most recent reading in raw counts
49
50// The temperature value from the most recent reading in raw counts
52
53// Converts a digital pressure measurement in counts to pressure measured
54float HONEYWELLABPSensor::countstopressure_(const int counts, const float min_pressure, const float max_pressure) {
55 return ((((float) counts - MIN_COUNT) * (max_pressure - min_pressure)) / (MAX_COUNT - MIN_COUNT)) + min_pressure;
56}
57
58// Converts a digital temperature measurement in counts to temperature in C
59// This will be invalid if sensore daoes not have temperature measurement capability
60float HONEYWELLABPSensor::countstotemperatures_(const int counts) { return (((float) counts / 2047.0) * 200.0) - 50.0; }
61
62// Pressure value from the most recent reading in units
66
67// Temperature value from the most recent reading in degrees C
69
71 ESP_LOGV(TAG, "Update Honeywell ABP Sensor");
72 if (readsensor_() == 0) {
73 if (this->pressure_sensor_ != nullptr)
75 if (this->temperature_sensor_ != nullptr)
77 }
78}
79
81
83 // LOG_SENSOR("", "HONEYWELLABP", this);
84 LOG_PIN(" CS Pin: ", this->cs_);
85 ESP_LOGCONFIG(TAG,
86 " Min Pressure Range: %0.1f\n"
87 " Max Pressure Range: %0.1f",
89 LOG_UPDATE_INTERVAL(this);
90}
91
93 this->honeywellabp_min_pressure_ = min_pressure;
94}
95
97 this->honeywellabp_max_pressure_ = max_pressure;
98}
99
100} // namespace honeywellabp
101} // 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:45
const float LATE
For components that should be initialized at the very end of the setup process.
Definition component.cpp:59
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7