Skip to content

Commit 851300b

Browse files
committed
drivers: Make status() private across all sensor drivers.
1 parent 1c64832 commit 851300b

15 files changed

Lines changed: 37 additions & 50 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ lib/<component>/
475475
- **Device identification**: `device_id()` — returns the device/WHO_AM_I register value. All I2C drivers with an ID register must implement this method.
476476
- **Reset methods**: `reset()` for hardware reset (pin toggle), `soft_reset()` for software reset (register write), `reboot()` for memory reboot (reload trimming).
477477
- **Power methods**: `power_on()` / `power_off()`. All drivers must implement both.
478-
- **Status methods**: `status()` returns the raw status register as an int, `data_ready()` returns True when all channels have new data, `<measurement>_ready()` for per-channel readiness (e.g. `temperature_ready()`, `pressure_ready()`).
478+
- **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

480480
### Linting
481481

lib/apds9960/apds9960/device.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(self, i2c, address=APDS9960_I2C_ADDR, valid_id=APDS9960_DEV_ID):
8282
def device_id(self):
8383
return self.dev_id
8484

85-
def status(self):
85+
def _status(self):
8686
return self._read_reg(APDS9960_REG_STATUS)
8787

8888
def data_ready(self):
@@ -230,18 +230,11 @@ def power_off(self):
230230
# ambient light and color sensor controls
231231
# *******************************************************************************
232232

233-
# check if there is new light data available
234233
def light_ready(self):
235-
val = self._read_reg(APDS9960_REG_STATUS)
236-
237-
# mask out AVALID bit
238-
val &= APDS9960_BIT_AVALID
239-
240-
return val == APDS9960_BIT_AVALID
234+
return bool(self._status() & APDS9960_BIT_AVALID)
241235

242236
def proximity_ready(self):
243-
val = self._read_reg(APDS9960_REG_STATUS)
244-
return (val & APDS9960_BIT_PVALID) == APDS9960_BIT_PVALID
237+
return bool(self._status() & APDS9960_BIT_PVALID)
245238

246239
def _ensure_light_enabled(self):
247240
enable = self.get_mode()

lib/hts221/hts221/device.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ def device_id(self):
6161
return self._read_reg(HTS221_WHO_AM_I)
6262

6363
# get STATUS register
64-
def status(self):
64+
def _status(self):
6565
return self._read_reg(HTS221_STATUS_REG)
6666

6767
def data_ready(self):
68-
s = self.status()
68+
s = self._status()
6969
return bool((s & HTS221_STATUS_T_DA) and (s & HTS221_STATUS_H_DA))
7070

7171
def temperature_ready(self):
72-
return bool(self.status() & HTS221_STATUS_T_DA)
72+
return bool(self._status() & HTS221_STATUS_T_DA)
7373

7474
def humidity_ready(self):
75-
return bool(self.status() & HTS221_STATUS_H_DA)
75+
return bool(self._status() & HTS221_STATUS_H_DA)
7676

7777
# power control
7878
def power_off(self):

lib/ism330dl/ism330dl/device.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,20 +251,20 @@ def motion(self):
251251
# Status
252252
# --------------------------------------------------
253253

254-
def status(self):
254+
def _status(self):
255255
return self._read_u8(REG_STATUS_REG)
256256

257257
def accel_ready(self):
258-
return bool(self.status() & STATUS_XLDA)
258+
return bool(self._status() & STATUS_XLDA)
259259

260260
def gyro_ready(self):
261-
return bool(self.status() & STATUS_GDA)
261+
return bool(self._status() & STATUS_GDA)
262262

263263
def temperature_ready(self):
264-
return bool(self.status() & STATUS_TDA)
264+
return bool(self._status() & STATUS_TDA)
265265

266266
def data_ready(self):
267-
s = self._read_u8(REG_STATUS_REG)
267+
s = self._status()
268268
return bool((s & STATUS_XLDA) and (s & STATUS_GDA) and (s & STATUS_TDA))
269269

270270
# --------------------------------------------------

lib/lis2mdl/examples/magnet_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def test_reads(dev):
239239
ok &= who == 0x40
240240

241241
# STATUS & DATA READY
242-
st1 = dev.status()
242+
st1 = dev.data_ready()
243243
print(f"Initial STATUS=0x{st1:02X}")
244244
# wait a few ms to let a new frame arrive
245245
sleep_ms(50)

lib/lis2mdl/lis2mdl/device.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ def read_magnet_raw(self):
182182
"""Reads the raw magnetic field (LSB). Same as read_magnet(), but more explicit."""
183183
return self.read_magnet() # (x,y,z) int16 LSB
184184

185-
def status(self) -> int:
185+
def _status(self) -> int:
186186
"""Reads STATUS_REG (0x67)."""
187187
return self._read_reg(LIS2MDL_STATUS_REG)
188188

189189
def data_ready(self) -> bool:
190190
"""True if a new XYZ triplet is ready (Zyxda bit)."""
191-
return bool(self.status() & (1 << 3))
191+
return bool(self._status() & (1 << 3))
192192

193193
def read_int_source(self) -> int:
194194
"""Reads INT_SOURCE_REG (0x64): source of the interrupt."""
@@ -331,7 +331,7 @@ def read_all(self) -> dict:
331331
mag_ut = self.read_magnet_uT()
332332
cal = self.read_magnet_calibrated_norm()
333333
temp = self.read_temperature_c()
334-
st = self.status()
334+
st = self._status()
335335
return {"raw": raw, "uT": mag_ut, "cal_norm": cal, "tempC": temp, "status": st}
336336

337337
##

lib/wsen-hids/examples/full_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def test_one_shot(sensor):
143143
try:
144144
humidity_rh, temperature_c = sensor.read_one_shot(timeout_ms=500)
145145

