Skip to content
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

usb_hid.set_interface_name #8989

Merged
merged 3 commits into from
Mar 3, 2024
Merged

Conversation

MariuszCwikla
Copy link

@MariuszCwikla MariuszCwikla commented Feb 28, 2024

By default on Windows HID device is seen as CircuitPython HID, see also #5445

This PR adds new method usb_hid.set_interface_name that provides means to change the name of USB HID interface.

Example:

usb_hid.set_interface_name("My HID device")
$ sudo lsusb -vd 239A:80F4 | grep iInterface
      iInterface              4 CircuitPython CDC control
      iInterface              5 CircuitPython CDC data
      iInterface              6 CircuitPython Mass Storage
      iInterface              7 My HID device
      iInterface              9 CircuitPython Audio
      iInterface              8 CircuitPython MIDI

On Windows the device is now seen as:

circuitpython-hid

I have tested it with Raspberry Pico.

@MariuszCwikla MariuszCwikla mentioned this pull request Feb 28, 2024
Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

Thank you for this! It's been asked for several times.

I've added some comments, especially about storage management.

shared-bindings/usb_hid/__init__.c Outdated Show resolved Hide resolved
shared-module/usb_hid/Device.c Outdated Show resolved Hide resolved
shared-module/usb_hid/Device.h Outdated Show resolved Hide resolved
@dhalbert
Copy link
Collaborator

Note the pre-commit failure. If you install pre-commit locally, it will catch these before you commit: https://learn.adafruit.com/building-circuitpython/build-circuitpython#install-pre-commit-3096511

Co-authored-by: Dan Halbert <halbert@halwitz.org>
@MariuszCwikla
Copy link
Author

Hi @dhalbert,
thank you for your comments.
I just pushed requested changes.

@dhalbert dhalbert linked an issue Mar 3, 2024 that may be closed by this pull request
Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

Thank you for this! It's been requested a number of times.

Tested on Trinket M0

@dhalbert dhalbert merged commit ffa45de into adafruit:main Mar 3, 2024
414 checks passed
@dhalbert dhalbert mentioned this pull request Mar 3, 2024
@vospascal
Copy link

this wouldnt allow to have multiple deviced having different names right ?
from my understanding thats where the VID (vendor )and PID (product) parts come in
if i would like 4 devices with different names i would need 4 unique PID's

@vospascal
Copy link

image
still under same vid/pid so its for all the devices then

@vospascal
Copy link

vospascal commented Jun 15, 2024

@MariuszCwikla you think we could do something with the pid and vid some how to make devices unique for local machine
cause now just as well edit the regex right? same result since its cached by windows

@dhalbert
Copy link
Collaborator

dhalbert commented Jun 15, 2024

No, there is only one VID/PID, becuase there is only one (composite) device presented.

@vospascal
Copy link

vospascal commented Jun 15, 2024

No, there is only one VID/PID, becuase there is only one (composite) device presented.

i found it in mpconfigboard.mk of my board thank you
does mean i need to build circuitpython

@dhalbert
Copy link
Collaborator

@vospascal
Copy link

thanks a lot Dan i was already almost done making custom builds in github ci..
how can i not have seen that ...

my solution

from hid_gamepad.simple.boot import gamepad_descriptor
import usb_hid
import supervisor

# Define custom VID, PID, product name, and manufacturer
CUSTOM_VID = 0xDDFD  # Non-registered VID
CUSTOM_PID = 0x5050  # Non-registered PID
PRODUCT_NAME = "SUNSHINE"
MANUFACTURER_NAME = "Good mood"

# Set USB identification
supervisor.set_usb_identification(vid=CUSTOM_VID, pid=CUSTOM_PID, manufacturer=MANUFACTURER_NAME, product=PRODUCT_NAME)


# Enable HID devices including the custom gamepad descriptor
usb_hid.enable(
    (usb_hid.Device.KEYBOARD,
     usb_hid.Device.MOUSE,
     usb_hid.Device.CONSUMER_CONTROL,
     gamepad_descriptor)
)

# Set interface name for the gamepad
usb_hid.set_interface_name("Good mood")

# Only use the gamepad
usb_hid.enable((gamepad_descriptor,))

this solved it for me now i got unique pid and vid and name in my regex editor

@MariuszCwikla
Copy link
Author

Yes, you should assign your VID/PID like in above example.
Windows caches name of VID/PID in the registry, so you might not see the change unless you clean registry or assign your own VID/PID. See also #9130 (comment)

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.

Rename HID device
3 participants