-
Notifications
You must be signed in to change notification settings - Fork 11
Limit reads & cache values #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This would simply report back the previous state unless |
I'm going to use this issue thread to document some sniffing of I2C traffic between a Wiimote and a Nunchuk. This information may prove useful for "tuning" the i2C specifics for this driver. This issue thread relates to the general slowness of the current read implemented in the driver. This is caused by the injection of hardwired sleeps. A single read takes 10's of ms as a result. Those delays were taken from existing Arduino libraries which did the same, and just generally accepted as necessary at the time of the initial writing of this driver. Blind attempts to reduce / remove them resulted in mixed success. So more information was needed. How does the original hardware, the Wiimote-Nunchuk combo, talk to each other? Let's find out... Hardware SetupBasic idea is to use a Pi 4 as a host and connect the Wiimote to it via Bluetooth. The Nunchuk cable was cut and a Nunchucky breakout was added to allow access to the pins. A Saleae was connected there. Software SetupUsed this python3-wiimote library, built locally on Pi. Connect to the Wiimote from the Pi. Ran things interactively: $ python3
Python 3.7.3 (default, Dec 20 2019, 18:57:59)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cwiid
>>> wiimote = cwiid.Wiimote()
>>> wiimote.rpt_mode = cwiid.RPT_BTN | cwiid.RPT_EXT
>>> wiimote.state
{'rpt_mode': 242, 'led': 1, 'rumble': 0, 'battery': 102, 'ext_type': 1, 'error': 0, 'buttons': 0, 'nunchuk': {'stick': (128, 129), 'acc': (73, 134, 142), 'buttons': 0}}
>>> wiimote.state['nunchuk']['stick']
(128, 129)
>>> etc. ResultsHere's a 1 second sample of the resulting traffic: Zooming in: Zooming in on an individual read: Here's the write request: Here's the read: Zooming in on the last read: Here's the trace file for future ref: |
The 9.5ms delay between reads is possibly the Wiimote's polling rate and not any kind of rate limit of the Nunchuk itself. The start-to-start time on reads is pretty much 10ms, which is a nice happy little round number for a polling IRQ running on the Wiimote. With the base read modified to be ( def _read_data(self):
with self.i2c_device as i2c:
i2c.write(b"\x00")
time.sleep(_I2C_READ_DELAY)
i2c.readinto(self.buffer) and running this spam read example on an Itsy M4: import board
import busio
import adafruit_nunchuk
i2c = busio.I2C(board.SCL, board.SDA, frequency=375000)
nc = adafruit_nunchuk.Nunchuk(i2c)
while True:
x, y = nc.joystick it seems to read just fine. This seems to indicate that there's no need for any extra delay between reads, from the Nunchuk's point of view. |
Closing this for now. I'm hoping the improvements from #20 make this no longer necessary. |
NOTE This issue by @ATMakersBill transferred from original repo.
It looks like there's code to read the i2c bus and keep the results for future calls to joystick, acceleration, and buttons. However, the button code doesn't seem to update the buffer.
It looks like it would be possible to make fewer reads and improve performance. Here's my suggestion....
I think that would give full control to the clients of the library.
The text was updated successfully, but these errors were encountered: