55
55
_VCNL4010_AMBIENT_LUX_SCALE = 0.25 # Lux value per 16-bit result value.
56
56
57
57
# User-facing constants:
58
- FREQUENCY_3M125 = 3
59
- FREQUENCY_1M5625 = 2
60
- FREQUENCY_781K25 = 1
61
- FREQUENCY_390K625 = 0
58
+ # Number of proximity measuremenrs per second
59
+ FREQUENCY_1_95 = 0
60
+ FREQUENCY_3_90625 = 1
61
+ FREQUENCY_7_8125 = 2
62
+ FREQUENCY_16_625 = 3
63
+ FREQUENCY_31_25 = 4
64
+ FREQUENCY_62_5 = 5
65
+ FREQUENCY_125 = 6
66
+ FREQUENCY_250 = 7
67
+
68
+ # Proximity modulator timing
69
+ MODULATION_3M125 = 3
70
+ MODULATION_1M5625 = 2
71
+ MODULATION_781K25 = 1
72
+ MODULATION_390K625 = 0
62
73
63
74
# Disable pylint's name warning as it causes too much noise. Suffixes like
64
75
# BE (big-endian) or mA (milli-amps) don't confirm to its conventions--by
@@ -113,7 +124,8 @@ 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
116
- self .frequency = FREQUENCY_390K625
127
+ self .frequency = FREQUENCY_1_95
128
+ self .modulation = MODULATION_390K625
117
129
self ._write_u8 (_VCNL4010_INTCONTROL , 0x08 )
118
130
119
131
def _read_u8 (self , address ):
@@ -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
@@ -170,20 +182,41 @@ def led_current_mA(self, val):
170
182
@property
171
183
def frequency (self ):
172
184
"""
173
- The frequency of proximity measurements. Must be a value of:
185
+ The frequency of proximity measurements per second. Must be a value of:
186
+
187
+ - FREQUENCY_1_95: 1.95 measurements/sec (default)
188
+ - FREQUENCY_3_90625: 3.90625 measurements/sec
189
+ - FREQUENCY_7_8125: 7.8125 measurements/sec
190
+ - FREQUENCY_16_625: 16.625 measurements/sec
191
+ - FREQUENCY_31_25: 31.25 measurements/sec
192
+ - FREQUENCY_62_5: 62.5 measurements/sec
193
+ - FREQUENCY_125: 125 measurements/sec
194
+ - FREQUENCY_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
+ @frequency .setter
202
+ def frequency (self , val ):
203
+ assert 0 <= val <= 7
204
+ self ._write_u8 (_VCNL4010_PROXRATE , val )
174
205
175
- - FREQUENCY_3M125: 3.125 Mhz
176
- - FREQUENCY_1M5625: 1.5625 Mhz
177
- - FREQUENCY_781K25: 781.25 Khz
178
- - FREQUENCY_390K625: 390.625 Khz (default)
206
+ @ property
207
+ def modulation ( self ):
208
+ """
209
+ Proximity modulator timimg. Must be a value of:
179
210
180
- See the datasheet for how frequency changes the proximity detection
181
- accuracy.
211
+ - MODULATION_3M125: 3.125 Mhz
212
+ - MODULATION_1M5625: 1.5625 Mhz
213
+ - MODULATION_781K25: 781.25 Khz
214
+ - MODULATION_390K625: 390.625 Khz (default)
182
215
"""
183
216
return (self ._read_u8 (_VCNL4010_MODTIMING ) >> 3 ) & 0x03
184
217
185
- @frequency .setter
186
- def frequency (self , val ):
218
+ @modulation .setter
219
+ def modulation (self , val ):
187
220
assert 0 <= val <= 3
188
221
timing = self ._read_u8 (_VCNL4010_MODTIMING )
189
222
timing &= ~ 0b00011000
0 commit comments