Skip to content

Commit 46fa51f

Browse files
committed
added low pressure threshold
1 parent d9b1a1b commit 46fa51f

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

adafruit_lps35hw.py

+32-24
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
**Hardware:**
3535
3636
**Software and Dependencies:**
37-
3837
* Adafruit CircuitPython firmware for the supported boards:
3938
https://github.com/adafruit/circuitpython/releases
4039
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
@@ -105,19 +104,15 @@ class DataRate: # pylint: disable=too-few-public-methods
105104
RATE_50_hz = const(0x04)
106105
RATE_75_hz = const(0x05)
107106

108-
class LPS35HW:
107+
class LPS35HW: # pylint: disable=too-many-instance-attributes
109108
"""Driver for the ST LPS35HW MEMS pressure sensor
110109
111110
:param ~busio.I2C i2c_bus: The I2C bus the INA260 is connected to.
112-
:param address: The I2C device address for the sensor. Default is ``0x5d``.
111+
:param address: The I2C device address for the sensor. Default is ``0x5d`` but will accept
112+
``0x5c`` when the ``SDO`` pin is connected to Ground.
113113
114114
"""
115115

116-
117-
reset_pressure = RWBit(_INTERRUPT_CFG, 4)
118-
"""Reset ``pressure`` to be reported as the measured absolute value"""
119-
120-
121116
data_rate = RWBits(3, _CTRL_REG1, 4)
122117
"""The rate at which the sensor measures ``pressure`` and ``temperature``. ``data_rate`` should
123118
be set to one of the values of ``adafruit_lps35hw.DataRate``. Note that setting ``data_rate``
@@ -138,16 +133,17 @@ class LPS35HW:
138133
_reset = RWBit(_CTRL_REG2, 2)
139134
_one_shot = RWBit(_CTRL_REG2, 0)
140135

141-
_interrupt_active_low = RWBit(_CTRL_REG3, 7)
142-
_interrupt_open_drain = RWBit(_CTRL_REG3, 6)
143-
_int_pin_on_high = RWBit(_CTRL_REG3, 1)
144-
_int_pin_on_low = RWBit(_CTRL_REG3, 0)
136+
# registers for configuring INT pin behavior
137+
_interrupt_cfg = UnaryStruct(_CTRL_REG3, "<B") # to read all values for latching?
145138

139+
# INT status registers
146140
_interrupt_active = RWBit(_INT_SOURCE, 2)
147141
_pressure_low = RWBit(_INT_SOURCE, 1)
148142
_pressure_high = RWBit(_INT_SOURCE, 0)
149143

150144
_auto_zero = RWBit(_INTERRUPT_CFG, 5)
145+
_reset_zero = RWBit(_INTERRUPT_CFG, 4)
146+
151147
_interrupts_enabled = RWBit(_INTERRUPT_CFG, 3)
152148
_interrupt_latch = RWBit(_INTERRUPT_CFG, 2)
153149
_interrupt_low = RWBit(_INTERRUPT_CFG, 1)
@@ -158,7 +154,6 @@ class LPS35HW:
158154
_chip_id = UnaryStruct(_WHO_AM_I, "<B")
159155
_pressure_threshold = UnaryStruct(_THS_P_L, "<H")
160156

161-
# def __init__(self, i2c_bus, address=0x5c):
162157
def __init__(self, i2c_bus, address=0x5d):
163158
self.i2c_device = i2cdevice.I2CDevice(i2c_bus, address)
164159
if self._chip_id != 0xb1:
@@ -187,7 +182,6 @@ def pressure(self):
187182
@property
188183
def temperature(self):
189184
"""The current temperature measurement in degrees C"""
190-
191185
return self._raw_temperature / 100.0
192186

193187
def reset(self):
@@ -210,13 +204,14 @@ def zero_pressure(self):
210204
while self._auto_zero:
211205
pass
212206

213-
# def reset_pressure(self):
214-
# """Reset ``pressure`` to be reported as the measured absolute value"""
215-
# self._reset_zero = True
207+
def reset_pressure(self):
208+
"""Reset ``pressure`` to be reported as the measured absolute value"""
209+
self._reset_zero = True
216210

217211
@property
218212
def pressure_threshold(self):
219-
"""The high presure threshold. Use ``high_threshold_enabled`` to use it"""
213+
"""The high presure threshold. Use ``high_threshold_enabled`` or ``high_threshold_enabled``
214+
to use it"""
220215
return self._pressure_threshold / 16
221216

222217
@pressure_threshold.setter
@@ -231,15 +226,28 @@ def high_threshold_enabled(self):
231226

232227
@high_threshold_enabled.setter
233228
def high_threshold_enabled(self, value):
234-
if value:
235-
self._interrupts_enabled = True
236-
self._interrupt_high = True
237-
else:
238-
self._interrupts_enabled = False
239-
self._interrupt_high = False
229+
self._interrupts_enabled = value
230+
self._interrupt_high = value
231+
232+
@property
233+
def low_threshold_enabled(self):
234+
"""Set to `True` or `False` to enable or disable the low pressure threshold. **Note the
235+
low pressure threshold only works in relative mode**"""
236+
return self._interrupts_enabled and self._interrupt_low
237+
238+
@low_threshold_enabled.setter
239+
def low_threshold_enabled(self, value):
240+
self._interrupts_enabled = value
241+
self._interrupt_low = value
240242

241243
@property
242244
def high_threshold_exceeded(self):
243245
"""Returns `True` if the pressure high threshold has been exceeded. Must be enabled by
244246
setting ``high_threshold_enabled`` to `True` and setting a ``pressure_threshold``."""
245247
return self._pressure_high
248+
249+
@property
250+
def low_threshold_exceeded(self):
251+
"""Returns `True` if the pressure low threshold has been exceeded. Must be enabled by
252+
setting ``high_threshold_enabled`` to `True` and setting a ``pressure_threshold``."""
253+
return self._pressure_low

0 commit comments

Comments
 (0)