Skip to content

Commit

Permalink
optimized CRC check
Browse files Browse the repository at this point in the history
  • Loading branch information
SoulKa committed Jan 15, 2024
1 parent 0ae584f commit d998c15
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions aht20/aht20.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ func (d *Dev) Sense(e *physic.Env) error {
}

// validate data
dataCrc := calculateCRC8(data[0:6])
if d.opts.ValidateData && dataCrc != data[6] {
return &DataCorruptionError{Received: data[6], Calculated: dataCrc}
if d.opts.ValidateData {
if dataCrc := calculateCRC8(data[:6]); dataCrc != data[6] {
return &DataCorruptionError{Received: data[6], Calculated: dataCrc}
}
}

// check if measurement is ready
Expand Down

0 comments on commit d998c15

Please sign in to comment.