V4L2: Get device/input status - c++

Maybe anybody will know the answer to the next question...
I have plugged in usb digital camera (it has one input pin - 0).
I check input status every 5 seconds via structure: v4l2_input (here is the example: http://pastebin.com/FFvNAkQ3), to process situation if one of the flags is set (V4L2_IN_ST_NO_POWER or V4L2_IN_ST_NO_SIGNAL or V4L2_IN_ST_NO_H_LOCK).
The problem is that even i unplug my usb digital camera, the input status is always 0 (0x00). Why the driver does not change input status flag when the device is unplugged?
Maybe it is possible to check device status not only input pin? If yes, then which ioctl request should be set...?

Related

Get HID report Descriptor from .pcap file

I am building a C++ app on windows that should reinterpret USB data stream captured by Wireshark and USBPCap stored into a .pcap file. I am currently having trouble to get HID Report descriptor, so then i would be able to interpret data that mouse sends to the host.
The site USB Made Simple has been a great source of information so far, and i have also read a tons of tutorials how to write your own HID Report descriptor in order to understand them. But what i need is to retrieve one from current data flow.
According to wireshark, mouse is sending me a DEVICE DESCRIPTOR (example here), after that it sends CONFIGURATION DESCRIPTOR with its INTERFACE, HID and ENDPOINT DESCRIPTORS (example here).
According to value of wDescriptorLength in HID DESCRIPTOR, there should be HID REPORT DESCRIPTOR of length 56, but there is not. After this there is only ENDPOINT DESCRIPTOR of length 7 and another INTERFACE and HID DESCRIPTOR of total lenght 18.
Is there any way to get HID REPORT DESCRIPTOR from this or am I missing something out ?
Thank you for any input.
Is there any way to get HID REPORT DESCRIPTOR from this or am I missing something out ?
Don't know about you but for me that looks like Wireshark/USBPCap is missing something.
If you compare it with mine example it looks like entries with USBHID protocol are missing in your part.
Please check your Wireshark version or if you don't have enabled any filters in capture configuration.
If you click 'gear' icon on the left side of USBPcap interface you can check your current settings:
Important note:
Despite fact that "Inject already connected devices descriptors..." is checked it doesn't work for me like I would expect and to capture Report Descriptor you have to reconnect device: unplug USB-HID device -> Start capture -> Plug in USB device -> Now you can stop capture.
You should be able to use the Win32 HID-parse utilities to do this:
https://learn.microsoft.com/en-us/windows-hardware/drivers/hid/preparsed-data
See here for an example of use, where the HID report is accessed using WM_INPUT:
https://github.com/supersmo/Using-Raw-Input-API-to-Process-Joystick-Input
...in particular these methods:
// determine buffer size required
CHECK( GetRawInputDeviceInfo(pRawInput->header.hDevice, RIDI_PREPARSEDDATA, NULL, &bufferSize) == 0 );
// allocate buffer
CHECK( pPreparsedData = (PHIDP_PREPARSED_DATA)HeapAlloc(hHeap, 0, bufferSize) );
// determine the usages etc
CHECK( (int)GetRawInputDeviceInfo(pRawInput->header.hDevice, RIDI_PREPARSEDDATA, pPreparsedData, &bufferSize) >= 0 );
// Button caps
CHECK( HidP_GetCaps(pPreparsedData, &Caps) == HIDP_STATUS_SUCCESS )
// Value caps
CHECK( pValueCaps = (PHIDP_VALUE_CAPS)HeapAlloc(hHeap, 0, sizeof(HIDP_VALUE_CAPS) * Caps.NumberInputValueCaps) );
capsLength = Caps.NumberInputValueCaps;
CHECK( HidP_GetValueCaps(HidP_Input, pValueCaps, &capsLength, pPreparsedData) == HIDP_STATUS_SUCCESS )
Another thing to look at is the ReactOS hidusb source which can be found (today) here:
https://doxygen.reactos.org/dd/d06/hidusb_8c_source.html
...pay particular attention to e.g. HidUsb_GetReportDescriptor
Hope this points you in the right direction.

windows: detect same device on both bluetooth api and setupapi

I'm currently creating a program that's divided in two parts, one where I detect nearby bluetooth devices and connect them to the pc if the name match and the other where I search for the device with setupapi and get an handle for HID comunication.
My problem is that I cannot find anything that tells me that the device I just connected is the same I found in setupapi.
So in the first part I have something like this:
BLUETOOTH_DEVICE_INFO btdi;
//--- Code omitted ---
BluetoothGetDeviceInfo(radio_handle, &btdi);
if(std::wstring(btdi.szName) == /*my name*/)
// Device found! now connect
BluetoothSetServiceState(radio_handle, &btdi, &HumanInterfaceDeviceServiceClass_UUID, BLUETOOTH_SERVICE_ENABLE);
And the setupapi related code:
SP_DEVICE_INTERFACE_DATA device_data;
device_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
//--- Code omitted ---
SetupDiEnumDeviceInterfaces(device_infos, NULL, &hid_guid, index, &device_data);
I was thinking about using the bluetooth address of the device but there seem to be no way to get that from setupapi.
So, to recap, is there any way to get the address of the device from setupi? And, if not, is there any other way to be sure that they're both the same device?
Here I posted the code how to find Wiimote connected as HID using its MAC. You have to rework that code so it can use your HID device (change VID and PID).

cv::videocapture can't open available USB cameras

I'm trying to connect to several USB cameras that are connected to different USB buses (hopefully cancelling the bandwidth bottleneck caused by the USB).
Before accessing to the cameras, I'm probing them with V4L2 API directly to see if they're accessible. For now, there are 3 cameras and V4L2 sees them all.
Then I'm trying to access them using openCV like this, each in its own object:
this->camera = new cv::VideoCapture(camera_port);
if(this->camera->isOpened()) {
....
cv::Mat capturedImage;
bool read;
read = this->camera->read(capturedImage);
....
}
where camera_port is 0,1,2.
Obviously this->camera is called with release() on program closure.
The problem arises when I'm accessing more than 1 camera. Only one camera out of the three returns an image. The others return errors that I'm seeing on the console (not the same on every run):
libv4l2: error turning on stream: Connection timed out,
VIDIOC_STREAMON: Connection timed out
libv4l2: error turning on stream: Input/output error,
VIDIOC_STREAMON: Input/output error
libv4l2: error turning on stream: Invalid argument,
VIDIOC_STREAMON: Invalid argument
Some other errors, but the above are the most frequent
However, this does work on the first run after replugging-in the USB cameras, but not on further runs of the program.
Thoughts?

How to set bus on apple's AudioUnit 3D Mixer?

I'm trying to figure out how to query or setup which sound is connected to which bus input of the 3D Mixer. Say I have an explosion sound, is there a way to specifically set which bus that sound will be located on for future reference?
Assuming you are working with an AUGraph(), this is pretty straightforward:
Just connect the node to the desired busNumber of the mixer.
// connect the file player's output to the mixer's input
checkResult( AUGraphConnectNodeInput(audioGraph,
filePlayerNode,
0,
mixerNode,
1, // this is the first bus #1 "AUGraphConnectNodeInput(filePlayer:out -> mixer:in");

How to read the temperature from sensors on the motherboard?

Trying to get the temperature of the processor.
Have already tried using WQL (WMI class MSAcpi_ThermalZoneTemperature), but apparently it is not implemented for all the platforms yet. On most of the machines it simply returns every existing error message via HRESULT return value. The temperature itself is not returned.
The idea is to read this temperature directly via the bus port. I have found the library, which gives the functionality of outp and inp functions, and with it managed to start initiate the connection (NTPort), however, the question becomes which port to connect to in order to read the data. The microcontroller is IT8728F. SpeedFan (the application that is able to read the temperature) in its logs says that it reads the data from port 0x290. However, when connecting to it, the data that comes back does not look like temperature (it always returns 29).
So what the next thing that was tried was to read from whatever port, trying to determine if any data that came through looked like temperature. However, from every port some data came through that was either too low or too high to be the real temperature.
int CPU_TEMP;
Outp(INDEX, BANK_SET);
Outp(DATA, Inp(DATA)|0x01);
for(CPU_TEMP=0x0;CPU_TEMP<0x999;CPU_TEMP++)
{
Outp(INDEX, CPU_TEMP);
printf("CPU temp: %iC\n", Inp(DATA));
}
maybe your processor is 29 degrees Celsius and stable. That seems legit for a processor.
Also: is that 0x00000029 or DEC 29? that makes a big difference