Detect hardware button events on a USB camera
-
Hi,
I'm trying to develop a desktop app with QML on Qt 5.2 that controls a USB-attached camera. I can already control the camera with software buttons, but want to have access to the camera's hardware button (it has one for shutter) too.
Since there are no hardware-related functionalities in Qt's camera API (either QCamera and the QML Camera element), my first thought was to read the button myself. I put together some simple C++ that reads the device on LibUSB, and it worked well enough—on its own. I found that when I tried to integrate the two parts together, Qt's camera API would spit out "Failed to create video device input" and stop working altogether.
I'm not very familiar with LibUSB, to be honest. Is this caused by some ownership problem between Qt and my LibUSB code? If so, how do I resolve this? Or is there a completely different way of doing this without digging into raw USB communication on my own?
Thanks in advance.
-
I'm by no means an expert on this, but have been trying essentially the same thing. Only one process can access the USB device at one time, from my understanding, and thus you need to incorporate a mutex or some polling function that releases control of the video stream to check the button status. This does mean that you're going to be writing your own custom driver for the camera if it didn't come with one. If anyone with better understanding of QCamera and USB controls can chime in with assistance it'd be appreciated.
-
This post is deleted! -
@uranusjr Hi, I have met the same problem. I wonder if you have solved it!
-
Hi @Felix.Yin
Only one process can access the USB device at one time
I think the problem is, once you opened the connection to the camera, a second access is not possible.
The solution would be, IMHO,, to modify the Qt camera code to add the new functions. You can do this for your own Qt copy (mind the GPL: you have to release the sources or use a commercial license!) or even propose a change in the official Qt API.
(This is just my bird's view of understanding, I have not looked up the Qt camera code).
Regards
-
@aha_1980 Thank you for your advice. It seems libusb is dead.
I have a search for a solution on linux https://stackoverflow.com/questions/29355100/uvc-camera-still-pin-capture-in-linux-c
But there is no libevdev on osx.