Skip to content

Commit c135baf

Browse files
committed
Rename frequency and modulation
Restoring the original `frequency` property to refer to the proximity modulator timing (to keep from making a breaking change to the API) and renamed the new property to `samplerate`.
1 parent dd8a32e commit c135baf

File tree

1 file changed

+39
-34
lines changed

1 file changed

+39
-34
lines changed

adafruit_vcnl4010.py

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@
5656

5757
# User-facing constants:
5858
# 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
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
6767

6868
# Proximity modulator timing
69-
MODULATION_3M125 = 3
70-
MODULATION_1M5625 = 2
71-
MODULATION_781K25 = 1
72-
MODULATION_390K625 = 0
69+
FREQUENCY_3M125 = 3
70+
FREQUENCY_1M5625 = 2
71+
FREQUENCY_781K25 = 1
72+
FREQUENCY_390K625 = 0
7373

7474
# Disable pylint's name warning as it causes too much noise. Suffixes like
7575
# BE (big-endian) or mA (milli-amps) don't confirm to its conventions--by
@@ -124,8 +124,8 @@ def __init__(self, i2c, address=_VCNL4010_I2CADDR_DEFAULT):
124124
if (revision & 0xF0) != 0x20:
125125
raise RuntimeError("Failed to find VCNL4010, check wiring!")
126126
self.led_current = 20
127-
self.frequency = FREQUENCY_1_95
128-
self.modulation = MODULATION_390K625
127+
self.samplerate = SAMPLERATE_1_95
128+
self.frequency = FREQUENCY_390K625
129129
self._write_u8(_VCNL4010_INTCONTROL, 0x08)
130130

131131
def _read_u8(self, address):
@@ -180,43 +180,48 @@ def led_current_mA(self, val):
180180
self.led_current = val // 10
181181

182182
@property
183-
def frequency(self):
183+
def samplerate(self):
184184
"""
185185
The frequency of proximity measurements per second. Must be a value of:
186186
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
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
195195
196196
See the datasheet for how frequency changes the power consumption and
197197
proximity detection accuracy.
198198
"""
199199
return self._read_u8(_VCNL4010_PROXRATE)
200200

201-
@frequency.setter
202-
def frequency(self, val):
201+
@samplerate.setter
202+
def samplerate(self, val):
203203
assert 0 <= val <= 7
204204
self._write_u8(_VCNL4010_PROXRATE, val)
205205

206206
@property
207-
def modulation(self):
207+
def frequency(self):
208208
"""
209-
Proximity modulator timimg. Must be a value of:
210-
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)
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:
213+
214+
- FREQUENCY_3M125: 3.125 Mhz
215+
- FREQUENCY_1M5625: 1.5625 Mhz
216+
- FREQUENCY_781K25: 781.25 Khz
217+
- FREQUENCY_390K625: 390.625 Khz (default)
218+
219+
The datasheet recommended leaving this at the default.
215220
"""
216221
return (self._read_u8(_VCNL4010_MODTIMING) >> 3) & 0x03
217222

218-
@modulation.setter
219-
def modulation(self, val):
223+
@frequency.setter
224+
def frequency(self, val):
220225
assert 0 <= val <= 3
221226
timing = self._read_u8(_VCNL4010_MODTIMING)
222227
timing &= ~0b00011000

0 commit comments

Comments
 (0)