fix out of range problem and write doc

pull/112/head
Voroshilin Andrey 5 months ago
parent 226f28bde0
commit 7a6479a6d0

@ -104,10 +104,12 @@ func (d *Dev) Read() (physic.Env, error) {
} }
// Verify checksum // Verify checksum
if len(data) >= 5{
checksum := data[0] + data[1] + data[2] + data[3] checksum := data[0] + data[1] + data[2] + data[3]
if data[4] != checksum { if data[4] != checksum {
return physic.Env{}, errors.New("dht22: checksum error") return physic.Env{}, errors.New("dht22: checksum error")
} }
}
// Parse data (big-endian) // Parse data (big-endian)
humidityInt := uint16(data[0])<<8 | uint16(data[1]) humidityInt := uint16(data[0])<<8 | uint16(data[1])

@ -0,0 +1,15 @@
// Copyright 2016 The Periph Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
//package dht22 is a driver for dht22/am2302 temperature and humidity sensor
//
//to start use function: "New"
//
//to read data from use function: "Read"
//or u can read data continiusly from chanale whate create by function: "SenseContinuous"
//
//datasheet:
//https://cdn-shop.adafruit.com/datasheets/Digital+humidity+and+temperature+sensor+AM2302.pdf
package dht22
Loading…
Cancel
Save