Skip to content

apds9960: Auto-enable sensor when reading without active mode.#75

Merged
nedseb merged 3 commits intomainfrom
fix/apds9960-auto-enable
Mar 14, 2026
Merged

apds9960: Auto-enable sensor when reading without active mode.#75
nedseb merged 3 commits intomainfrom
fix/apds9960-auto-enable

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Mar 13, 2026

Closes #72

Summary

Reading light or proximity data now automatically enables the sensor if it was disabled, instead of returning stale/zero values.

  • _ensure_light_enabled() — checks AEN and PON bits in ENABLE register; if not set, calls enableLightSensor() and polls AVALID (up to 500ms)
  • _ensure_proximity_enabled() — checks PEN and PON bits; if not set, calls enableProximitySensor() and waits 50ms
  • Called in readAmbientLight(), readRedLight(), readGreenLight(), readBlueLight(), readProximity()
  • No overhead when sensor is already active (no register writes)

Follows the auto-trigger convention from #44.

Test plan

Mock tests (no hardware)

python3 -m pytest tests/ -k "apds9960 and mock" -v
tests/test_scenarios.py::test_scenario[apds9960/Verify device ID register (mock)/mock] PASSED
tests/test_scenarios.py::test_scenario[apds9960/Read ambient light returns expected value/mock] PASSED
tests/test_scenarios.py::test_scenario[apds9960/Read proximity returns expected value/mock] PASSED
tests/test_scenarios.py::test_scenario[apds9960/Read red light returns expected value/mock] PASSED
tests/test_scenarios.py::test_scenario[apds9960/Ambient light readable without explicit enable/mock] PASSED
tests/test_scenarios.py::test_scenario[apds9960/Proximity readable without explicit enable/mock] PASSED
tests/test_scenarios.py::test_scenario[apds9960/Red light readable after power off/mock] PASSED
tests/test_scenarios.py::test_scenario[apds9960/No re-enable when already active/mock] PASSED

8 passed

Hardware tests (STeaMi board connected)

python3 -m pytest tests/ --port /dev/ttyACM0 -k "apds9960 and hardware" -s -v
tests/test_scenarios.py::test_scenario[apds9960/Verify device ID register (hardware)/hardware] PASSED
tests/test_scenarios.py::test_scenario[apds9960/Ambient light in plausible range/hardware] PASSED
tests/test_scenarios.py::test_scenario[apds9960/Proximity in plausible range/hardware] PASSED

3 passed, 2 skipped

@nedseb nedseb changed the title apds9960: Auto-enable sensor when reading without active mode. [WIP] apds9960: Auto-enable sensor when reading without active mode. Mar 13, 2026
@nedseb nedseb added the enhancement New feature or request label Mar 13, 2026
@nedseb nedseb force-pushed the fix/apds9960-auto-enable branch from d7c61ce to 1a5629a Compare March 14, 2026 21:20
@nedseb nedseb marked this pull request as ready for review March 14, 2026 21:21
@nedseb nedseb requested a review from Copilot March 14, 2026 21:22
@nedseb nedseb self-assigned this Mar 14, 2026
@nedseb nedseb changed the title [WIP] apds9960: Auto-enable sensor when reading without active mode. apds9960: Auto-enable sensor when reading without active mode. Mar 14, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds “auto-enable on read” behavior to the APDS9960 driver so light/proximity read methods work even if the corresponding sensor (or power) hasn’t been explicitly enabled, and extends the scenario suite to cover the intended behavior.

Changes:

  • Add internal helpers to auto-enable the light/proximity engines before reads.
  • Call those helpers from readAmbientLight / read{Red,Green,Blue}Light / readProximity.
  • Add new YAML scenario cases intended to validate auto-enable behavior in mock mode.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
lib/apds9960/apds9960/device.py Introduces _ensure_*_enabled() and uses them in read methods to auto-enable sensors.
tests/scenarios/apds9960.yaml Adds new scenario tests for “read without explicit enable” and “no re-enable when already active”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/scenarios/apds9960.yaml Outdated
Comment thread tests/scenarios/apds9960.yaml Outdated
Comment thread tests/scenarios/apds9960.yaml Outdated
Comment thread lib/apds9960/apds9960/device.py Outdated
Comment thread lib/apds9960/apds9960/device.py
@nedseb nedseb merged commit d85def2 into main Mar 14, 2026
3 checks passed
@nedseb nedseb deleted the fix/apds9960-auto-enable branch March 14, 2026 21:51
@semantic-release-updater
Copy link
Copy Markdown

🎉 This PR is included in version 0.0.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

apds9960: Auto-enable sensor when reading without active mode.

3 participants