81
81
APDS9960_GPULSE = const (0xA6 )
82
82
APDS9960_GCONF3 = const (0xAA )
83
83
APDS9960_GCONF4 = const (0xAB )
84
- # APDS9960_GFLVL = const(0xAE)
84
+ APDS9960_GFLVL = const (0xAE )
85
85
APDS9960_GSTATUS = const (0xAF )
86
86
# APDS9960_IFORCE = const(0xE4)
87
87
# APDS9960_PICLEAR = const(0xE5)
@@ -189,7 +189,7 @@ def gesture(self): #pylint: disable-msg=too-many-branches
189
189
=1 if an UP, =2 if a DOWN, =3 if an LEFT, =4 if a RIGHT
190
190
"""
191
191
# buffer to read of contents of device FIFO buffer
192
- if self .buf129 :
192
+ if not self .buf129 :
193
193
self .buf129 = bytearray (129 )
194
194
195
195
buffer = self .buf129
@@ -207,9 +207,13 @@ def gesture(self): #pylint: disable-msg=too-many-branches
207
207
208
208
time .sleep (0.030 ) # 30 ms
209
209
210
+ n_recs = self ._read8 (APDS9960_GFLVL )
211
+ if not n_recs :
212
+ continue
213
+
210
214
with self .i2c_device as i2c :
211
215
i2c .write (buffer , end = 1 , stop = False )
212
- i2c .readinto (buffer , start = 1 )
216
+ i2c .readinto (buffer , start = 1 , end = min ( 129 , 1 + n_recs * 4 ) )
213
217
upp , down , left , right = buffer [1 :5 ]
214
218
215
219
if abs (upp - down ) > 13 :
0 commit comments