@@ -112,6 +112,9 @@ def __init__(self,
112
112
integration_time = 0x01 ,
113
113
gain = 0x01 ):
114
114
115
+ self .buf129 = None
116
+ self .buf2 = bytearray (2 )
117
+
115
118
self .i2c_device = I2CDevice (i2c , address )
116
119
self ._interrupt_pin = interrupt_pin
117
120
if interrupt_pin :
@@ -142,7 +145,6 @@ def __init__(self,
142
145
# gesture pulse length=0x2 pulse count=0x3
143
146
self ._write8 (APDS9960_GPULSE , (0x2 << 6 ) | 0x3 )
144
147
145
-
146
148
## BOARD
147
149
def _reset_counts (self ):
148
150
"""Gesture detection internal counts"""
@@ -187,7 +189,10 @@ def gesture(self): #pylint: disable-msg=too-many-branches
187
189
=1 if an UP, =2 if a DOWN, =3 if an LEFT, =4 if a RIGHT
188
190
"""
189
191
# buffer to read of contents of device FIFO buffer
190
- buffer = bytearray (129 )
192
+ if self .buf129 :
193
+ self .buf129 = bytearray (129 )
194
+
195
+ buffer = self .buf129
191
196
buffer [0 ] = APDS9960_GFIFO_U
192
197
if not self ._gesture_valid :
193
198
return 0
@@ -331,32 +336,32 @@ def integration_time(self, int_time):
331
336
# method for reading and writing to I2C
332
337
def _write8 (self , command , abyte ):
333
338
"""Write a command and 1 byte of data to the I2C device"""
334
- buf = bytearray ( 2 )
339
+ buf = self . buf2
335
340
buf [0 ] = command
336
341
buf [1 ] = abyte
337
342
with self .i2c_device as i2c :
338
343
i2c .write (buf )
339
344
340
345
def _writecmdonly (self , command ):
341
346
"""Writes a command and 0 bytes of data to the I2C device"""
342
- buf = bytearray ( 1 )
347
+ buf = self . buf2
343
348
buf [0 ] = command
344
349
with self .i2c_device as i2c :
345
- i2c .write (buf )
350
+ i2c .write (buf , end = 1 )
346
351
347
352
def _read8 (self , command ):
348
353
"""Sends a command and reads 1 byte of data from the I2C device"""
349
- buf = bytearray ( 1 )
354
+ buf = self . buf2
350
355
buf [0 ] = command
351
356
with self .i2c_device as i2c :
352
- i2c .write (buf )
353
- i2c .readinto (buf )
357
+ i2c .write (buf , end = 1 )
358
+ i2c .readinto (buf , end = 1 )
354
359
return buf [0 ]
355
360
356
361
def _color_data16 (self , command ):
357
362
"""Sends a command and reads 2 bytes of data from the I2C device
358
363
The returned data is low byte first followed by high byte"""
359
- buf = bytearray ( 2 )
364
+ buf = self . buf2
360
365
buf [0 ] = command
361
366
with self .i2c_device as i2c :
362
367
i2c .write (buf , end = 1 , stop = False )
0 commit comments