mirror of
https://github.com/esphome/esphome.git
synced 2025-10-30 06:33:51 +00:00
Move crc16 to helpers (#3780)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "senseair.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
@@ -42,7 +43,7 @@ void SenseAirComponent::update() {
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t calc_checksum = this->senseair_checksum_(response, 11);
|
||||
uint16_t calc_checksum = crc16(response, 11);
|
||||
uint16_t resp_checksum = (uint16_t(response[12]) << 8) | response[11];
|
||||
if (resp_checksum != calc_checksum) {
|
||||
ESP_LOGW(TAG, "SenseAir checksum doesn't match: 0x%02X!=0x%02X", resp_checksum, calc_checksum);
|
||||
@@ -60,23 +61,6 @@ void SenseAirComponent::update() {
|
||||
this->co2_sensor_->publish_state(ppm);
|
||||
}
|
||||
|
||||
uint16_t SenseAirComponent::senseair_checksum_(uint8_t *ptr, uint8_t length) {
|
||||
uint16_t crc = 0xFFFF;
|
||||
uint8_t i;
|
||||
while (length--) {
|
||||
crc ^= *ptr++;
|
||||
for (i = 0; i < 8; i++) {
|
||||
if ((crc & 0x01) != 0) {
|
||||
crc >>= 1;
|
||||
crc ^= 0xA001;
|
||||
} else {
|
||||
crc >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
void SenseAirComponent::background_calibration() {
|
||||
// Responses are just echoes but must be read to clear the buffer
|
||||
ESP_LOGD(TAG, "SenseAir Starting background calibration");
|
||||
|
||||
@@ -23,7 +23,6 @@ class SenseAirComponent : public PollingComponent, public uart::UARTDevice {
|
||||
void abc_disable();
|
||||
|
||||
protected:
|
||||
uint16_t senseair_checksum_(uint8_t *ptr, uint8_t length);
|
||||
bool senseair_write_command_(const uint8_t *command, uint8_t *response, uint8_t response_length);
|
||||
|
||||
sensor::Sensor *co2_sensor_{nullptr};
|
||||
|
||||
Reference in New Issue
Block a user