Skip to content

Commit 17f82bd

Browse files
committed
done linting and doxing
1 parent c00d072 commit 17f82bd

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

adafruit_hts221.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@
4949
import adafruit_bus_device.i2c_device as i2cdevice
5050
from adafruit_register.i2c_struct import ROUnaryStruct
5151
from adafruit_register.i2c_bits import RWBits, ROBits
52-
from adafruit_register.i2c_bit import RWBit
52+
from adafruit_register.i2c_bit import RWBit, ROBit
5353

5454
_WHO_AM_I = const(0x0F)
5555

5656
_CTRL_REG1 = const(0x20)
5757
_CTRL_REG2 = const(0x21)
5858
_CTRL_REG3 = const(0x22)
59-
59+
_STATUS_REG = const(0x27)
6060
# some addresses are anded to set the top bit so that multi-byte reads will work
6161
_HUMIDITY_OUT_L = const(0x28 | 0x80) # Humidity output register (LSByte)
6262
_TEMP_OUT_L = const(0x2A | 0x80) # Temperature output register (LSByte)
@@ -122,7 +122,7 @@ class Rate(CV):
122122

123123
Rate.add_values(
124124
(
125-
("RATE_ONE_SHOT", 0, 0, None),
125+
("ONE_SHOT", 0, 0, None),
126126
("RATE_1_HZ", 1, 1, None),
127127
("RATE_7_HZ", 2, 7, None),
128128
("RATE_12_5_HZ", 3, 12.5, None),
@@ -145,7 +145,9 @@ class HTS221: # pylint: disable=too-many-instance-attributes
145145
enabled = RWBit(_CTRL_REG1, 7)
146146
"""Controls the power down state of the sensor. Setting to `False` will shut the sensor down"""
147147
_data_rate = RWBits(2, _CTRL_REG1, 0)
148-
148+
_one_shot_bit = RWBit(_CTRL_REG2, 0)
149+
_temperature_status_bit = ROBit(_STATUS_REG, 0)
150+
_humidity_status_bit = ROBit(_STATUS_REG, 1)
149151
_raw_temperature = ROUnaryStruct(_TEMP_OUT_L, "<h")
150152
_raw_humidity = ROUnaryStruct(_HUMIDITY_OUT_L, "<h")
151153

@@ -242,10 +244,9 @@ def temperature(self):
242244
@property
243245
def data_rate(self):
244246
"""The rate at which the sensor measures ``humidity`` and ``temperature``. ``data_rate``
245-
shouldbe set to one of the values of ``adafruit_lps2x.DataRate``. Note that setting
246-
``data_rate``to ``Rate.ONE_SHOT`` places the sensor into a low-power shutdown mode where
247-
measurements toupdate ``humidity`` and ``temperature`` are only taken when
248-
``take_measurement`` is called."""
247+
should be set to one of the values of ``adafruit_hts221.Rate``. Note that setting
248+
``data_rate`` to ``Rate.ONE_SHOT`` will cause ``humidity`` and ``temperature`` measurements
249+
to only update when ``take_measurements`` is called."""
249250
return self._data_rate
250251

251252
@data_rate.setter
@@ -254,3 +255,21 @@ def data_rate(self, value):
254255
raise AttributeError("data_rate must be a `Rate`")
255256

256257
self._data_rate = value
258+
259+
@property
260+
def humidity_data_ready(self):
261+
"""Returns true if a new humidity measurement is available to be read"""
262+
return self._humidity_status_bit
263+
264+
@property
265+
def temperature_data_ready(self):
266+
"""Returns true if a new temperature measurement is available to be read"""
267+
return self._temperature_status_bit
268+
269+
270+
def take_measurements(self):
271+
"""Update the value of ``pressure`` and ``temperature`` by taking a single measurement.
272+
Only meaningful if ``data_rate`` is set to ``ONE_SHOT``"""
273+
self._one_shot_bit = True
274+
while self._one_shot_bit:
275+
pass

0 commit comments

Comments
 (0)