Skip to content

Commit e434a59

Browse files
committed
drivers: Standardize continuous and one-shot mode method naming.
1 parent cc0dee0 commit e434a59

6 files changed

Lines changed: 27 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ lib/<component>/
477477
- **Power methods**: `power_on()` / `power_off()`. All drivers must implement both.
478478
- **Status methods**: `_status()` returns the raw status register as an int (private), `data_ready()` returns True when all channels have new data, `<measurement>_ready()` for per-channel readiness (e.g. `temperature_ready()`, `pressure_ready()`).
479479
- **Measurement methods**: bare noun without unit suffix only for `temperature()` (°C) and `humidity()` (%RH). All others include the unit: `pressure_hpa()`, `distance_mm()`, `voltage_mv()`, `acceleration_g()`, etc. `read()` for combined reading returning a tuple, `<measurement>_raw()` for raw register values.
480+
- **Mode methods**: `set_continuous(odr)` to start continuous measurements, `trigger_one_shot()` for a single conversion, `read_one_shot()` for trigger + wait + return data.
480481

481482
### Linting
482483

lib/hts221/hts221/device.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ def set_odr(self, odr=0):
9191
t = self._read_reg(HTS221_CTRL_REG1) & 0xFC
9292
self._write_reg(HTS221_CTRL_REG1, t | odr)
9393

94+
def set_continuous(self, odr=1):
95+
self.power_on()
96+
self.set_odr(odr)
97+
9498
# get/set Humidity and temperature average configuration
9599
def get_av(self):
96100
return self._read_reg(HTS221_AV_CONF)
@@ -117,6 +121,10 @@ def trigger_one_shot(self):
117121
self._write_reg(HTS221_CTRL_REG2, ctrl2 | HTS221_CTRL2_ONE_SHOT)
118122
sleep_ms(15)
119123

124+
def read_one_shot(self):
125+
self.trigger_one_shot()
126+
return self.read()
127+
120128
def reboot(self):
121129
ctrl2 = self._read_reg(HTS221_CTRL_REG2)
122130
self._write_reg(HTS221_CTRL_REG2, ctrl2 | HTS221_CTRL2_BOOT)

lib/lis2mdl/lis2mdl/device.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ def set_odr(self, hz: int):
7676
reg = (reg & ~(0b11 << 2)) | (odr_bits << 2)
7777
self._write_reg(LIS2MDL_CFG_REG_A, reg)
7878

79+
def set_continuous(self, hz=10):
80+
self.set_odr(hz)
81+
self.set_mode("continuous")
82+
83+
def trigger_one_shot(self):
84+
self.set_mode("single")
85+
86+
def read_one_shot(self):
87+
self.trigger_one_shot()
88+
return self.magnetic_field()
89+
7990
def set_low_power(self, enabled: bool):
8091
# LP bit (bit4) : 0=High-Res, 1=Low-Power
8192
reg = self._read_reg(LIS2MDL_CFG_REG_A)

lib/wsen-hids/examples/continuous_mode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
sensor = WSEN_HIDS(i2c)
99

10-
sensor.set_continuous_mode(WSEN_HIDS.ODR_1_HZ)
10+
sensor.set_continuous(WSEN_HIDS.ODR_1_HZ)
1111

1212
for _ in range(10):
1313
humidity, temperature = sensor.read()

lib/wsen-hids/examples/full_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,13 @@ def test_continuous_mode(sensor, odr, label, wait_ms=1500, loops=5, delay_s=0.5)
211211
print_header("7) Continuous mode - {}".format(label))
212212

213213
try:
214-
sensor.set_continuous_mode(odr=odr)
214+
sensor.set_continuous(odr=odr)
215215

216216
ctrl1 = read_reg(sensor, REG_CTRL_1)
217217
pd_ok = bool(ctrl1 & CTRL_1_PD)
218218
odr_ok = (ctrl1 & CTRL_1_ODR_MASK) == odr
219219

220-
print("CTRL_1 after set_continuous_mode = 0x{:02X}".format(ctrl1))
220+
print("CTRL_1 after set_continuous = 0x{:02X}".format(ctrl1))
221221

222222
if pd_ok:
223223
print_pass("PD bit set")
@@ -283,7 +283,7 @@ def test_status_helpers(sensor):
283283
print_header("8) STATUS helpers")
284284

285285
try:
286-
sensor.set_continuous_mode(odr=ODR_1_HZ)
286+
sensor.set_continuous(odr=ODR_1_HZ)
287287
sleep(1.5)
288288

289289
h_avail = sensor.humidity_ready()
@@ -312,7 +312,7 @@ def test_unitary_methods(sensor):
312312
print_header("9) humidity() and temperature()")
313313

314314
try:
315-
sensor.set_continuous_mode(odr=ODR_1_HZ)
315+
sensor.set_continuous(odr=ODR_1_HZ)
316316
sleep(1.2)
317317

318318
humidity_rh = sensor.humidity()

lib/wsen-hids/wsen_hids/device.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class WSEN_HIDS(object):
1818
- humidity()
1919
- temperature()
2020
- read_one_shot()
21-
- set_continuous_mode()
21+
- set_continuous()
2222
- set_one_shot_mode()
2323
- enable_bdu()
2424
- enable_heater()
@@ -182,7 +182,7 @@ def set_one_shot_mode(self):
182182
ctrl1 &= ~CTRL_1_ODR_MASK # ODR = 00 => one-shot
183183
self._write_reg(REG_CTRL_1, ctrl1)
184184

185-
def set_continuous_mode(self, odr=ODR_1_HZ):
185+
def set_continuous(self, odr=ODR_1_HZ):
186186
if odr not in (ODR_1_HZ, ODR_7_HZ, ODR_12_5_HZ):
187187
raise ValueError("Invalid ODR for continuous mode")
188188

0 commit comments

Comments
 (0)