Possible to send USB "message" when process exists #108
-
My app has a GUI component that talks to an embedded device (Pi Pico running embassy). The device waits for a "connection" from USB, and on a Pi Pico W also from TCP. Once a connection is started either on USB or TCP, it enters a message loop for that interface (USB, or TCP). When the host GUI "disconnects" (including when crashing, or killed) I would like the device to know, so it can exit the USB message loop and go back to waiting for a message from either USB or TCP, to facilitate other connections later. It's hard to catch all the possible exit causes in host code and send an explicit "disconnect" message. Is there any way to inform the device over USB that the host process "it was talking to" (that claimed the interface being used) has exited? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
The way to do this is is to have your descriptors specify two alternate settings for your interface:
After claiming the interface, use |
Beta Was this translation helpful? Give feedback.
-
That sounds ideal. I'll change the alt_setting I currently use from 0 to 1
and then try receiving the handler event in embassy.
Thanks for the tip!
Is that something worth documenting in the docs (or did I miss it?)?
…On Sun, Jan 12, 2025, 11:34 PM Kevin Mehall ***@***.***> wrote:
The way to do this is is to have your descriptors specify two alternate
settings for your interface:
- Alt setting 0 representing the disabled state with no endpoints
- Alt setting 1 representing the enabled state with any endpoints you
need
After claiming the interface, use .set_alt_setting(1) to switch to the
enabled state. The OS will automatically set the alt setting back to 0 when
the interface is released, even if the process is killed or crashes. Your
device will receive a SET_INTERFACE request when the alt setting is changed
in either direction, which is exposed as a Handler method in Embassy
<https://docs.embassy.dev/embassy-usb/git/default/trait.Handler.html#method.set_alternate_setting>
.
—
Reply to this email directly, view it on GitHub
<#108 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABKF4LDIZLIHQEVNS7IA4YD2KLUX7AVCNFSM6AAAAABVAK75CCVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCOBRGQ2TIOA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Fantastic, worked like a dream! |
Beta Was this translation helpful? Give feedback.
The way to do this is is to have your descriptors specify two alternate settings for your interface:
After claiming the interface, use
.set_alt_setting(1)
to switch to the enabled state. The OS will automatically set the alt setting back to 0 when the interface is released, even if the process is killed or crashes. Your device will receive a SET_INTERFACE request when the alt setting is changed in either direction, which is exposed as a Handler method in Embassy.