Skip to content

Commit 69082fc

Browse files
committed
fixed buffer not being allocated bug and read only whats available
1 parent 058f088 commit 69082fc

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

adafruit_apds9960/apds9960.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
APDS9960_GPULSE = const(0xA6)
8282
APDS9960_GCONF3 = const(0xAA)
8383
APDS9960_GCONF4 = const(0xAB)
84-
# APDS9960_GFLVL = const(0xAE)
84+
APDS9960_GFLVL = const(0xAE)
8585
APDS9960_GSTATUS = const(0xAF)
8686
# APDS9960_IFORCE = const(0xE4)
8787
# APDS9960_PICLEAR = const(0xE5)
@@ -189,7 +189,7 @@ def gesture(self): #pylint: disable-msg=too-many-branches
189189
=1 if an UP, =2 if a DOWN, =3 if an LEFT, =4 if a RIGHT
190190
"""
191191
# buffer to read of contents of device FIFO buffer
192-
if self.buf129:
192+
if not self.buf129:
193193
self.buf129 = bytearray(129)
194194

195195
buffer = self.buf129
@@ -207,9 +207,13 @@ def gesture(self): #pylint: disable-msg=too-many-branches
207207

208208
time.sleep(0.030) # 30 ms
209209

210+
n_recs = self._read8(APDS9960_GFLVL)
211+
if not n_recs:
212+
continue
213+
210214
with self.i2c_device as i2c:
211215
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))
213217
upp, down, left, right = buffer[1:5]
214218

215219
if abs(upp - down) > 13:

0 commit comments

Comments
 (0)