10static const char *
const TAG =
"hc8";
11static const std::array<uint8_t, 5> HC8_COMMAND_GET_PPM{0x64, 0x69, 0x03, 0x5E, 0x4E};
12static const std::array<uint8_t, 3> HC8_COMMAND_CALIBRATE_PREAMBLE{0x11, 0x03, 0x03};
29 if (now_ms < warmup_ms) {
30 ESP_LOGW(TAG,
"HC8 warming up, %" PRIu32
" s left", (warmup_ms - now_ms) / 1000);
44 std::array<uint8_t, 14> response;
45 if (!this->
read_array(response.data(), response.size())) {
46 ESP_LOGW(TAG,
"Reading data from HC8 failed!");
51 if (response[0] != 0x64 || response[1] != 0x69) {
52 ESP_LOGW(TAG,
"Invalid preamble from HC8!");
58 ESP_LOGW(TAG,
"HC8 Checksum mismatch");
66 ESP_LOGD(TAG,
"HC8 Received CO₂=%uppm", ppm);
73 ESP_LOGD(TAG,
"HC8 Calibrating baseline to %uppm", baseline);
75 std::array<uint8_t, 6> command{};
76 std::copy(begin(HC8_COMMAND_CALIBRATE_PREAMBLE),
end(HC8_COMMAND_CALIBRATE_PREAMBLE), begin(command));
77 command[3] = baseline >> 8;
78 command[4] = baseline;
82 for (uint8_t i = 0; i < 5; ++i)
83 command[5] -= command[i];
92 ESP_LOGCONFIG(TAG,
"HC8:");
96 ESP_LOGCONFIG(TAG,
" Warmup time: %" PRIu32
" s", this->
warmup_seconds_);
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
void status_set_warning(const char *message=nullptr)
void status_clear_warning()
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
void calibrate(uint16_t baseline)
float get_setup_priority() const override
sensor::Sensor * co2_sensor_
void dump_config() override
void publish_state(float state)
Publish a new state to the front-end.
optional< std::array< uint8_t, N > > read_array()
void check_uart_settings(uint32_t baud_rate, uint8_t stop_bits=1, UARTParityOptions parity=UART_CONFIG_PARITY_NONE, uint8_t data_bits=8)
Check that the configuration of the UART bus matches the provided values and otherwise print a warnin...
void write_array(const uint8_t *data, size_t len)
const float DATA
For components that import data from directly connected sensors like DHT.
uint16_t crc16(const uint8_t *data, uint16_t len, uint16_t crc, uint16_t reverse_poly, bool refin, bool refout)
Calculate a CRC-16 checksum of data with size len.
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
Application App
Global storage of Application pointer - only one Application can exist.