Skip to content

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

@nedseb

Description

@nedseb

Sub-issue of #44.

Problem

After init, all features are disabled (setMode(APDS9960_MODE_ALL, False)). If the user calls readAmbientLight() or readProximity() without first calling enableLightSensor() or enableProximitySensor(), stale/zero data is returned silently.

Similarly, calling disablePower() then readAmbientLight() returns stale data.

Solution

Add auto-enable logic before read methods:

  • readAmbientLight(), readRedLight(), readGreenLight(), readBlueLight(): check if AEN (ambient light enable) bit is set in ENABLE register; if not, enable it and wait for a valid reading (poll AVALID in STATUS)
  • readProximity(): check if PEN (proximity enable) bit is set; if not, enable it and wait for PVALID
  • Add _ensure_light_enabled() and _ensure_proximity_enabled() helpers
  • Optionally add isProximityAvailable() method (counterpart to existing isLightAvailable())

Considerations

This driver is a port of the SparkFun APDS-9960 library. The auto-enable pattern is not in the original library but aligns with the project convention (issue #44). The change should be backward-compatible since enabling a sensor that is already enabled is a no-op.

Reference

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdriverConcerne un driver spécifiqueenhancementNew feature or requestreleased

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions