Skip to content

Commit

Permalink
update docs, removed cruft
Browse files Browse the repository at this point in the history
  • Loading branch information
siddacious committed Jun 11, 2020
1 parent a534427 commit a5e2eba
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions adafruit_shtc3.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
# * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
# * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
* Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
"""

# imports
Expand Down Expand Up @@ -80,8 +80,9 @@
class SHTC3:
"""
A driver for the SHTC3 temperature and humidity sensor.
:param i2c_bus: The `busio.I2C` object to use. This is the only required parameter.
:param int address: (optional) The I2C address of the device.
:param ~busio.I2C i2c_bus: The `busio.I2C` object to use. This is the only required parameter.
"""

def __init__(self, i2c_bus):
Expand All @@ -90,7 +91,7 @@ def __init__(self, i2c_bus):
self._buffer = bytearray(6)
self.low_power = False
self.reset()
self.sleep = False
self.sleeping = False
if self._chip_id & 0x083F != _SHTC3_CHIP_ID:
raise RuntimeError("Failed to find an ICM20X sensor - check your wiring!")

Expand Down Expand Up @@ -124,12 +125,12 @@ def reset(self):
time.sleep(0.001)

@property
def sleep(self):
def sleeping(self):
"""Determines the sleep state of the sensor"""
return self._cached_sleep

@sleep.setter
def sleep(self, sleep_enabled):
@sleeping.setter
def sleeping(self, sleep_enabled):
if sleep_enabled:
self._write_command(_SHTC3_SLEEP)
else:
Expand All @@ -150,19 +151,19 @@ def low_power(self, low_power_enabled):

@property
def relative_humidity(self):
"""Current relative humidity in % rH"""
"""The current relative humidity in % rH"""
return self.measurements[1]

@property
def temperature(self):
"""Current temperature in degrees celcius"""
"""The current temperature in degrees celcius"""
return self.measurements[0]

@property
def measurements(self):
"""both `temperature` and `relative_humidity`, read simultaneously"""

self.sleep = False
self.sleeping = False
temperature = None
humidity = None
# send correct command for the current power state
Expand Down Expand Up @@ -193,16 +194,16 @@ def measurements(self):
# decode data into human values:
# convert bytes into 16-bit signed integer
# convert the LSB value to a human value according to the datasheet
raw_temp = unpack_from(">h", temp_data)
raw_temp = unpack_from(">h", temp_data)[0]
raw_temp = ((4375 * raw_temp) >> 14) - 4500
temperature = raw_temp / 100.0

# repeat above steps for humidity data
raw_humidity = unpack_from(">h", humidity_data)
raw_humidity = unpack_from(">h", humidity_data)[0]
raw_humidity = (625 * raw_humidity) >> 12
humidity = raw_humidity / 100.0

self.sleep = True
self.sleeping = True
return (temperature, humidity)

## CRC-8 formula from page 14 of SHTC3 datasheet
Expand All @@ -211,7 +212,6 @@ def measurements(self):

@staticmethod
def _crc8(buffer):
print("\t\tbuff", [hex(i) for i in buffer])
crc = 0xFF
for byte in buffer:
crc ^= byte
Expand All @@ -220,5 +220,4 @@ def _crc8(buffer):
crc = (crc << 1) ^ 0x31
else:
crc = crc << 1
print("\t\tcrc:", hex(crc & 0xFF))
return crc & 0xFF # return the bottom 8 bits

0 comments on commit a5e2eba

Please # to comment.