Compare commits

...

4 commits

Author SHA1 Message Date
dherrada
899bf3898b Fixed discord invite link 2020-07-08 16:49:04 -04:00
Limor "Ladyada" Fried
88413be0f6
Merge pull request #16 from jerryneedell/jerryn_revert_pr_9
revert PR_9
2020-04-21 10:56:59 -04:00
Jerry Needell
26fcc72fe2 remove unecesary file 2020-04-20 20:11:53 -04:00
Jerry Needell
c6beb6c3ba revert PR_9 2020-04-20 19:56:42 -04:00
2 changed files with 4 additions and 19 deletions

View file

@ -6,7 +6,7 @@ Introduction
:alt: Documentation Status
.. image:: https://img.shields.io/discord/327254708534116352.svg
:target: https://discord.gg/nBQh6qu
:target: https://adafru.it/discord
:alt: Discord
.. image:: https://github.com/adafruit/Adafruit_CircuitPython_AM2320/workflows/Build%20CI/badge.svg

View file

@ -77,21 +77,6 @@ def _crc16(data):
return crc
class AM2320Exception(Exception):
"""Base class for exceptions."""
class AM2320DeviceNotFound(AM2320Exception, ValueError):
"""Indicates that a device couldn't be found."""
class AM2320ReadError(AM2320Exception, RuntimeError):
"""indicates that valid data could not be read from the sensor.
This may be due to a regular I2C read failure, or due to a checksum
mismatch."""
class AM2320:
"""A driver for the AM2320 temperature and humidity sensor.
@ -109,7 +94,7 @@ class AM2320:
except ValueError:
pass
time.sleep(0.25)
raise AM2320DeviceNotFound("AM2320 not found")
raise ValueError("AM2320 not found")
def _read_register(self, register, length):
with self._i2c as i2c:
@ -130,12 +115,12 @@ class AM2320:
# print("$%02X => %s" % (register, [hex(i) for i in result]))
# Check preamble indicates correct readings
if result[0] != 0x3 or result[1] != length:
raise AM2320ReadError("I2C read failure")
raise RuntimeError("I2C read failure")
# Check CRC on all but last 2 bytes
crc1 = struct.unpack("<H", bytes(result[-2:]))[0]
crc2 = _crc16(result[0:-2])
if crc1 != crc2:
raise AM2320ReadError("CRC failure 0x%04X vs 0x%04X" % (crc1, crc2))
raise RuntimeError("CRC failure 0x%04X vs 0x%04X" % (crc1, crc2))
return result[2:-2]
@property