Skip to content

Commit 36c7fca

Browse files
committed
adding_sea_level_pressure_property
1 parent ef9555e commit 36c7fca

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

README.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Introduction
1313
:target: https://github.com/adafruit/Adafruit_CircuitPython_DPS310/actions
1414
:alt: Build Status
1515

16+
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
17+
:target: https://github.com/psf/black
18+
:alt: Code Style: Black
19+
1620
Library for the DPS310 Precision Barometric Pressure Sensor
1721

1822

@@ -72,14 +76,14 @@ Usage Example
7276
print("")
7377
time.sleep(1.0)
7478
75-
Caveat: by default the library initializes the IC with constant temperature and pressure measurements at 64Hz with 64 samples. It is not possible to change the IC's mode, temperature_oversample_count or pressure_oversample_count on-the-fly so resetting the IC and operation parameteres is required. For instance, to set the mode to continuous pressure measurement at 1Hz with 2 samples:
76-
7779
7880
Known Issues
7981
============
80-
Library extensive features might not be compatible with memory limited boards.
82+
Library extensive features might not be compatible with memory limited boards. For these kind of
83+
boards you need to use the ``adafruit_dps310/basic.mpy``, the file needs to be in the ``mpy``
84+
format in order to fit in memory.
8185
For boards with more memory available you could use the code present
82-
in ``adafruit_dps310/dps310_advanced.py``. For usage refer to ``dps310_simpletest_advanced.py``
86+
in ``adafruit_dps310/advanced.py``. For usage refer to ``dps310_simpletest_advanced.py``
8387

8488

8589
Contributing

adafruit_dps310/advanced.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,17 @@ class SampleCount(CV):
146146
# pylint: enable=unnecessary-pass
147147

148148
_DPS310_DEFAULT_ADDRESS = const(0x77) # DPS310 default i2c address
149-
#_DPS310_DEVICE_ID = const(0x10) # DPS310 device identifier
149+
# _DPS310_DEVICE_ID = const(0x10) # DPS310 device identifier
150150

151-
#_DPS310_PRSB2 = const(0x00) # Highest byte of pressure data
152-
#_DPS310_TMPB2 = const(0x03) # Highest byte of temperature data
151+
# _DPS310_PRSB2 = const(0x00) # Highest byte of pressure data
152+
# _DPS310_TMPB2 = const(0x03) # Highest byte of temperature data
153153
_DPS310_PRSCFG = const(0x06) # Pressure configuration
154154
_DPS310_TMPCFG = const(0x07) # Temperature configuration
155-
#_DPS310_MEASCFG = const(0x08) # Sensor configuration
156-
#_DPS310_CFGREG = const(0x09) # Interrupt/FIFO configuration
157-
#_DPS310_RESET = const(0x0C) # Soft reset
158-
#_DPS310_PRODREVID = const(0x0D) # Register that contains the part ID
159-
#_DPS310_TMPCOEFSRCE = const(0x28) # Temperature calibration src
155+
# _DPS310_MEASCFG = const(0x08) # Sensor configuration
156+
# _DPS310_CFGREG = const(0x09) # Interrupt/FIFO configuration
157+
# _DPS310_RESET = const(0x0C) # Soft reset
158+
# _DPS310_PRODREVID = const(0x0D) # Register that contains the part ID
159+
# _DPS310_TMPCOEFSRCE = const(0x28) # Temperature calibration src
160160

161161

162162
class DPS310_Advanced(DPS310):
@@ -199,7 +199,6 @@ class DPS310_Advanced(DPS310):
199199
def __init__(self, i2c_bus, address=_DPS310_DEFAULT_ADDRESS):
200200
super().__init__(i2c_bus, _DPS310_DEFAULT_ADDRESS)
201201

202-
203202
def initialize(self):
204203
"""Initialize the sensor to continuous measurement"""
205204

adafruit_dps310/basic.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ def __init__(self, i2c_bus, address=_DPS310_DEFAULT_ADDRESS):
146146
1040384,
147147
2088960,
148148
)
149-
self.sea_level_pressure = 1013.25
150-
"""Pressure in hectoPascals at sea level. Used to calibrate :attr:`altitude`."""
149+
self._sea_level_pressure = 1013.25
150+
151151
self.initialize()
152152

153153
def initialize(self):
@@ -223,7 +223,9 @@ def pressure(self):
223223
def altitude(self):
224224
"""The altitude based on the sea level pressure (:attr:`sea_level_pressure`) -
225225
which you must enter ahead of time)"""
226-
return 44330 * (1.0 - math.pow(self.pressure / self.sea_level_pressure, 0.1903))
226+
return 44330 * (
227+
1.0 - math.pow(self.pressure / self._sea_level_pressure, 0.1903)
228+
)
227229

228230
@property
229231
def temperature(self):
@@ -232,6 +234,17 @@ def temperature(self):
232234
_temperature = _scaled_rawtemp * self._c1 + self._c0 / 2.0
233235
return _temperature
234236

237+
@property
238+
def sea_level_pressure(self):
239+
"""The local sea level pressure in hectoPascals (aka millibars). This is used
240+
for calculation of :attr:`altitude`. Values are typically in the range
241+
980 - 1030."""
242+
return self._sea_level_pressure
243+
244+
@sea_level_pressure.setter
245+
def sea_level_pressure(self, value):
246+
self._sea_level_pressure = value
247+
235248
def wait_temperature_ready(self):
236249
"""Wait until a temperature measurement is available."""
237250

docs/conf.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
# Uncomment the below if you use native CircuitPython modules such as
2626
# digitalio, micropython and busio. List the modules you use. Without it, the
2727
# autodoc module docs will fail to generate with a warning.
28-
autodoc_mock_imports = ["adafruit_register", "adafruit_bus_device"]
28+
autodoc_mock_imports = [
29+
"adafruit_register",
30+
"adafruit_bus_device",
31+
"micropython",
32+
]
2933

3034

3135
intersphinx_mapping = {

0 commit comments

Comments
 (0)