Skip to content

Commit 3b141e5

Browse files
authored
Merge pull request #2 from adafruit/partial_lib
a few more proximity bits
2 parents 530f1d4 + f461b99 commit 3b141e5

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

adafruit_vcnl4200.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,20 @@ class Adafruit_VCNL4200:
150150
als_persistance = RWBits(2, _ALS_CONF, 2) # ALS persistence bits
151151
als_low_threshold = UnaryStruct(_ALS_THDL, "<H")
152152
als_high_threshold = UnaryStruct(_ALS_THDH, "<H")
153-
prox_shutdown = RWBit(_PS_CONF12, 0) # Bit 0: PS_SD (Proximity Sensor Shutdown)
153+
prox_active_force = RWBit(_PS_CONF3MS, 3)
154+
prox_duty = RWBits(2, _PS_CONF12, 6)
155+
prox_hd = RWBit(_PS_CONF12, 11)
154156
prox_integration_time = RWBits(3, _PS_CONF12, 1)
157+
prox_interrupt = RWBits(2, _PS_CONF12, 8)
158+
prox_persistence = RWBits(2, _PS_CONF12, 4)
159+
prox_shutdown = RWBit(_PS_CONF12, 0) # Bit 0: PS_SD (Proximity Sensor Shutdown)
155160
proximity = ROUnaryStruct(_PS_DATA, "<H")
156161
lux = ROUnaryStruct(_ALS_DATA, "<H")
157162
white_light = ROUnaryStruct(_WHITE_DATA, "<H") # 16-bit register for white light data
158163
_als_int_en = RWBits(1, _ALS_CONF, 1) # Bit 1: ALS interrupt enable
159164
_als_int_switch = RWBits(1, _ALS_CONF, 5) # Bit 5: ALS interrupt channel selection (white/ALS)
160-
_proximity_int_en = RWBits(
161-
1, _PS_CONF12, 0
162-
) # Bit 0 in proximity config register for proximity interrupt enable
165+
_proximity_int_en = RWBits(1, _PS_CONF12, 0)
166+
_prox_trigger = RWBit(_PS_CONF3MS, 2)
163167

164168
def __init__(self, i2c: I2C, addr: int = _I2C_ADDRESS) -> None:
165169
self.i2c_device = I2CDevice(i2c, addr)
@@ -181,8 +185,10 @@ def __init__(self, i2c: I2C, addr: int = _I2C_ADDRESS) -> None:
181185
self.als_low_threshold = 0
182186
self.als_high_threshold = 0xFFFF
183187
self.set_interrupt(enabled=False, white_channel=False)
188+
self.prox_duty = PS_DUTY["1_160"]
184189
self.prox_shutdown = False
185190
self.prox_integration_time = PS_IT["1T"]
191+
self.prox_persistence = PS_PERS["1"]
186192
except Exception as error:
187193
raise RuntimeError(f"Failed to initialize: {error}") from error
188194

@@ -195,3 +201,11 @@ def set_interrupt(self, enabled, white_channel):
195201
return True
196202
except OSError:
197203
return False
204+
205+
def trigger_prox(self):
206+
"""Triggers a single proximity measurement manually in active force mode."""
207+
try:
208+
self._prox_trigger = True
209+
return True
210+
except OSError:
211+
return False

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Uncomment the below if you use native CircuitPython modules such as
2626
# digitalio, micropython and busio. List the modules you use. Without it, the
2727
# autodoc module docs will fail to generate with a warning.
28-
# autodoc_mock_imports = ["digitalio", "busio"]
28+
autodoc_mock_imports = ["busio", "adafruit_register", "adafruit_bus_device"]
2929

3030
autodoc_preserve_defaults = True
3131

0 commit comments

Comments
 (0)