Skip to content

Commit 97f74f3

Browse files
committed
humidity->relative_humidity, fixing typos
1 parent b959cdd commit 97f74f3

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

adafruit_hts221.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,16 @@ class Rate(CV):
129129
)
130130
)
131131

132-
# def bp(val):
133-
# return format(val, "#010b")
132+
134133
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
136135
137136
: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.
140137
141138
"""
142139

143140
_chip_id = ROUnaryStruct(_WHO_AM_I, "<B")
144-
_boot = RWBit(_CTRL_REG2, 7)
141+
_boot_bit = RWBit(_CTRL_REG2, 7)
145142
enabled = RWBit(_CTRL_REG1, 7)
146143
"""Controls the power down state of the sensor. Setting to `False` will shut the sensor down"""
147144
_data_rate = RWBits(2, _CTRL_REG1, 0)
@@ -165,13 +162,13 @@ class HTS221: # pylint: disable=too-many-instance-attributes
165162
_h0_t0_out = ROUnaryStruct(_H0_T0_OUT, "<h")
166163
_h1_t0_out = ROUnaryStruct(_H1_T1_OUT, "<h")
167164

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)
170167
if not self._chip_id in [_HTS221_CHIP_ID]:
171168
raise RuntimeError(
172169
"Failed to find HTS221HB! Found chip ID 0x%x" % self._chip_id
173170
)
174-
self.boot()
171+
self._boot()
175172
self.enabled = True
176173
self.data_rate = Rate.RATE_12_5_HZ # pylint:disable=no-member
177174

@@ -197,16 +194,16 @@ def __init__(self, i2c_bus, address=_HTS221_DEFAULT_ADDRESS):
197194
self.calib_hum_meas_0 = self._h0_t0_out
198195
self.calib_hum_meas_1 = self._h1_t0_out
199196

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
203200
# wait for the reset to finish
204-
while self._boot:
201+
while self._boot_bit:
205202
pass
206203

207204
@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"""
210207
calibrated_value_delta = self.calib_hum_value_1 - self.calib_hum_value_0
211208
calibrated_measurement_delta = self.calib_hum_meas_1 - self.calib_hum_meas_0
212209

@@ -243,10 +240,10 @@ def temperature(self):
243240

244241
@property
245242
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."""
250247
return self._data_rate
251248

252249
@data_rate.setter
@@ -258,7 +255,7 @@ def data_rate(self, value):
258255

259256
@property
260257
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"""
262259
return self._humidity_status_bit
263260

264261
@property
@@ -267,8 +264,8 @@ def temperature_data_ready(self):
267264
return self._temperature_status_bit
268265

269266
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``"""
272269
self._one_shot_bit = True
273270
while self._one_shot_bit:
274271
pass

examples/hts221_simpletest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
i2c = busio.I2C(board.SCL, board.SDA)
77
hts = adafruit_hts221.HTS221(i2c)
88
while True:
9-
print("Humidity: %.2f percent rH" % hts.humidity)
9+
print("Relative Humidity: %.2f %% rH" % hts.relative_humidity)
1010
print("Temperature: %.2f C" % hts.temperature)
11+
print("")
1112
time.sleep(1)

0 commit comments

Comments
 (0)