42
42
# INTEGRATION_TIME_DEF = const(0x01)
43
43
# GAIN_DEF = const(0x01)
44
44
45
- #pylint: disable-msg=bad-whitespace
46
- #APDS9960_RAM = const(0x00)
47
- APDS9960_ENABLE = const (0x80 )
48
- APDS9960_ATIME = const (0x81 )
49
- #APDS9960_WTIME = const(0x83)
50
- #APDS9960_AILTIL = const(0x84)
45
+ # pylint: disable-msg=bad-whitespace
46
+ # APDS9960_RAM = const(0x00)
47
+ APDS9960_ENABLE = const (0x80 )
48
+ APDS9960_ATIME = const (0x81 )
49
+ # APDS9960_WTIME = const(0x83)
50
+ # APDS9960_AILTIL = const(0x84)
51
51
# APDS9960_AILTH = const(0x85)
52
52
# APDS9960_AIHTL = const(0x86)
53
53
# APDS9960_AIHTH = const(0x87)
54
- APDS9960_PILT = const (0x89 )
55
- APDS9960_PIHT = const (0x8B )
56
- APDS9960_PERS = const (0x8C )
54
+ APDS9960_PILT = const (0x89 )
55
+ APDS9960_PIHT = const (0x8B )
56
+ APDS9960_PERS = const (0x8C )
57
57
# APDS9960_CONFIG1 = const(0x8D)
58
58
# APDS9960_PPULSE = const(0x8E)
59
- APDS9960_CONTROL = const (0x8F )
59
+ APDS9960_CONTROL = const (0x8F )
60
60
# APDS9960_CONFIG2 = const(0x90)
61
- APDS9960_ID = const (0x92 )
62
- APDS9960_STATUS = const (0x93 )
63
- APDS9960_CDATAL = const (0x94 )
61
+ APDS9960_ID = const (0x92 )
62
+ APDS9960_STATUS = const (0x93 )
63
+ APDS9960_CDATAL = const (0x94 )
64
64
# APDS9960_CDATAH = const(0x95)
65
65
# APDS9960_RDATAL = const(0x96)
66
66
# APDS9960_RDATAH = const(0x97)
67
67
# APDS9960_GDATAL = const(0x98)
68
68
# APDS9960_GDATAH = const(0x99)
69
69
# APDS9960_BDATAL = const(0x9A)
70
70
# APDS9960_BDATAH = const(0x9B)
71
- APDS9960_PDATA = const (0x9C )
71
+ APDS9960_PDATA = const (0x9C )
72
72
# APDS9960_POFFSET_UR = const(0x9D)
73
73
# APDS9960_POFFSET_DL = const(0x9E)
74
74
# APDS9960_CONFIG3 = const(0x9F)
75
- APDS9960_GPENTH = const (0xA0 )
75
+ APDS9960_GPENTH = const (0xA0 )
76
76
# APDS9960_GEXTH = const(0xA1)
77
- APDS9960_GCONF1 = const (0xA2 )
78
- APDS9960_GCONF2 = const (0xA3 )
77
+ APDS9960_GCONF1 = const (0xA2 )
78
+ APDS9960_GCONF2 = const (0xA3 )
79
79
# APDS9960_GOFFSET_U = const(0xA4)
80
80
# APDS9960_GOFFSET_D = const(0xA5)
81
81
# APDS9960_GOFFSET_L = const(0xA7)
82
82
# APDS9960_GOFFSET_R = const(0xA9)
83
- APDS9960_GPULSE = const (0xA6 )
84
- APDS9960_GCONF3 = const (0xAA )
85
- APDS9960_GCONF4 = const (0xAB )
86
- APDS9960_GFLVL = const (0xAE )
87
- APDS9960_GSTATUS = const (0xAF )
83
+ APDS9960_GPULSE = const (0xA6 )
84
+ APDS9960_GCONF3 = const (0xAA )
85
+ APDS9960_GCONF4 = const (0xAB )
86
+ APDS9960_GFLVL = const (0xAE )
87
+ APDS9960_GSTATUS = const (0xAF )
88
88
# APDS9960_IFORCE = const(0xE4)
89
89
# APDS9960_PICLEAR = const(0xE5)
90
90
# APDS9960_CICLEAR = const(0xE6)
91
- APDS9960_AICLEAR = const (0xE7 )
92
- APDS9960_GFIFO_U = const (0xFC )
91
+ APDS9960_AICLEAR = const (0xE7 )
92
+ APDS9960_GFIFO_U = const (0xFC )
93
93
# APDS9960_GFIFO_D = const(0xFD)
94
94
# APDS9960_GFIFO_L = const(0xFE)
95
95
# APDS9960_GFIFO_R = const(0xFF)
96
- #pylint: enable-msg=bad-whitespace
96
+ # pylint: enable-msg=bad-whitespace
97
97
98
98
99
- #pylint: disable-msg=too-many-instance-attributes
99
+ # pylint: disable-msg=too-many-instance-attributes
100
100
class APDS9960 :
101
101
"""
102
102
APDS9900 provide basic driver services for the ASDS9960 breakout board
@@ -107,12 +107,9 @@ class APDS9960:
107
107
_gesture_mode = RWBit (APDS9960_GCONF4 , 0 )
108
108
_proximity_persistance = RWBits (4 , APDS9960_PERS , 4 )
109
109
110
- def __init__ (self ,
111
- i2c , * ,
112
- interrupt_pin = None ,
113
- address = 0x39 ,
114
- integration_time = 0x01 ,
115
- gain = 0x01 ):
110
+ def __init__ (
111
+ self , i2c , * , interrupt_pin = None , address = 0x39 , integration_time = 0x01 , gain = 0x01
112
+ ):
116
113
117
114
self .buf129 = None
118
115
self .buf2 = bytearray (2 )
@@ -138,9 +135,9 @@ def __init__(self,
138
135
139
136
self .color_gain = gain
140
137
self .integration_time = integration_time
141
- self .gesture_dimensions = 0x00 # all
142
- self .gesture_fifo_threshold = 0x01 # fifo 4
143
- self .gesture_gain = 0x02 # gain 4
138
+ self .gesture_dimensions = 0x00 # all
139
+ self .gesture_fifo_threshold = 0x01 # fifo 4
140
+ self .gesture_gain = 0x02 # gain 4
144
141
self .gesture_proximity_threshold = 50
145
142
self ._reset_counts ()
146
143
@@ -155,7 +152,6 @@ def _reset_counts(self):
155
152
self ._saw_left_start = 0
156
153
self ._saw_right_start = 0
157
154
158
-
159
155
enable = RWBit (APDS9960_ENABLE , 0 )
160
156
"""Board enable. True to enable, False to disable"""
161
157
enable_color = RWBit (APDS9960_ENABLE , 1 )
@@ -186,7 +182,7 @@ def enable_gesture(self, enable_flag):
186
182
self ._gesture_mode = False
187
183
self ._gesture_enable = enable_flag
188
184
189
- def gesture (self ): # pylint: disable-msg=too-many-branches
185
+ def gesture (self ): # pylint: disable-msg=too-many-branches
190
186
"""Returns gesture code if detected. =0 if no gesture detected
191
187
=1 if an UP, =2 if a DOWN, =3 if an LEFT, =4 if a RIGHT
192
188
"""
@@ -206,14 +202,19 @@ def gesture(self): #pylint: disable-msg=too-many-branches
206
202
up_down_diff = 0
207
203
left_right_diff = 0
208
204
gesture_received = 0
209
- time .sleep (0.030 ) # 30 ms
205
+ time .sleep (0.030 ) # 30 ms
210
206
211
207
n_recs = self ._read8 (APDS9960_GFLVL )
212
208
if n_recs :
213
209
214
210
with self .i2c_device as i2c :
215
- i2c .write_then_readinto (buffer , buffer , out_end = 1 , in_start = 1 ,
216
- in_end = min (129 , 1 + n_recs * 4 ))
211
+ i2c .write_then_readinto (
212
+ buffer ,
213
+ buffer ,
214
+ out_end = 1 ,
215
+ in_start = 1 ,
216
+ in_end = min (129 , 1 + n_recs * 4 ),
217
+ )
217
218
upp , down , left , right = buffer [1 :5 ]
218
219
219
220
if abs (upp - down ) > 13 :
@@ -227,14 +228,14 @@ def gesture(self): #pylint: disable-msg=too-many-branches
227
228
# either leading edge of down movement
228
229
# or trailing edge of up movement
229
230
if self ._saw_up_start :
230
- gesture_received = 0x01 # up
231
+ gesture_received = 0x01 # up
231
232
else :
232
233
self ._saw_down_start += 1
233
234
elif up_down_diff > 0 :
234
235
# either leading edge of up movement
235
236
# or trailing edge of down movement
236
237
if self ._saw_down_start :
237
- gesture_received = 0x02 # down
238
+ gesture_received = 0x02 # down
238
239
else :
239
240
self ._saw_up_start += 1
240
241
@@ -243,14 +244,14 @@ def gesture(self): #pylint: disable-msg=too-many-branches
243
244
# either leading edge of right movement
244
245
# trailing edge of left movement
245
246
if self ._saw_left_start :
246
- gesture_received = 0x03 # left
247
+ gesture_received = 0x03 # left
247
248
else :
248
249
self ._saw_right_start += 1
249
250
elif left_right_diff > 0 :
250
251
# either leading edge of left movement
251
252
# trailing edge of right movement
252
253
if self ._saw_right_start :
253
- gesture_received = 0x04 # right
254
+ gesture_received = 0x04 # right
254
255
else :
255
256
self ._saw_left_start += 1
256
257
@@ -282,10 +283,12 @@ def color_data_ready(self):
282
283
@property
283
284
def color_data (self ):
284
285
"""Tuple containing r, g, b, c values"""
285
- return self ._color_data16 (APDS9960_CDATAL + 2 ), \
286
- self ._color_data16 (APDS9960_CDATAL + 4 ), \
287
- self ._color_data16 (APDS9960_CDATAL + 6 ), \
288
- self ._color_data16 (APDS9960_CDATAL )
286
+ return (
287
+ self ._color_data16 (APDS9960_CDATAL + 2 ),
288
+ self ._color_data16 (APDS9960_CDATAL + 4 ),
289
+ self ._color_data16 (APDS9960_CDATAL + 6 ),
290
+ self ._color_data16 (APDS9960_CDATAL ),
291
+ )
289
292
290
293
### PROXIMITY
291
294
@property
@@ -295,30 +298,31 @@ def proximity_interrupt_threshold(self):
295
298
When setting the proximity interrupt threshold values using a tuple of
296
299
zero to three values: low threshold, high threshold, persistance.
297
300
persistance defaults to 4 if not provided"""
298
- return self ._read8 (APDS9960_PILT ), \
299
- self ._read8 (APDS9960_PIHT ), \
300
- self ._proximity_persistance
301
+ return (
302
+ self ._read8 (APDS9960_PILT ),
303
+ self ._read8 (APDS9960_PIHT ),
304
+ self ._proximity_persistance ,
305
+ )
301
306
302
307
@proximity_interrupt_threshold .setter
303
308
def proximity_interrupt_threshold (self , setting_tuple ):
304
309
if setting_tuple :
305
310
self ._write8 (APDS9960_PILT , setting_tuple [0 ])
306
311
if len (setting_tuple ) > 1 :
307
312
self ._write8 (APDS9960_PIHT , setting_tuple [1 ])
308
- persist = 4 # default 4
313
+ persist = 4 # default 4
309
314
if len (setting_tuple ) > 2 :
310
315
persist = min (setting_tuple [2 ], 7 )
311
316
self ._proximity_persistance = persist
312
317
313
-
314
318
@property
315
319
def gesture_proximity_threshold (self ):
316
320
"""Proximity threshold value: range 0-255"""
317
321
return self ._read8 (APDS9960_GPENTH )
318
322
319
323
@gesture_proximity_threshold .setter
320
324
def gesture_proximity_threshold (self , thresh ):
321
- self ._write8 (APDS9960_GPENTH , thresh & 0xff )
325
+ self ._write8 (APDS9960_GPENTH , thresh & 0xFF )
322
326
323
327
@property
324
328
def proximity (self ):
@@ -336,7 +340,7 @@ def integration_time(self):
336
340
337
341
@integration_time .setter
338
342
def integration_time (self , int_time ):
339
- self ._write8 (APDS9960_ATIME , int_time & 0xff )
343
+ self ._write8 (APDS9960_ATIME , int_time & 0xFF )
340
344
341
345
# method for reading and writing to I2C
342
346
def _write8 (self , command , abyte ):
0 commit comments