From 337cf2a45694856fa0bbd8d54fa5315b6817b81b Mon Sep 17 00:00:00 2001 From: Stefan Brand Date: Sun, 2 May 2021 16:42:07 +0200 Subject: [PATCH] Fix Adding all 3 PMx Values to the Payload --- lib/HM330x/HM330x.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/HM330x/HM330x.cpp b/lib/HM330x/HM330x.cpp index 9307e2f..0dadf6d 100644 --- a/lib/HM330x/HM330x.cpp +++ b/lib/HM330x/HM330x.cpp @@ -62,7 +62,7 @@ uint8_t HM330x::getSensorData(char *payload, uint8_t startbyte) { if (calcSum(data) == data[HM330x_DATA_LEN-1]) { for (uint8_t pos = 5; pos<8; pos++) { - value = bytesToUint16(data, 5); + value = bytesToUint16(data, pos); uint16ToPayload(value, payload, startbyte); startbyte += 2; } @@ -79,13 +79,13 @@ bool HM330x::sendCmd(uint8_t cmd) { return Wire.endTransmission(); } -// Calculate CRC8 +// Calculate the CheckSum uint8_t HM330x::calcSum(uint8_t bytes[]) { - uint8_t crc8 = 0; + uint8_t checksum = 0; for (int i = 0; i < HM330x_DATA_LEN - 1; i++) { - crc8 += bytes[i]; + checksum += bytes[i]; } - return crc8; + return checksum; } // Get Value from Sensor Bytes Array