Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

relic-se
Copy link
Contributor

Relatively simple fix here. The changes are as follows:

  • BootMouse.update returns a tuple (immutable) rather than a list object
  • If the device reads successfully and no buttons are pressed, an empty tuple is returned rather than None
  • If an error is encountered during the device read, None is returned

Fixes #8

Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the improvements! This looks good to me, I tested successfully on Fruit Jam 10.0.0-beta.3 with the simpletest from this repo.

If it turns out that creating tuples in the main loop ends up leading to excessive GC action, it may be worth considering changing update() to return an int with bits that correspond to the buttons that are pressed instead of a list. It would make the API a little less "pythonic" but would mean that there is no tuple or list getting created by it in the main loop.

@FoamyGuy FoamyGuy merged commit 1b3bee5 into adafruit:main Sep 24, 2025
1 check passed
@relic-se relic-se deleted the usb-errors branch September 24, 2025 22:32
@relic-se
Copy link
Contributor Author

If it turns out that creating tuples in the main loop ends up leading to excessive GC action, it may be worth considering changing update() to return an int with bits that correspond to the buttons that are pressed instead of a list. It would make the API a little less "pythonic" but would mean that there is no tuple or list getting created by it in the main loop.

My (potentially incorrect) understanding was that tuples were more performant and used less memory than lists, but yes, using an integer would be even better.

How I managed this in my recent relic_usb_host_gamepad library was to keep a private integer within the object which is updated during update. Then, I added boolean properties which test the integer with a bitmask to determine if the button was pressed when the mouse was last updated. Since gamepads have a whole lot of buttons, I got a little more fancy using descriptors and changed states, but that might not be necessary here.

This would look something along the lines of:

while True:
    if mouse.update():  # True if successfully read from mouse
        if mouse.left_button:  # tests against internal integer
            print("left button pressed")
        if mouse.right_button:
            print("right button pressed")

If this is how you'd like to see this working, I could draft up something along these lines.

adafruit-adabot pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Sep 25, 2025
Updating https://github.com/adafruit/Adafruit_CircuitPython_EPD to 2.16.0 from 2.15.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_EPD#97 from adafruit/uc8179_tricolor

Updating https://github.com/adafruit/Adafruit_CircuitPython_USB_Host_Mouse to 1.3.1 from 1.3.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_USB_Host_Mouse#9 from relic-se/usb-errors

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Added the following libraries: Adafruit_CircuitPython_SPA06_003
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

USB Errors
2 participants