@@ -129,19 +129,16 @@ class Rate(CV):
129
129
)
130
130
)
131
131
132
- # def bp(val):
133
- # return format(val, "#010b")
132
+
134
133
class HTS221 : # pylint: disable=too-many-instance-attributes
135
- """Library for the ST LPS2x family of humidity sensors
134
+ """Library for the ST HTS221 Humidity and Temperature Sensor
136
135
137
136
:param ~busio.I2C i2c_bus: The I2C bus the HTS221HB is connected to.
138
- :param address: The I2C device address for the sensor. Default is ``0x5d`` but will accept
139
- ``0x5c`` when the ``SDO`` pin is connected to Ground.
140
137
141
138
"""
142
139
143
140
_chip_id = ROUnaryStruct (_WHO_AM_I , "<B" )
144
- _boot = RWBit (_CTRL_REG2 , 7 )
141
+ _boot_bit = RWBit (_CTRL_REG2 , 7 )
145
142
enabled = RWBit (_CTRL_REG1 , 7 )
146
143
"""Controls the power down state of the sensor. Setting to `False` will shut the sensor down"""
147
144
_data_rate = RWBits (2 , _CTRL_REG1 , 0 )
@@ -165,13 +162,13 @@ class HTS221: # pylint: disable=too-many-instance-attributes
165
162
_h0_t0_out = ROUnaryStruct (_H0_T0_OUT , "<h" )
166
163
_h1_t0_out = ROUnaryStruct (_H1_T1_OUT , "<h" )
167
164
168
- def __init__ (self , i2c_bus , address = _HTS221_DEFAULT_ADDRESS ):
169
- self .i2c_device = i2cdevice .I2CDevice (i2c_bus , address )
165
+ def __init__ (self , i2c_bus ):
166
+ self .i2c_device = i2cdevice .I2CDevice (i2c_bus , _HTS221_DEFAULT_ADDRESS )
170
167
if not self ._chip_id in [_HTS221_CHIP_ID ]:
171
168
raise RuntimeError (
172
169
"Failed to find HTS221HB! Found chip ID 0x%x" % self ._chip_id
173
170
)
174
- self .boot ()
171
+ self ._boot ()
175
172
self .enabled = True
176
173
self .data_rate = Rate .RATE_12_5_HZ # pylint:disable=no-member
177
174
@@ -197,16 +194,16 @@ def __init__(self, i2c_bus, address=_HTS221_DEFAULT_ADDRESS):
197
194
self .calib_hum_meas_0 = self ._h0_t0_out
198
195
self .calib_hum_meas_1 = self ._h1_t0_out
199
196
200
- def boot ( self ):
201
- """Reset the sensor, restoring all configuration registers to their defaults"""
202
- self ._boot = True
197
+ # This is the closest thing to a software reset. It re-loads the calibration values from flash
198
+ def _boot ( self ):
199
+ self ._boot_bit = True
203
200
# wait for the reset to finish
204
- while self ._boot :
201
+ while self ._boot_bit :
205
202
pass
206
203
207
204
@property
208
- def humidity (self ):
209
- """The current humidity measurement in hPa """
205
+ def relative_humidity (self ):
206
+ """The current relative humidity measurement in %rH """
210
207
calibrated_value_delta = self .calib_hum_value_1 - self .calib_hum_value_0
211
208
calibrated_measurement_delta = self .calib_hum_meas_1 - self .calib_hum_meas_0
212
209
@@ -243,10 +240,10 @@ def temperature(self):
243
240
244
241
@property
245
242
def data_rate (self ):
246
- """The rate at which the sensor measures ``humidity `` and ``temperature``. ``data_rate``
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."""
243
+ """The rate at which the sensor measures ``relative_humidity `` and ``temperature``.
244
+ ``data_rate`` should be set to one of the values of ``adafruit_hts221.Rate``. Note that
245
+ setting ``data_rate`` to ``Rate.ONE_SHOT`` will cause ``relative_humidity `` and
246
+ ``temperature`` measurements to only update when ``take_measurements`` is called."""
250
247
return self ._data_rate
251
248
252
249
@data_rate .setter
@@ -258,7 +255,7 @@ def data_rate(self, value):
258
255
259
256
@property
260
257
def humidity_data_ready (self ):
261
- """Returns true if a new humidity measurement is available to be read"""
258
+ """Returns true if a new relative humidity measurement is available to be read"""
262
259
return self ._humidity_status_bit
263
260
264
261
@property
@@ -267,8 +264,8 @@ def temperature_data_ready(self):
267
264
return self ._temperature_status_bit
268
265
269
266
def take_measurements (self ):
270
- """Update the value of ``pressure `` and ``temperature`` by taking a single measurement.
271
- Only meaningful if ``data_rate`` is set to ``ONE_SHOT``"""
267
+ """Update the value of ``relative_humidity `` and ``temperature`` by taking a single
268
+ measurement. Only meaningful if ``data_rate`` is set to ``ONE_SHOT``"""
272
269
self ._one_shot_bit = True
273
270
while self ._one_shot_bit :
274
271
pass
0 commit comments