Skip to content

Commit 4799013

Browse files
committed
wsen-pads: Adress review comments.
1 parent 5098385 commit 4799013

4 files changed

Lines changed: 18 additions & 9 deletions

File tree

lib/wsen-pads/examples/altitude.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from wsen_pads import WSEN_PADS
44

55
SEA_LEVEL_PRESSURE = 1013.25 # depends on your location, you can adjust it for better altitude estimation
6-
EXPONENT = 0.1903 # standard atmosphere exponent for altitude calculation
6+
# International Standard Atmosphere exponent: 1 / 5.255
7+
EXPONENT = 1.0 / 5.255
78

89
i2c = I2C(1)
910

lib/wsen-pads/examples/basic_reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from machine import I2C, Pin
1+
from machine import I2C
22
from time import sleep
33
from wsen_pads import WSEN_PADS
44

lib/wsen-pads/examples/test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
REG_CTRL_2,
99
REG_STATUS,
1010
REG_INT_SOURCE,
11+
CTRL1_BDU,
12+
CTRL2_IF_ADD_INC
1113
)
1214

1315
def print_header(title):
@@ -74,10 +76,10 @@ def test_default_registers(sensor):
7476
ctrl2 = sensor._read_u8(REG_CTRL_2)
7577

7678
# BDU should be enabled by the driver
77-
bdu_ok = bool(ctrl1 & 0x02)
79+
bdu_ok = bool(ctrl1 & CTRL1_BDU)
7880

7981
# IF_ADD_INC should be enabled by the driver
80-
if_add_inc_ok = bool(ctrl2 & 0x10)
82+
if_add_inc_ok = bool(ctrl2 & CTRL2_IF_ADD_INC)
8183

8284
if bdu_ok:
8385
print_pass("BDU enabled")

lib/wsen-pads/wsen_pads/device.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from utime import sleep_ms, ticks_ms, ticks_diff
1+
from time import sleep_ms, ticks_ms, ticks_diff
22

33
from wsen_pads.const import *
44
from wsen_pads.exceptions import *
@@ -54,7 +54,8 @@ def __init__(self, i2c, address=WSEN_PADS_I2C_DEFAULT_ADDR):
5454
def _is_present(self):
5555
"""Return True if the device address is visible on the I2C bus."""
5656
try:
57-
return self.address in self.i2c.scan()
57+
self.i2c.readfrom(self.address, 1)
58+
return True
5859
except Exception:
5960
return False
6061

@@ -254,14 +255,19 @@ def temperature(self):
254255
"""
255256
return self.temperature_raw() * TEMPERATURE_C_PER_DIGIT
256257

257-
def read(self):
258+
def read(self, low_noise=False):
258259
"""
259260
Read and return both pressure and temperature.
261+
Has to be used in one-shot mode. Continuous mode must be disabled first.
260262
261263
Returns:
262264
tuple: (pressure_hpa, temperature_c)
263265
"""
264-
self.trigger_one_shot()
266+
if continuous_mode := (self._read_u8(REG_CTRL_1) & CTRL1_ODR_MASK) != 0:
267+
raise WSENPADSInvalidMode(
268+
"read() cannot be used in continuous mode. Please call power_down() first."
269+
)
270+
self.trigger_one_shot(low_noise=low_noise)
265271
return self.pressure(), self.temperature()
266272

267273
# ---------------------------------------------------------------------
@@ -302,7 +308,7 @@ def read_one_shot(self, low_noise=False):
302308
Returns:
303309
tuple: (pressure_hpa, temperature_c)
304310
"""
305-
return self.read()
311+
return self.read(low_noise=low_noise)
306312

307313
# ---------------------------------------------------------------------
308314
# Continuous mode

0 commit comments

Comments
 (0)