Skip to content

Commit 0b18873

Browse files
committed
Color engine tweaks and doc updates
1 parent faa7969 commit 0b18873

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

adafruit_apds9960/apds9960.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
_BIT_MASK_ENABLE_PROX = const(0x04)
110110
_BIT_MASK_ENABLE_PROX_INT = const(0x20)
111111
_BIT_MASK_ENABLE_GESTURE = const(0x40)
112+
_BIT_MASK_STATUS_AVALID = const(0x01)
112113
_BIT_MASK_STATUS_GINT = const(0x04)
113114
_BIT_MASK_GSTATUS_GFOV = const(0x02)
114115
_BIT_MASK_GCONF4_GFIFO_CLR = const(0x04)
@@ -217,9 +218,9 @@ def __init__(
217218
self._write8(_APDS9960_GCONF2, 0x41)
218219
# GPULSE: 5 (6 pulses), GPLEN: 2 (16 us)
219220
self._write8(_APDS9960_GPULSE, 0x85)
220-
# ATIME: 182 (200ms color integration time)
221-
self._write8(_APDS9960_ATIME, 0xB6)
222-
# AGAIN: 1 (4x color gain), PGAIN: 0 (1x)
221+
# ATIME: 255 (712ms color integration time, max count of 65535)
222+
self._write8(_APDS9960_ATIME, 0x00)
223+
# AGAIN: 1 (4x color gain), PGAIN: 0 (1x) (default), LDRIVE: 0 (100 mA) (default)
223224
self._write8(_APDS9960_CONTROL, 0x01)
224225

225226
## BOARD
@@ -318,6 +319,15 @@ def enable_color(self, value: bool) -> None:
318319
"""If true, the sensor's color/light engine is enabled"""
319320
self._set_bit(_APDS9960_ENABLE, _BIT_MASK_ENABLE_COLOR, value)
320321

322+
@property
323+
def color_data_ready(self) -> int:
324+
"""Color data ready flag.
325+
326+
Returns ``0`` if no new data is ready, ``1`` if new data is ready.
327+
328+
This flag is reset when `color_data` is read."""
329+
return self._get_bit(_APDS9960_STATUS, _BIT_MASK_STATUS_AVALID)
330+
321331
## PROXIMITY
322332
@property
323333
def proximity(self) -> int:
@@ -480,14 +490,17 @@ def gesture(self) -> int:
480490
return gesture_found
481491

482492
## COLOR
483-
@property
484-
def color_data_ready(self) -> int:
485-
"""Color data ready flag. Zero if not ready, 1 if ready"""
486-
return self._read8(_APDS9960_STATUS) & 0x01
487-
488493
@property
489494
def color_data(self) -> Tuple[int, int, int, int]:
490-
"""Tuple containing r, g, b, c values"""
495+
"""Tuple containing red, green, blue, and clear light intensity values detected by the
496+
sensor during the latest color/light engine run.
497+
498+
Each value is a 16-bit integer with a possible value of ``0`` to ``65535``.
499+
500+
.. hint:: Testing with and tuning `color_gain` and `color_integration_time` values will
501+
likely be required to get useful color results. Optimum values for these will depend
502+
largely on the implementation details such as sensor positioning, illumination intensity
503+
and color temperature, reflectivity of the object(s) being measured, etc."""
491504
return (
492505
self._color_data16(_APDS9960_CDATAL + 2),
493506
self._color_data16(_APDS9960_CDATAL + 4),

0 commit comments

Comments
 (0)