56
56
# GAIN_DEF = const(0x01)
57
57
58
58
# APDS9960_RAM = const(0x00)
59
- APDS9960_ENABLE = const (0x80 )
60
- APDS9960_ATIME = const (0x81 )
59
+ _APDS9960_ENABLE = const (0x80 )
60
+ _APDS9960_ATIME = const (0x81 )
61
61
# APDS9960_WTIME = const(0x83)
62
62
# APDS9960_AILTIL = const(0x84)
63
63
# APDS9960_AILTH = const(0x85)
64
64
# APDS9960_AIHTL = const(0x86)
65
65
# APDS9960_AIHTH = const(0x87)
66
- APDS9960_PILT = const (0x89 )
67
- APDS9960_PIHT = const (0x8B )
68
- APDS9960_PERS = const (0x8C )
66
+ _APDS9960_PILT = const (0x89 )
67
+ _APDS9960_PIHT = const (0x8B )
68
+ _APDS9960_PERS = const (0x8C )
69
69
# APDS9960_CONFIG1 = const(0x8D)
70
70
# APDS9960_PPULSE = const(0x8E)
71
- APDS9960_CONTROL = const (0x8F )
71
+ _APDS9960_CONTROL = const (0x8F )
72
72
# APDS9960_CONFIG2 = const(0x90)
73
- APDS9960_ID = const (0x92 )
74
- APDS9960_STATUS = const (0x93 )
75
- APDS9960_CDATAL = const (0x94 )
73
+ _APDS9960_ID = const (0x92 )
74
+ _APDS9960_STATUS = const (0x93 )
75
+ _APDS9960_CDATAL = const (0x94 )
76
76
# APDS9960_CDATAH = const(0x95)
77
77
# APDS9960_RDATAL = const(0x96)
78
78
# APDS9960_RDATAH = const(0x97)
79
79
# APDS9960_GDATAL = const(0x98)
80
80
# APDS9960_GDATAH = const(0x99)
81
81
# APDS9960_BDATAL = const(0x9A)
82
82
# APDS9960_BDATAH = const(0x9B)
83
- APDS9960_PDATA = const (0x9C )
83
+ _APDS9960_PDATA = const (0x9C )
84
84
# APDS9960_POFFSET_UR = const(0x9D)
85
85
# APDS9960_POFFSET_DL = const(0x9E)
86
86
# APDS9960_CONFIG3 = const(0x9F)
87
- APDS9960_GPENTH = const (0xA0 )
87
+ _APDS9960_GPENTH = const (0xA0 )
88
88
# APDS9960_GEXTH = const(0xA1)
89
- APDS9960_GCONF1 = const (0xA2 )
90
- APDS9960_GCONF2 = const (0xA3 )
89
+ _APDS9960_GCONF1 = const (0xA2 )
90
+ _APDS9960_GCONF2 = const (0xA3 )
91
91
# APDS9960_GOFFSET_U = const(0xA4)
92
92
# APDS9960_GOFFSET_D = const(0xA5)
93
93
# APDS9960_GOFFSET_L = const(0xA7)
94
94
# APDS9960_GOFFSET_R = const(0xA9)
95
- APDS9960_GPULSE = const (0xA6 )
96
- APDS9960_GCONF3 = const (0xAA )
97
- APDS9960_GCONF4 = const (0xAB )
98
- APDS9960_GFLVL = const (0xAE )
99
- APDS9960_GSTATUS = const (0xAF )
95
+ _APDS9960_GPULSE = const (0xA6 )
96
+ _APDS9960_GCONF3 = const (0xAA )
97
+ _APDS9960_GCONF4 = const (0xAB )
98
+ _APDS9960_GFLVL = const (0xAE )
99
+ _APDS9960_GSTATUS = const (0xAF )
100
100
# APDS9960_IFORCE = const(0xE4)
101
101
# APDS9960_PICLEAR = const(0xE5)
102
102
# APDS9960_CICLEAR = const(0xE6)
103
- APDS9960_AICLEAR = const (0xE7 )
104
- APDS9960_GFIFO_U = const (0xFC )
103
+ _APDS9960_AICLEAR = const (0xE7 )
104
+ _APDS9960_GFIFO_U = const (0xFC )
105
105
# APDS9960_GFIFO_D = const(0xFD)
106
106
# APDS9960_GFIFO_L = const(0xFE)
107
107
# APDS9960_GFIFO_R = const(0xFF)
@@ -144,10 +144,10 @@ class APDS9960:
144
144
145
145
"""
146
146
147
- _gesture_enable = RWBit (APDS9960_ENABLE , 6 )
148
- _gesture_valid = RWBit (APDS9960_GSTATUS , 0 )
149
- _gesture_mode = RWBit (APDS9960_GCONF4 , 0 )
150
- _proximity_persistance = RWBits (4 , APDS9960_PERS , 4 )
147
+ _gesture_enable = RWBit (_APDS9960_ENABLE , 6 )
148
+ _gesture_valid = RWBit (_APDS9960_GSTATUS , 0 )
149
+ _gesture_mode = RWBit (_APDS9960_GCONF4 , 0 )
150
+ _proximity_persistance = RWBits (4 , _APDS9960_PERS , 4 )
151
151
152
152
def __init__ (
153
153
self ,
@@ -164,7 +164,7 @@ def __init__(
164
164
165
165
self .i2c_device = I2CDevice (i2c , address )
166
166
167
- if self ._read8 (APDS9960_ID ) != 0xAB :
167
+ if self ._read8 (_APDS9960_ID ) != 0xAB :
168
168
raise RuntimeError ()
169
169
170
170
self .enable_gesture = False
@@ -188,7 +188,7 @@ def __init__(
188
188
self ._reset_counts ()
189
189
190
190
# gesture pulse length=0x2 pulse count=0x3
191
- self ._write8 (APDS9960_GPULSE , (0x2 << 6 ) | 0x3 )
191
+ self ._write8 (_APDS9960_GPULSE , (0x2 << 6 ) | 0x3 )
192
192
193
193
## BOARD
194
194
def _reset_counts (self ) -> None :
@@ -198,20 +198,20 @@ def _reset_counts(self) -> None:
198
198
self ._saw_left_start = 0
199
199
self ._saw_right_start = 0
200
200
201
- enable = RWBit (APDS9960_ENABLE , 0 )
201
+ enable = RWBit (_APDS9960_ENABLE , 0 )
202
202
"""Board enable. True to enable, False to disable"""
203
- enable_color = RWBit (APDS9960_ENABLE , 1 )
203
+ enable_color = RWBit (_APDS9960_ENABLE , 1 )
204
204
"""Color detection enable flag.
205
205
True when color detection is enabled, else False"""
206
- enable_proximity = RWBit (APDS9960_ENABLE , 2 )
206
+ enable_proximity = RWBit (_APDS9960_ENABLE , 2 )
207
207
"""Enable of proximity mode"""
208
- gesture_fifo_threshold = RWBits (2 , APDS9960_GCONF1 , 6 )
208
+ gesture_fifo_threshold = RWBits (2 , _APDS9960_GCONF1 , 6 )
209
209
"""Gesture fifo threshold value: range 0-3"""
210
- gesture_gain = RWBits (2 , APDS9960_GCONF2 , 5 )
210
+ gesture_gain = RWBits (2 , _APDS9960_GCONF2 , 5 )
211
211
"""Gesture gain value: range 0-3"""
212
- color_gain = RWBits (2 , APDS9960_CONTROL , 0 )
212
+ color_gain = RWBits (2 , _APDS9960_CONTROL , 0 )
213
213
"""Color gain value"""
214
- enable_proximity_interrupt = RWBit (APDS9960_ENABLE , 5 )
214
+ enable_proximity_interrupt = RWBit (_APDS9960_ENABLE , 5 )
215
215
"""Proximity interrupt enable flag. True if enabled,
216
216
False to disable"""
217
217
@@ -256,7 +256,7 @@ def gesture(self) -> int: # pylint: disable-msg=too-many-branches
256
256
self .buf129 = bytearray (129 )
257
257
258
258
buffer = self .buf129
259
- buffer [0 ] = APDS9960_GFIFO_U
259
+ buffer [0 ] = _APDS9960_GFIFO_U
260
260
if not self ._gesture_valid :
261
261
return 0
262
262
@@ -269,7 +269,7 @@ def gesture(self) -> int: # pylint: disable-msg=too-many-branches
269
269
gesture_received = 0
270
270
time .sleep (0.030 ) # 30 ms
271
271
272
- n_recs = self ._read8 (APDS9960_GFLVL )
272
+ n_recs = self ._read8 (_APDS9960_GFLVL )
273
273
if n_recs :
274
274
275
275
with self .i2c_device as i2c :
@@ -336,25 +336,25 @@ def gesture(self) -> int: # pylint: disable-msg=too-many-branches
336
336
@property
337
337
def gesture_dimensions (self ) -> int :
338
338
"""Gesture dimension value: range 0-3"""
339
- return self ._read8 (APDS9960_GCONF3 )
339
+ return self ._read8 (_APDS9960_GCONF3 )
340
340
341
341
@gesture_dimensions .setter
342
342
def gesture_dimensions (self , dims : int ) -> None :
343
- self ._write8 (APDS9960_GCONF3 , dims & 0x03 )
343
+ self ._write8 (_APDS9960_GCONF3 , dims & 0x03 )
344
344
345
345
@property
346
346
def color_data_ready (self ) -> int :
347
347
"""Color data ready flag. zero if not ready, 1 is ready"""
348
- return self ._read8 (APDS9960_STATUS ) & 0x01
348
+ return self ._read8 (_APDS9960_STATUS ) & 0x01
349
349
350
350
@property
351
351
def color_data (self ) -> Tuple [int , int , int , int ]:
352
352
"""Tuple containing r, g, b, c values"""
353
353
return (
354
- self ._color_data16 (APDS9960_CDATAL + 2 ),
355
- self ._color_data16 (APDS9960_CDATAL + 4 ),
356
- self ._color_data16 (APDS9960_CDATAL + 6 ),
357
- self ._color_data16 (APDS9960_CDATAL ),
354
+ self ._color_data16 (_APDS9960_CDATAL + 2 ),
355
+ self ._color_data16 (_APDS9960_CDATAL + 4 ),
356
+ self ._color_data16 (_APDS9960_CDATAL + 6 ),
357
+ self ._color_data16 (_APDS9960_CDATAL ),
358
358
)
359
359
360
360
### PROXIMITY
@@ -366,17 +366,17 @@ def proximity_interrupt_threshold(self) -> Tuple[int, int, int]:
366
366
zero to three values: low threshold, high threshold, persistance.
367
367
persistance defaults to 4 if not provided"""
368
368
return (
369
- self ._read8 (APDS9960_PILT ),
370
- self ._read8 (APDS9960_PIHT ),
369
+ self ._read8 (_APDS9960_PILT ),
370
+ self ._read8 (_APDS9960_PIHT ),
371
371
self ._proximity_persistance ,
372
372
)
373
373
374
374
@proximity_interrupt_threshold .setter
375
375
def proximity_interrupt_threshold (self , setting_tuple : Tuple [int , ...]) -> None :
376
376
if setting_tuple :
377
- self ._write8 (APDS9960_PILT , setting_tuple [0 ])
377
+ self ._write8 (_APDS9960_PILT , setting_tuple [0 ])
378
378
if len (setting_tuple ) > 1 :
379
- self ._write8 (APDS9960_PIHT , setting_tuple [1 ])
379
+ self ._write8 (_APDS9960_PIHT , setting_tuple [1 ])
380
380
persist = 4 # default 4
381
381
if len (setting_tuple ) > 2 :
382
382
persist = min (setting_tuple [2 ], 7 )
@@ -385,29 +385,29 @@ def proximity_interrupt_threshold(self, setting_tuple: Tuple[int, ...]) -> None:
385
385
@property
386
386
def gesture_proximity_threshold (self ) -> int :
387
387
"""Proximity threshold value: range 0-255"""
388
- return self ._read8 (APDS9960_GPENTH )
388
+ return self ._read8 (_APDS9960_GPENTH )
389
389
390
390
@gesture_proximity_threshold .setter
391
391
def gesture_proximity_threshold (self , thresh : int ) -> None :
392
- self ._write8 (APDS9960_GPENTH , thresh & 0xFF )
392
+ self ._write8 (_APDS9960_GPENTH , thresh & 0xFF )
393
393
394
394
@property
395
395
def proximity (self ) -> int :
396
396
"""Proximity value: range 0-255"""
397
- return self ._read8 (APDS9960_PDATA )
397
+ return self ._read8 (_APDS9960_PDATA )
398
398
399
399
def clear_interrupt (self ) -> None :
400
400
"""Clear all interrupts"""
401
- self ._writecmdonly (APDS9960_AICLEAR )
401
+ self ._writecmdonly (_APDS9960_AICLEAR )
402
402
403
403
@property
404
404
def integration_time (self ) -> int :
405
405
"""Proximity integration time: range 0-255"""
406
- return self ._read8 (APDS9960_ATIME )
406
+ return self ._read8 (_APDS9960_ATIME )
407
407
408
408
@integration_time .setter
409
409
def integration_time (self , int_time : int ) -> None :
410
- self ._write8 (APDS9960_ATIME , int_time & 0xFF )
410
+ self ._write8 (_APDS9960_ATIME , int_time & 0xFF )
411
411
412
412
# method for reading and writing to I2C
413
413
def _write8 (self , command : int , abyte : int ) -> None :
0 commit comments