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
Sub-issue of #44.
Problem
After init, all features are disabled (
setMode(APDS9960_MODE_ALL, False)). If the user callsreadAmbientLight()orreadProximity()without first callingenableLightSensor()orenableProximitySensor(), stale/zero data is returned silently.Similarly, calling
disablePower()thenreadAmbientLight()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_ensure_light_enabled()and_ensure_proximity_enabled()helpersisProximityAvailable()method (counterpart to existingisLightAvailable())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
_ensure_data()pattern (PR wsen-pads: Add pressure sensor driver. #3)