30 REG_IR_LED_CURRENT = 0x83
31 REG_AMB_PARAMETERS = 0x84
32 REG_AMB_RESULT_HIGH = 0x85
33 REG_PROX_RESULT_HIGH = 0x87
34 REG_PROX_FREQUENCY = 0x89
35 REG_PROX_ADJUST = 0x8A
37 VAL_MOD_TIMING_DEF = 129
39 VAL_PR_FREQ_3M125HZ = 0
40 VAL_PR_FREQ_1M5625HZ = 1
41 VAL_PR_FREQ_781K25HZ = 2
42 VAL_PR_FREQ_390K625HZ = 3
44 VAL_START_AMB = 1 << 4
45 VAL_START_PROX = 1 << 3
50 MASK_PROX_FREQUENCY = 0b00111111
51 MASK_IR_LED_CURRENT = 0b00111111
52 MASK_PROX_READY = 0b00100000
53 MASK_AMB_READY = 0b01000000
55 def __init__(self, slave=0b0010011, current=20, frequency=781, prox_threshold=15, prox_cycles=10, cal_cycles= 5):
56 I2C.__init__(self,
toint(slave))
68 return "VCNL4000(slave=0x%02X)" % self.
slave
71 return [Luminosity.__family__(self), Distance.__family__(self)]
77 ambient_parameter_bytes = 1 << 7 | 1 << 3 | 5
86 debug (
"VCNL4000: offset = %d" % (self.
offset))
106 if not self.
frequency in [391, 781, 1563, 3125]:
107 raise ValueError(
"Frequency %d out of range [%d,%d,%d,,%d]" % (self.
frequency, 391, 781, 1563, 3125))
134 if not self.
current in range(0,201):
135 raise ValueError(
"%d mA LED current out of range [%d..%d] mA" % (self.
current, 0, 201))
141 return bits_current * 10
148 light_word = light_bytes[0] << 8 | light_bytes[1]
152 return (light_word + 3) * 0.25
159 while (fail < match_cycles) & (success < match_cycles):
166 if fail == match_cycles:
177 debug (
"VCNL4000: prox real raw counts = %d" % (raw_proximity_counts))
178 if raw_proximity_counts >= 10000:
179 estimated_distance = 0
180 elif raw_proximity_counts >= 3000:
181 estimated_distance = 5
182 elif raw_proximity_counts >= 900:
183 estimated_distance = 10
184 elif raw_proximity_counts >= 300:
185 estimated_distance = 20
186 elif raw_proximity_counts >= 150:
187 estimated_distance = 30
188 elif raw_proximity_counts >= 75:
189 estimated_distance = 40
190 elif raw_proximity_counts >= 50:
191 estimated_distance = 50
192 elif raw_proximity_counts >= 25:
193 estimated_distance = 70
195 estimated_distance = 100
196 return estimated_distance
209 debug (
"VCNL4000: prox raw value = %d" % (proximity_bytes[0] << 8 | proximity_bytes[1]))
210 return (proximity_bytes[0] << 8 | proximity_bytes[1])
int VAL_PR_FREQ_390K625HZ
def __readProximityCounts__
def __calculateMillimeter__
def __setProximityTiming__
def __setAmbientMeasuringMode__