1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-15 07:08:20 +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 ===--- // ---=== Calc CRC16 ===---
uint16_t crc_16(uint8_t *ptr, uint8_t length) uint16_t crc_16(uint8_t *ptr, uint8_t length)
{ {
uint16_t crc = 0xFFFF; uint16_t crc = 0xFFFF;
uint8_t i; uint8_t i;
//------------------------------ //------------------------------
while(length--) while (length--)
{ {
crc ^= *ptr++; crc ^= *ptr++;
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
if ((crc & 0x01) != 0) if ((crc & 0x01) != 0) {
{
crc >>= 1; crc >>= 1;
crc ^= 0xA001; crc ^= 0xA001;
} } else
else
crc >>= 1; crc >>= 1;
} }
return crc; return crc;
@ -74,7 +72,6 @@ void AM2320Component::dump_config() {
float AM2320Component::get_setup_priority() const { return setup_priority::DATA; } 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) { 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)) { if (!this->write_bytes(a_register, data, 2)) {
ESP_LOGW(TAG, "Writing bytes for AM2320 failed!"); ESP_LOGW(TAG, "Writing bytes for AM2320 failed!");
return false; 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); return this->parent_->raw_receive(this->address_, data, len);
} }
bool AM2320Component::read_data_(uint8_t *data) { bool AM2320Component::read_data_(uint8_t *data) {
// Wake up // Wake up
this->write_bytes(0, data, 0); this->write_bytes(0, data, 0);