Skip to content

Commit be4f22e

Browse files
committed
drivers: Standardize read and measurement method naming.
1 parent 6da03de commit be4f22e

22 files changed

Lines changed: 99 additions & 99 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ bq = BQ27441(i2c)
8484

8585
# Reading battery information
8686
bq.state_of_charge() # State of charge in %
87-
bq.voltage() # Voltage in mV
87+
bq.voltage_mv() # Voltage in mV
8888
bq.current_average() # Average current discharge in mA
8989
bq.capacity_full() # Full capacity in mAh
9090
bq.capacity_remaining() # Remaining capacity in mAh
@@ -250,7 +250,7 @@ i2c = machine.I2C(1)
250250
apds = APDS9960(i2c)
251251

252252
apds.enable_light_sensor()
253-
light = apds.read_ambient_light()
253+
light = apds.ambient_light()
254254

255255
```
256256

@@ -327,7 +327,7 @@ i2c = machine.I2C(1)
327327
pads = WSEN_PADS(i2c)
328328

329329
# Reading values
330-
pressure = pads.pressure() # Pressure in hPa
330+
pressure = pads.pressure_hpa() # Pressure in hPa
331331
temperature = pads.temperature() # Temperature in °C
332332
```
333333

@@ -476,6 +476,7 @@ lib/<component>/
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.
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()`).
479+
- **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.
479480

480481
### Linting
481482

lib/apds9960/apds9960/device.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def is_gesture_available(self):
169169
return val == APDS9960_BIT_GVALID
170170

171171
# processes a gesture event and returns best guessed gesture
172-
def read_gesture(self):
172+
def gesture(self):
173173
fifo_level = 0
174174
fifo_data = []
175175

@@ -258,7 +258,7 @@ def _ensure_proximity_enabled(self):
258258
raise OSError("APDS9960 proximity data ready timeout")
259259

260260
# reads the ambient (clear) light level as a 16-bit value
261-
def read_ambient_light(self):
261+
def ambient_light(self):
262262
self._ensure_light_enabled()
263263
# read value from clear channel, low byte register
264264
low = self._read_reg(APDS9960_REG_CDATAL)
@@ -269,7 +269,7 @@ def read_ambient_light(self):
269269
return low + (high << 8)
270270

271271
# reads the red light level as a 16-bit value
272-
def read_red_light(self):
272+
def red_light(self):
273273
self._ensure_light_enabled()
274274
# read value from red channel, low byte register
275275
low = self._read_reg(APDS9960_REG_RDATAL)
@@ -280,7 +280,7 @@ def read_red_light(self):
280280
return low + (high << 8)
281281

282282
# reads the green light level as a 16-bit value
283-
def read_green_light(self):
283+
def green_light(self):
284284
self._ensure_light_enabled()
285285
# read value from green channel, low byte register
286286
low = self._read_reg(APDS9960_REG_GDATAL)
@@ -291,7 +291,7 @@ def read_green_light(self):
291291
return low + (high << 8)
292292

293293
# reads the blue light level as a 16-bit value
294-
def read_blue_light(self):
294+
def blue_light(self):
295295
self._ensure_light_enabled()
296296
# read value from blue channel, low byte register
297297
low = self._read_reg(APDS9960_REG_BDATAL)
@@ -306,7 +306,7 @@ def read_blue_light(self):
306306
# *******************************************************************************
307307

308308
# reads the proximity level as an 8-bit value
309-
def read_proximity(self):
309+
def proximity(self):
310310
self._ensure_proximity_enabled()
311311
return self._read_reg(APDS9960_REG_PDATA)
312312

lib/apds9960/examples/ambient_light.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
oval = -1
1616
while True:
1717
sleep(0.25)
18-
val = apds.read_ambient_light()
18+
val = apds.ambient_light()
1919
if val != oval:
2020
print("AmbientLight={}".format(val))
2121
oval = val

lib/apds9960/examples/gesture.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@
3636
while True:
3737
sleep(0.5)
3838
if apds.is_gesture_available():
39-
motion = apds.read_gesture()
39+
motion = apds.gesture()
4040
print("Gesture={}".format(dirs.get(motion, "unknown")))

lib/apds9960/examples/proximity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
oval = -1
1818
while True:
1919
sleep(0.25)
20-
val = apds.read_proximity()
20+
val = apds.proximity()
2121
if val != oval:
2222
print("proximity={}".format(val))
2323
oval = val

lib/bq27441/bq27441/device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def state_of_health(self):
174174
return self.soh(SohMeasureType.PERCENT)
175175

176176
# Reads and returns the battery voltage
177-
def voltage(self):
177+
def voltage_mv(self):
178178
"""Return current voltage"""
179179
return self.read_word(BQ27441_COMMAND_VOLTAGE)
180180

lib/bq27441/examples/fuel_gauge.py

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

1414
while True:
1515
print("State of Charge:", fg.state_of_charge(), "%")
16-
print("Battery Voltage:", fg.voltage(), "mV")
16+
print("Battery Voltage:", fg.voltage_mv(), "mV")
1717
print("Average Current:", fg.current_average(), "mA")
1818
print("Full Capacity:", fg.capacity_full(), "/")
1919
print("Remaining Capacity:", fg.capacity_remaining(), "mAh")

lib/hts221/hts221/device.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,3 @@ def calibrate_temperature(self, ref_low, measured_low, ref_high, measured_high):
193193
raise ValueError("measured_low and measured_high must differ")
194194
self._temp_gain = float(ref_high - ref_low) / delta
195195
self._temp_offset = float(ref_low) - self._temp_gain * float(measured_low)
196-
197-
def get(self):
198-
h, t = self.read()
199-
return [h, t]

lib/lis2mdl/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ mag = LIS2MDL(i2c)
6363
### Read magnetic field
6464

6565
```python
66-
x, y, z = mag.read_magnet_uT()
66+
x, y, z = mag.magnetic_field_ut()
6767
print("Magnetic field (µT):", x, y, z)
6868
```
6969

@@ -181,7 +181,7 @@ Expected value: `0x40`
181181
### Read temperature (approximate)
182182

183183
```python
184-
print("Temperature (°C):", mag.read_temperature_c())
184+
print("Temperature (°C):", mag.temperature())
185185
```
186186

187187
### Check data readiness
@@ -204,12 +204,12 @@ print("Register dump:", regs)
204204

205205
| Method | Description |
206206
| ---------------------------------- | ------------------------------ |
207-
| `read_magnet_raw()` | Raw sensor values (int16) |
208-
| `read_magnet_uT()` | Magnetic field in µT |
209-
| `read_magnet_calibrated_norm()` | Calibrated and normalized data |
207+
| `magnetic_field_raw()` | Raw sensor values (int16) |
208+
| `magnetic_field_ut()` | Magnetic field in µT |
209+
| `calibrated_field()` | Calibrated and normalized data |
210210
| `heading_flat_only()` | Flat compass heading |
211211
| `heading_with_tilt_compensation()` | Tilt-corrected heading |
212-
| `read_temperature_c()` | Read relative temperature |
212+
| `temperature()` | Read relative temperature |
213213
| `power_on()` / `power_off()` | Power management |
214214
| `soft_reset()` / `reboot()` | Sensor reset functions |
215215

lib/lis2mdl/examples/magnet_fieldForce.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
print("Calibration complete.")
1313

1414
while True:
15-
field_strength = mag.magnitude_uT()
15+
field_strength = mag.magnitude_ut()
1616
print("Champ magnétique :", field_strength, "µT")
1717
sleep_ms(100)

0 commit comments

Comments
 (0)