49
49
import adafruit_bus_device .i2c_device as i2cdevice
50
50
from adafruit_register .i2c_struct import ROUnaryStruct
51
51
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
53
53
54
54
_WHO_AM_I = const (0x0F )
55
55
56
56
_CTRL_REG1 = const (0x20 )
57
57
_CTRL_REG2 = const (0x21 )
58
58
_CTRL_REG3 = const (0x22 )
59
-
59
+ _STATUS_REG = const ( 0x27 )
60
60
# some addresses are anded to set the top bit so that multi-byte reads will work
61
61
_HUMIDITY_OUT_L = const (0x28 | 0x80 ) # Humidity output register (LSByte)
62
62
_TEMP_OUT_L = const (0x2A | 0x80 ) # Temperature output register (LSByte)
@@ -122,7 +122,7 @@ class Rate(CV):
122
122
123
123
Rate .add_values (
124
124
(
125
- ("RATE_ONE_SHOT " , 0 , 0 , None ),
125
+ ("ONE_SHOT " , 0 , 0 , None ),
126
126
("RATE_1_HZ" , 1 , 1 , None ),
127
127
("RATE_7_HZ" , 2 , 7 , None ),
128
128
("RATE_12_5_HZ" , 3 , 12.5 , None ),
@@ -145,7 +145,9 @@ class HTS221: # pylint: disable=too-many-instance-attributes
145
145
enabled = RWBit (_CTRL_REG1 , 7 )
146
146
"""Controls the power down state of the sensor. Setting to `False` will shut the sensor down"""
147
147
_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 )
149
151
_raw_temperature = ROUnaryStruct (_TEMP_OUT_L , "<h" )
150
152
_raw_humidity = ROUnaryStruct (_HUMIDITY_OUT_L , "<h" )
151
153
@@ -242,10 +244,9 @@ def temperature(self):
242
244
@property
243
245
def data_rate (self ):
244
246
"""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."""
249
250
return self ._data_rate
250
251
251
252
@data_rate .setter
@@ -254,3 +255,21 @@ def data_rate(self, value):
254
255
raise AttributeError ("data_rate must be a `Rate`" )
255
256
256
257
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