-
Notifications
You must be signed in to change notification settings - Fork 11
update read speeds when using the properties - fix #2 #18
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
Conversation
Look at the approach I've pushed here: The |
You asked to separate the issue out, so I was trying to fix the data read issue first. I don't think there is an issue with the property method once the data read issue is solved, which I believe the proposed method in this PR solves that. I think the your proposed approach will still cause the slowness in the data read if a user uses Have you tested the two versions of the code with the original Here is mine with the Classic Controller as well. https://github.com/jfurcean/CircuitPython_WiiChuck It seems to me to be much cleaner without the values property and the tuple unpacking |
Yep, thanks for making this new PR. Here we are just focused on the slowness issue. The current library definitely has issues with that. I did try the mouse example with the existing library, your PR, and the version I linked above. The current library is slow. Your PR is noticeably faster. Same for the version I linked. The version I linked is an example that takes the approach suggested here: While your PR does improve the performance relative to the existing library, it introduces new issues. Consider this simple example: import board
import adafruit_nunchuk
nc = adafruit_nunchuk.Nunchuk(board.I2C())
while True:
print(nc.joystick) Using your PR code, it behaves like this:
Yes it is faster. But it returns lots of duplicate data. For the analog mouse example, that generally doesn't matter, since it doesn't show up in any noticeable way. But that behavior could be an issue for other use cases. Using the version of the code I linked above, it behaves like this:
Which is the more expected behavior. I think it will be overly complex to provide both property access and speed and make it happen automagically. More logic would be needed to prevent the behavior shown above. Another option might be to have a manual while True:
nc.update()
x, y = nc.joystick
if nc.button_C:
print("button C pressed")
# etc Needing to call |
I am not sure I agree about that the 'duplicate data' is an issue. This same things happens with buttons in any circuit python code. I think this actually producing what is expected. Individuals using the libraries would need to handle the issue just like the c and z buttons are handled. The last approach is exactly how the Arduino library handles it and I believe it will end up producing the same results as this PR. I agree that it is clunky though and why I didn't suggest it. [edit] I think the update() approach might be the best solution. |
There might be an issue with the use of time.monotonic() as in CircuitPython, with some MCU, the precision of that function change over time... https://learn.adafruit.com/clue-sensor-plotter-circuitpython/time-in-circuitpython |
Yeah, the update() method is probably the best current solution. This will align with the similar Arduino library as well. |
This commit should help with the issue raised in #2. You should notice improved performance using the
examples/nunchuk_analog_mouse.py
example.