1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-14 14:48:18 +00:00

Fixed crc function style

This commit is contained in:
Mikkonen Teemu 2019-05-23 17:55:26 +03:00
parent 7d7060f83c
commit f59b527bc8

View File

@ -14,19 +14,17 @@ static const char *TAG = "am2320";
// ---=== Calc CRC16 ===---
uint16_t crc_16(uint8_t *ptr, uint8_t length)
{
uint16_t crc = 0xFFFF;
uint8_t i;
//------------------------------
while(length--)
uint16_t crc = 0xFFFF;
uint8_t i;
//------------------------------
while (length--)
{
crc ^= *ptr++;
for (i = 0; i < 8; i++)
if ((crc & 0x01) != 0)
{
if ((crc & 0x01) != 0) {
crc >>= 1;
crc ^= 0xA001;
}
else
} else
crc >>= 1;
}
return crc;
@ -74,7 +72,6 @@ void AM2320Component::dump_config() {
float AM2320Component::get_setup_priority() const { return setup_priority::DATA; }
bool AM2320Component::read_bytes_(uint8_t a_register, uint8_t *data, uint8_t len, uint32_t conversion) {
if (!this->write_bytes(a_register, data, 2)) {
ESP_LOGW(TAG, "Writing bytes for AM2320 failed!");
return false;
@ -85,7 +82,6 @@ bool AM2320Component::read_bytes_(uint8_t a_register, uint8_t *data, uint8_t len
return this->parent_->raw_receive(this->address_, data, len);
}
bool AM2320Component::read_data_(uint8_t *data) {
// Wake up
this->write_bytes(0, data, 0);