0

Moving from the world of Embedded Micro controllers and C, to C++ with wxWidgets.

I've created a simple GUI program, using codeblocks and wxWidgets to interface with a USB Hid device I've made using the HIDAPI from signal11.

Using simple buttons, I can connect, disconnect and check firmware software versions on the device.

What I want to be able to do is have the GUI automatically detect if a device is present or not, so If I unplug my device the GUI responds (Greys everything out) or re enables everything when plugged in.

Is this something that needs a never ending thread to achieve, or is there a better way? I would usually do something like this in an interrupt routine on a micro controller, but am unsure of its equivalent on the desktop platform?

Xander
  • 1
  • 1
  • yes, it probably needs an never ending thread, that will notify the GUI about connecting/disconnecting USB. – Igor Oct 14 '16 at 14:22

1 Answers1

0

USB devices connections/disconnections are not handled by wxWidgets, so you will have to use platform-specific APIs for this and they vary depending on your platform. Under Windows, you actually don't need a background thread because you get these notifications in the form of Windows WM_DEVICECHANGE message, so you can simply override MSWHandleMessage() in the window for which you had previously asked Windows to send these messages to using RegisterDeviceNotification() and handle them there.

VZ.
  • 21,740
  • 3
  • 39
  • 42