diff --git a/adafruit_vcnl4010.py b/adafruit_vcnl4010.py index 0ec8639..7015153 100644 --- a/adafruit_vcnl4010.py +++ b/adafruit_vcnl4010.py @@ -55,6 +55,17 @@ _VCNL4010_AMBIENT_LUX_SCALE = 0.25 # Lux value per 16-bit result value. # User-facing constants: +# Number of proximity measuremenrs per second +SAMPLERATE_1_95 = 0 +SAMPLERATE_3_90625 = 1 +SAMPLERATE_7_8125 = 2 +SAMPLERATE_16_625 = 3 +SAMPLERATE_31_25 = 4 +SAMPLERATE_62_5 = 5 +SAMPLERATE_125 = 6 +SAMPLERATE_250 = 7 + +# Proximity modulator timing FREQUENCY_3M125 = 3 FREQUENCY_1M5625 = 2 FREQUENCY_781K25 = 1 @@ -113,6 +124,7 @@ def __init__(self, i2c, address=_VCNL4010_I2CADDR_DEFAULT): if (revision & 0xF0) != 0x20: raise RuntimeError("Failed to find VCNL4010, check wiring!") self.led_current = 20 + self.samplerate = SAMPLERATE_1_95 self.frequency = FREQUENCY_390K625 self._write_u8(_VCNL4010_INTCONTROL, 0x08) @@ -153,8 +165,8 @@ def led_current(self, val): @property def led_current_mA(self): - """The current of the LED in milli-amps. The value here is - specified in a milliamps from 0-200. Note that this value will be + """The current of the LED in milliamps. The value here is + specified in milliamps from 0-200. Note that this value will be quantized down to a smaller less-accurate value as the chip only supports current changes in 10mA increments, i.e. a value of 123 mA will actually use 120 mA. See the datasheet for how the LED current impacts @@ -167,18 +179,44 @@ def led_current_mA(self): def led_current_mA(self, val): self.led_current = val // 10 + @property + def samplerate(self): + """ + The frequency of proximity measurements per second. Must be a value of: + + - SAMPLERATE_1_95: 1.95 measurements/sec (default) + - SAMPLERATE_3_90625: 3.90625 measurements/sec + - SAMPLERATE_7_8125: 7.8125 measurements/sec + - SAMPLERATE_16_625: 16.625 measurements/sec + - SAMPLERATE_31_25: 31.25 measurements/sec + - SAMPLERATE_62_5: 62.5 measurements/sec + - SAMPLERATE_125: 125 measurements/sec + - SAMPLERATE_250: 250 measurements/sec + + See the datasheet for how frequency changes the power consumption and + proximity detection accuracy. + """ + return self._read_u8(_VCNL4010_PROXRATE) + + @samplerate.setter + def samplerate(self, val): + assert 0 <= val <= 7 + self._write_u8(_VCNL4010_PROXRATE, val) + @property def frequency(self): """ - The frequency of proximity measurements. Must be a value of: + Proximity modulator timimg. This is the frequency of the IR square + wave used for the proximity measurement. + + Must be a value of: - FREQUENCY_3M125: 3.125 Mhz - FREQUENCY_1M5625: 1.5625 Mhz - FREQUENCY_781K25: 781.25 Khz - FREQUENCY_390K625: 390.625 Khz (default) - See the datasheet for how frequency changes the proximity detection - accuracy. + The datasheet recommended leaving this at the default. """ return (self._read_u8(_VCNL4010_MODTIMING) >> 3) & 0x03