drivers: Standardize read and measurement method naming.#160
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Standardizes sensor measurement method naming across several drivers to follow a consistent “bare noun” API and updates scenarios/examples/docs accordingly (per #80).
Changes:
- Renames LIS2MDL temperature API from
read_temperature_c()totemperature()and updates related tests/examples/docs. - Renames APDS9960 measurement methods from
read_*to bare nouns (ambient_light(),proximity(),gesture(), etc.) and updates tests/examples/docs. - Removes HTS221
get()(duplicate ofread()) and documents the measurement naming convention in the root README.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/scenarios/lis2mdl.yaml | Updates scenario calls to temperature() |
| tests/scenarios/board_temperature_comparison.yaml | Updates LIS2MDL temperature usage in board comparison script |
| tests/scenarios/apds9960.yaml | Updates scenario calls to APDS9960 bare-noun measurement methods |
| lib/lis2mdl/lis2mdl/device.py | Renames read_temperature_c() → temperature() and updates internal usage |
| lib/lis2mdl/examples/magnet_test.py | Updates example to call temperature() |
| lib/lis2mdl/README.md | Updates LIS2MDL README to reference temperature() |
| lib/hts221/hts221/device.py | Removes get() wrapper around read() |
| lib/apds9960/examples/proximity.py | Updates example to call proximity() |
| lib/apds9960/examples/gesture.py | Updates example to call gesture() |
| lib/apds9960/examples/ambient_light.py | Updates example to call ambient_light() |
| lib/apds9960/apds9960/device.py | Renames read_* methods to bare nouns |
| README.md | Updates APDS9960 usage example and documents measurement naming convention |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - **Reset methods**: `reset()` for hardware reset (pin toggle), `soft_reset()` for software reset (register write), `reboot()` for memory reboot (reload trimming). | ||
| - **Power methods**: `power_on()` / `power_off()`. All drivers must implement both. | ||
| - **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()`). | ||
| - **Measurement methods**: bare noun for the main unit (`temperature()`, `humidity()`, `pressure()`), `read()` for combined reading returning a tuple, `<measurement>_raw()` for raw register values. No `read_` prefix on individual measurements. |
Comment on lines
248
to
+252
| hi = self._read_reg(LIS2MDL_TEMP_OUT_H_REG) | ||
| v = (hi << 8) | lo | ||
| return v - 0x10000 if (v & 0x8000) else v | ||
|
|
||
| def read_temperature_c(self) -> float: | ||
| def temperature(self) -> float: |
Comment on lines
191
to
195
| delta = float(measured_high - measured_low) | ||
| if delta == 0.0: | ||
| raise ValueError("measured_low and measured_high must differ") | ||
| self._temp_gain = float(ref_high - ref_low) / delta | ||
| self._temp_offset = float(ref_low) - self._temp_gain * float(measured_low) |
| @@ -169,7 +169,7 @@ def is_gesture_available(self): | |||
| return val == APDS9960_BIT_GVALID | |||
|
|
|||
| # processes a gesture event and returns best guessed gesture | |||
e3ac1cb to
6cf63d9
Compare
6cf63d9 to
be4f22e
Compare
|
🎉 This PR is included in version 0.0.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #80
Summary
Standardize measurement method naming across all drivers.
Convention:
temperature(),humidity()— bare noun, no unit suffix (°C and %RH are unambiguous)pressure_hpa(),distance_mm(),voltage_mv(),acceleration_g(), etc.read()— combined reading returning a tuple<measurement>_raw()— raw register valuesread_prefix on individual measurementsChanges
get()read())read_temperature_c()temperature()read_magnet()magnetic_field()read_magnet_raw()magnetic_field_raw()read_magnet_uT()magnetic_field_ut()read_magnet_calibrated_norm()calibrated_field()magnitude_uT()magnitude_ut()read_ambient_light()ambient_light()read_red/green/blue_light()red/green/blue_light()read_proximity()proximity()read_gesture()gesture()read()onlydistance_mm()as primary,read()as aliaspressure()pressure_hpa()voltage()voltage_mv()Final state
read()→ tupletemperature(),humidity()acceleration_g(),acceleration_ms2(),gyroscope_dps(),gyroscope_rads(),temperature_c()magnetic_field(),magnetic_field_ut(),magnetic_field_raw(),calibrated_field(),temperature(),magnitude_ut()read()(alias)distance_mm()read()→ tupletemperature(),humidity()read()→ tupletemperature(),pressure_hpa(),pressure_kpa()ambient_light(),red_light(),green_light(),blue_light(),proximity(),gesture()voltage_mv(),temperature(),soc()Also updated README, tests, examples, and driver READMEs.
Test plan