55
55
_VCNL4010_AMBIENT_LUX_SCALE = 0.25 # Lux value per 16-bit result value.
56
56
57
57
# User-facing constants:
58
+ # Number of proximity measuremenrs per second
59
+ SAMPLERATE_1_95 = 0
60
+ SAMPLERATE_3_90625 = 1
61
+ SAMPLERATE_7_8125 = 2
62
+ SAMPLERATE_16_625 = 3
63
+ SAMPLERATE_31_25 = 4
64
+ SAMPLERATE_62_5 = 5
65
+ SAMPLERATE_125 = 6
66
+ SAMPLERATE_250 = 7
67
+
68
+ # Proximity modulator timing
58
69
FREQUENCY_3M125 = 3
59
70
FREQUENCY_1M5625 = 2
60
71
FREQUENCY_781K25 = 1
@@ -113,6 +124,7 @@ def __init__(self, i2c, address=_VCNL4010_I2CADDR_DEFAULT):
113
124
if (revision & 0xF0 ) != 0x20 :
114
125
raise RuntimeError ("Failed to find VCNL4010, check wiring!" )
115
126
self .led_current = 20
127
+ self .samplerate = SAMPLERATE_1_95
116
128
self .frequency = FREQUENCY_390K625
117
129
self ._write_u8 (_VCNL4010_INTCONTROL , 0x08 )
118
130
@@ -153,8 +165,8 @@ def led_current(self, val):
153
165
154
166
@property
155
167
def led_current_mA (self ):
156
- """The current of the LED in milli-amps . The value here is
157
- specified in a milliamps from 0-200. Note that this value will be
168
+ """The current of the LED in milliamps . The value here is
169
+ specified in milliamps from 0-200. Note that this value will be
158
170
quantized down to a smaller less-accurate value as the chip only
159
171
supports current changes in 10mA increments, i.e. a value of 123 mA will
160
172
actually use 120 mA. See the datasheet for how the LED current impacts
@@ -167,18 +179,44 @@ def led_current_mA(self):
167
179
def led_current_mA (self , val ):
168
180
self .led_current = val // 10
169
181
182
+ @property
183
+ def samplerate (self ):
184
+ """
185
+ The frequency of proximity measurements per second. Must be a value of:
186
+
187
+ - SAMPLERATE_1_95: 1.95 measurements/sec (default)
188
+ - SAMPLERATE_3_90625: 3.90625 measurements/sec
189
+ - SAMPLERATE_7_8125: 7.8125 measurements/sec
190
+ - SAMPLERATE_16_625: 16.625 measurements/sec
191
+ - SAMPLERATE_31_25: 31.25 measurements/sec
192
+ - SAMPLERATE_62_5: 62.5 measurements/sec
193
+ - SAMPLERATE_125: 125 measurements/sec
194
+ - SAMPLERATE_250: 250 measurements/sec
195
+
196
+ See the datasheet for how frequency changes the power consumption and
197
+ proximity detection accuracy.
198
+ """
199
+ return self ._read_u8 (_VCNL4010_PROXRATE )
200
+
201
+ @samplerate .setter
202
+ def samplerate (self , val ):
203
+ assert 0 <= val <= 7
204
+ self ._write_u8 (_VCNL4010_PROXRATE , val )
205
+
170
206
@property
171
207
def frequency (self ):
172
208
"""
173
- The frequency of proximity measurements. Must be a value of:
209
+ Proximity modulator timimg. This is the frequency of the IR square
210
+ wave used for the proximity measurement.
211
+
212
+ Must be a value of:
174
213
175
214
- FREQUENCY_3M125: 3.125 Mhz
176
215
- FREQUENCY_1M5625: 1.5625 Mhz
177
216
- FREQUENCY_781K25: 781.25 Khz
178
217
- FREQUENCY_390K625: 390.625 Khz (default)
179
218
180
- See the datasheet for how frequency changes the proximity detection
181
- accuracy.
219
+ The datasheet recommended leaving this at the default.
182
220
"""
183
221
return (self ._read_u8 (_VCNL4010_MODTIMING ) >> 3 ) & 0x03
184
222
0 commit comments