Skip to content

Commit c280f64

Browse files
committed
add setter/getter for gesture-gain
1 parent 180b8c6 commit c280f64

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

adafruit_apds9960/apds9960.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@
123123
_BIT_POS_CONTROL_PGAIN = const(2)
124124
_BIT_MASK_CONTROL_PGAIN = const(0x0C)
125125

126+
_BIT_POS_GCONF2_GGAIN = const(5)
127+
_BIT_MASK_GCONF2_GGAIN = const(0x60)
126128

127129
# pylint: disable-msg=too-many-instance-attributes
128130
class APDS9960:
@@ -224,7 +226,7 @@ def __init__(
224226
self._write8(_APDS9960_GEXTH, 0x1E)
225227
# GEXPERS: 2 (4 cycles), GEXMSK: 0 (default) GFIFOTH: 2 (8 datasets)
226228
self._write8(_APDS9960_GCONF1, 0x82)
227-
# GGAIN: 2 (4x), GLDRIVE: 100 mA (default), GGAIN: 1 (2x)
229+
# GGAIN: 2 (4x), GLDRIVE: 100 mA (default), GWTIME: 1 (2.8ms)
228230
self._write8(_APDS9960_GCONF2, 0x41)
229231
# GPULSE: 5 (6 pulses), GPLEN: 2 (16 us)
230232
self._write8(_APDS9960_GPULSE, 0x85)
@@ -423,6 +425,30 @@ def enable_gesture(self) -> bool:
423425
def enable_gesture(self, value: bool) -> None:
424426
self._set_bit(_APDS9960_ENABLE, _BIT_MASK_ENABLE_GESTURE, value)
425427

428+
@property
429+
def gesture_gain(self) -> int:
430+
"""Gesture mode gain value.
431+
432+
This sets the gain multiplier for the ADC during gesture engine operations.
433+
434+
.. csv-table::
435+
:header: "``gesture_gain``", "Gain Multiplier", "Note"
436+
437+
0, "1x", "Power-on Default"
438+
1, "2x", ""
439+
2, "4x", "Driver Default"
440+
3, "8x", ""
441+
"""
442+
return self._get_bits(
443+
_APDS9960_GCONF2, _BIT_POS_GCONF2_GGAIN, _BIT_MASK_GCONF2_GGAIN
444+
)
445+
446+
@gesture_gain.setter
447+
def gesture_gain(self, value: int) -> None:
448+
self._set_bits(
449+
_APDS9960_GCONF2, _BIT_POS_GCONF2_GGAIN, _BIT_MASK_GCONF2_GGAIN, value
450+
)
451+
426452
@property
427453
def rotation(self) -> int:
428454
"""Clock-wise offset to apply to gesture results.

0 commit comments

Comments
 (0)