Skip to content

Commit 953127a

Browse files
committed
faster read
1 parent c51d1f6 commit 953127a

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

adafruit_nunchuk.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,16 @@
4848
__version__ = "0.0.0-auto.0"
4949
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Nunchuk.git"
5050

51-
_DEFAULT_ADDRESS = 0x52
5251
_I2C_INIT_DELAY = 0.1
53-
_I2C_READ_DELAY = 0.01
5452

5553

5654
class Nunchuk:
5755
"""Class which provides interface to Nintendo Nunchuk controller."""
5856

59-
def __init__(self, i2c, address=_DEFAULT_ADDRESS):
60-
self.buffer = bytearray(6)
57+
def __init__(self, i2c, address=0x52, i2c_read_delay=0.002):
58+
self.buffer = bytearray(8)
6159
self.i2c_device = I2CDevice(i2c, address)
60+
self._i2c_read_delay = i2c_read_delay
6261
time.sleep(_I2C_INIT_DELAY)
6362
with self.i2c_device as i2c_dev:
6463
# turn off encrypted data
@@ -100,9 +99,7 @@ def _read_data(self):
10099

101100
def _read_register(self, address):
102101
with self.i2c_device as i2c:
103-
time.sleep(_I2C_READ_DELAY)
104102
i2c.write(address)
105-
time.sleep(_I2C_READ_DELAY)
103+
time.sleep(self._i2c_read_delay) # at least 200us
106104
i2c.readinto(self.buffer)
107-
time.sleep(_I2C_READ_DELAY)
108105
return self.buffer

0 commit comments

Comments
 (0)