146-
status = sensor.status()
146+
status = sensor.data_ready()
147147
h_ready = sensor.humidity_ready()
148148
t_ready = sensor.temperature_ready()
149149
ready = sensor.data_ready()
@@ -241,7 +241,7 @@ def test_continuous_mode(sensor, odr, label, wait_ms=1500, loops=5, delay_s=0.5)
241241

242242
for i in range(loops):
243243
humidity_rh, temperature_c = sensor.read()
244-
status = sensor.status()
244+
status = sensor.data_ready()
245245

246246
print(
247247
"#{:d} H={:.2f} %RH T={:.2f} °C STATUS=0x{:02X}".format(
@@ -290,7 +290,7 @@ def test_status_helpers(sensor):
290290
sensor.set_continuous_mode(odr=ODR_1_HZ)
291291
sleep(1.5)
292292

293-
status = sensor.status()
293+
status = sensor.data_ready()
294294
h_avail = sensor.humidity_ready()
295295
t_avail = sensor.temperature_ready()
296296
ready = sensor.data_ready()

lib/wsen-hids/wsen_hids/device.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,17 @@ def reboot(self):
215215
# Status
216216
# -------------------------------------------------------------------------
217217

218-
def status(self):
218+
def _status(self):
219219
return self._read_reg(REG_STATUS)
220220

221221
def humidity_ready(self):
222-
return bool(self.status() & STATUS_H_DA)
222+
return bool(self._status() & STATUS_H_DA)
223223

224224
def temperature_ready(self):
225-
return bool(self.status() & STATUS_T_DA)
225+
return bool(self._status() & STATUS_T_DA)
226226

227227
def data_ready(self):
228-
status = self.status()
228+
status = self._status()
229229
return bool((status & STATUS_H_DA) and (status & STATUS_T_DA))
230230

231231
# -------------------------------------------------------------------------

lib/wsen-pads/examples/test.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ def print_fail(name, err=None):
3131
def dump_registers(sensor):
3232
ctrl1 = sensor._read_u8(REG_CTRL_1)
3333
ctrl2 = sensor._read_u8(REG_CTRL_2)
34-
status = sensor._read_u8(REG_STATUS)
3534
int_source = sensor._read_u8(REG_INT_SOURCE)
3635

3736
print("CTRL_1 = 0x{:02X}".format(ctrl1))
3837
print("CTRL_2 = 0x{:02X}".format(ctrl2))
39-
print("STATUS = 0x{:02X}".format(status))
38+
print("data_ready() =", sensor.data_ready())
4039
print("INT_SOURCE = 0x{:02X}".format(int_source))
4140

4241

@@ -136,13 +135,12 @@ def test_one_shot(sensor):
136135

137136
raw_p = sensor.pressure_raw()
138137
raw_t = sensor.temperature_raw()
139-
status = sensor.status()
140138

141139
print("Raw pressure :", raw_p)
142140
print("Raw temperature :", raw_t)
143141
print("Pressure : {:.2f} hPa".format(pressure_hpa))
144142
print("Temperature : {:.2f} °C".format(temperature_c))
145-
print("STATUS : 0x{:02X}".format(status))
143+
print("data_ready() :", sensor.data_ready())
146144

147145
# Basic sanity checks
148146
MIN_PRESSURE = 260.0
@@ -190,16 +188,14 @@ def test_continuous_mode(sensor, odr, label, wait_s=2):
190188
temperature_c = sensor.temperature()
191189
raw_p = sensor.pressure_raw()
192190
raw_t = sensor.temperature_raw()
193-
status = sensor.status()
194-
195191
print(
196-
"#{:d} P={:.2f} hPa T={:.2f} °C rawP={} rawT={} STATUS=0x{:02X}".format(
192+
"#{:d} P={:.2f} hPa T={:.2f} °C rawP={} rawT={} ready={}".format(
197193
i + 1,
198194
pressure_hpa,
199195
temperature_c,
200196
raw_p,
201197
raw_t,
202-
status,
198+
sensor.data_ready(),
203199
)
204200
)
205201

@@ -229,12 +225,10 @@ def test_status_flags(sensor):
229225
sensor.set_continuous(odr=ODR_1_HZ)
230226
sleep(1.5)
231227

232-
status = sensor.status()
233228
p_avail = sensor.pressure_ready()
234229
t_avail = sensor.temperature_ready()
235230
ready = sensor.data_ready()
236231

237-
print("STATUS = 0x{:02X}".format(status))
238232
print("pressure_ready() =", p_avail)
239233
print("temperature_ready() =", t_avail)
240234
print("data_ready() =", ready)

lib/wsen-pads/wsen_pads/device.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,25 +155,25 @@ def device_id(self):
155155
"""Return the value of the DEVICE_ID register."""
156156
return self._read_reg(REG_DEVICE_ID)
157157

158-
def status(self):
158+
def _status(self):
159159
"""Return the raw STATUS register value."""
160160
return self._read_reg(REG_STATUS)
161161

162162
def pressure_ready(self):
163163
"""Return True when new pressure data is available."""
164-
return bool(self.status() & STATUS_P_DA)
164+
return bool(self._status() & STATUS_P_DA)
165165

166166
def temperature_ready(self):
167167
"""Return True when new temperature data is available."""
168-
return bool(self.status() & STATUS_T_DA)
168+
return bool(self._status() & STATUS_T_DA)
169169

170170
def data_ready(self):
171171
"""
172172
Return True when both pressure and temperature data are available.
173173
174174
This is mainly useful in continuous mode.
175175
"""
176-
status = self.status()
176+
status = self._status()
177177
return bool((status & STATUS_P_DA) and (status & STATUS_T_DA))
178178

179179
# ---------------------------------------------------------------------

0 commit comments

Comments
 (0)