Skip to content

a few more proximity bits #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions adafruit_vcnl4200.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,20 @@ class Adafruit_VCNL4200:
als_persistance = RWBits(2, _ALS_CONF, 2) # ALS persistence bits
als_low_threshold = UnaryStruct(_ALS_THDL, "<H")
als_high_threshold = UnaryStruct(_ALS_THDH, "<H")
prox_shutdown = RWBit(_PS_CONF12, 0) # Bit 0: PS_SD (Proximity Sensor Shutdown)
prox_active_force = RWBit(_PS_CONF3MS, 3)
prox_duty = RWBits(2, _PS_CONF12, 6)
prox_hd = RWBit(_PS_CONF12, 11)
prox_integration_time = RWBits(3, _PS_CONF12, 1)
prox_interrupt = RWBits(2, _PS_CONF12, 8)
prox_persistence = RWBits(2, _PS_CONF12, 4)
prox_shutdown = RWBit(_PS_CONF12, 0) # Bit 0: PS_SD (Proximity Sensor Shutdown)
proximity = ROUnaryStruct(_PS_DATA, "<H")
lux = ROUnaryStruct(_ALS_DATA, "<H")
white_light = ROUnaryStruct(_WHITE_DATA, "<H") # 16-bit register for white light data
_als_int_en = RWBits(1, _ALS_CONF, 1) # Bit 1: ALS interrupt enable
_als_int_switch = RWBits(1, _ALS_CONF, 5) # Bit 5: ALS interrupt channel selection (white/ALS)
_proximity_int_en = RWBits(
1, _PS_CONF12, 0
) # Bit 0 in proximity config register for proximity interrupt enable
_proximity_int_en = RWBits(1, _PS_CONF12, 0)
_prox_trigger = RWBit(_PS_CONF3MS, 2)

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

Expand All @@ -195,3 +201,11 @@ def set_interrupt(self, enabled, white_channel):
return True
except OSError:
return False

def trigger_prox(self):
"""Triggers a single proximity measurement manually in active force mode."""
try:
self._prox_trigger = True
return True
except OSError:
return False
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Uncomment the below if you use native CircuitPython modules such as
# digitalio, micropython and busio. List the modules you use. Without it, the
# autodoc module docs will fail to generate with a warning.
# autodoc_mock_imports = ["digitalio", "busio"]
autodoc_mock_imports = ["busio", "adafruit_register", "adafruit_bus_device"]

autodoc_preserve_defaults = True

Expand Down