From 180b8c6d54384315d9e46558cb7587e89338cc22 Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Thu, 3 Mar 2022 13:22:16 +0100 Subject: [PATCH 1/4] add setter/getter for proximity-gain --- adafruit_apds9960/apds9960.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/adafruit_apds9960/apds9960.py b/adafruit_apds9960/apds9960.py index 7670bd9..4a548fa 100644 --- a/adafruit_apds9960/apds9960.py +++ b/adafruit_apds9960/apds9960.py @@ -120,6 +120,10 @@ _BIT_POS_CONTROL_AGAIN = const(0) _BIT_MASK_CONTROL_AGAIN = const(3) +_BIT_POS_CONTROL_PGAIN = const(2) +_BIT_MASK_CONTROL_PGAIN = const(0x0C) + + # pylint: disable-msg=too-many-instance-attributes class APDS9960: """ @@ -370,6 +374,30 @@ def proximity_interrupt_threshold(self, setting_tuple: Tuple[int, ...]) -> None: _APDS9960_PERS, _BIT_POS_PERS_PPERS, _BIT_MASK_PERS_PPERS, persist ) + @property + def proximity_gain(self) -> int: + """Proximity sensor gain value. + + This sets the gain multiplier for the ADC during proximity engine operations. + + .. csv-table:: + :header: "``proximity_gain``", "Gain Multiplier", "Note" + + 0, "1x", "Power-on Default" + 1, "2x", "" + 2, "4x", "" + 3, "8x", "" + """ + return self._get_bits( + _APDS9960_CONTROL, _BIT_POS_CONTROL_PGAIN, _BIT_MASK_CONTROL_PGAIN + ) + + @proximity_gain.setter + def proximity_gain(self, value: int) -> None: + self._set_bits( + _APDS9960_CONTROL, _BIT_POS_CONTROL_PGAIN, _BIT_MASK_CONTROL_PGAIN, value + ) + def clear_interrupt(self) -> None: """Clears all non-gesture interrupts. From c280f644ed93b9a9cfa205ef25724e1d026cc9dd Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Thu, 3 Mar 2022 13:35:28 +0100 Subject: [PATCH 2/4] add setter/getter for gesture-gain --- adafruit_apds9960/apds9960.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/adafruit_apds9960/apds9960.py b/adafruit_apds9960/apds9960.py index 4a548fa..6c7ace9 100644 --- a/adafruit_apds9960/apds9960.py +++ b/adafruit_apds9960/apds9960.py @@ -123,6 +123,8 @@ _BIT_POS_CONTROL_PGAIN = const(2) _BIT_MASK_CONTROL_PGAIN = const(0x0C) +_BIT_POS_GCONF2_GGAIN = const(5) +_BIT_MASK_GCONF2_GGAIN = const(0x60) # pylint: disable-msg=too-many-instance-attributes class APDS9960: @@ -224,7 +226,7 @@ def __init__( self._write8(_APDS9960_GEXTH, 0x1E) # GEXPERS: 2 (4 cycles), GEXMSK: 0 (default) GFIFOTH: 2 (8 datasets) self._write8(_APDS9960_GCONF1, 0x82) - # GGAIN: 2 (4x), GLDRIVE: 100 mA (default), GGAIN: 1 (2x) + # GGAIN: 2 (4x), GLDRIVE: 100 mA (default), GWTIME: 1 (2.8ms) self._write8(_APDS9960_GCONF2, 0x41) # GPULSE: 5 (6 pulses), GPLEN: 2 (16 us) self._write8(_APDS9960_GPULSE, 0x85) @@ -423,6 +425,30 @@ def enable_gesture(self) -> bool: def enable_gesture(self, value: bool) -> None: self._set_bit(_APDS9960_ENABLE, _BIT_MASK_ENABLE_GESTURE, value) + @property + def gesture_gain(self) -> int: + """Gesture mode gain value. + + This sets the gain multiplier for the ADC during gesture engine operations. + + .. csv-table:: + :header: "``gesture_gain``", "Gain Multiplier", "Note" + + 0, "1x", "Power-on Default" + 1, "2x", "" + 2, "4x", "Driver Default" + 3, "8x", "" + """ + return self._get_bits( + _APDS9960_GCONF2, _BIT_POS_GCONF2_GGAIN, _BIT_MASK_GCONF2_GGAIN + ) + + @gesture_gain.setter + def gesture_gain(self, value: int) -> None: + self._set_bits( + _APDS9960_GCONF2, _BIT_POS_GCONF2_GGAIN, _BIT_MASK_GCONF2_GGAIN, value + ) + @property def rotation(self) -> int: """Clock-wise offset to apply to gesture results. From b1902364be4e195e1bda5aaa6bd9f88aa9166188 Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Thu, 3 Mar 2022 13:36:14 +0100 Subject: [PATCH 3/4] fix wrong power-on default for CONTROL register --- adafruit_apds9960/apds9960.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_apds9960/apds9960.py b/adafruit_apds9960/apds9960.py index 6c7ace9..f1e3754 100644 --- a/adafruit_apds9960/apds9960.py +++ b/adafruit_apds9960/apds9960.py @@ -201,7 +201,7 @@ def __init__( self._write8(_APDS9960_GCONF4, 0) self._write8(_APDS9960_GPULSE, 0) self._write8(_APDS9960_ATIME, 255) - self._write8(_APDS9960_CONTROL, 1) + self._write8(_APDS9960_CONTROL, 0) # Clear all non-gesture interrupts self.clear_interrupt() From bbf51127f9cdd66a931b1da858e5ca90ad231229 Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Fri, 4 Mar 2022 15:36:45 +0100 Subject: [PATCH 4/4] fixed formatting to keep black happy --- adafruit_apds9960/apds9960.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_apds9960/apds9960.py b/adafruit_apds9960/apds9960.py index f1e3754..3a2e24e 100644 --- a/adafruit_apds9960/apds9960.py +++ b/adafruit_apds9960/apds9960.py @@ -389,7 +389,7 @@ def proximity_gain(self) -> int: 1, "2x", "" 2, "4x", "" 3, "8x", "" - """ + """ return self._get_bits( _APDS9960_CONTROL, _BIT_POS_CONTROL_PGAIN, _BIT_MASK_CONTROL_PGAIN ) @@ -438,7 +438,7 @@ def gesture_gain(self) -> int: 1, "2x", "" 2, "4x", "Driver Default" 3, "8x", "" - """ + """ return self._get_bits( _APDS9960_GCONF2, _BIT_POS_GCONF2_GGAIN, _BIT_MASK_GCONF2_GGAIN )