Reading HID Bluetooth devices' buffer on Win32
-
I'm exploring Win32's HID API to read/write from/to various devices. So far, I've been able to read responsive input for two wired devices -- an XBOX 360 Compliant controller and a steering wheel. This is good, but buffers filled by reading Bluetooth HID devices with
ReadFile
are not updating with user input. I've been able to test two devices: an Xbox One Wireless Controller(VID=045E,PID=02E0), and an Xbox One S Controller [Bluetooth](VID=045E,PID=02FD). What could be causing this? Are there any specific things that must be done before/while reading a Bluetooth HID device? Some notes: • RawInput does not seem to be usable without a window(i.e., in a pure console program), since it requires WM_INPUT messages to function. • XInput seems to exclusively support Xbox controllers. May use it for Xbox controllers specifically(especially for trigger separation). • Have not explored DirectInput for controllers yet. Unsure if it's useable for modern controllers(including bluetooth-based ones). Here's the current code setup. Code notes: • The end goal is to read/write inputs for real-time programs(e.g., games). • Tangentially, I'm not very experienced with Win32 and its file handling, so there's probably some issues with the general usage. Code of interestif(isXOneX){
HANDLE deviceHandle = CreateFile(devicePath,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL);
PHIDP_PREPARSED_DATA preparsedData;
HidD_GetPreparsedData(deviceHandle,&preparsedData);
HIDP_CAPS caps;
HidP_GetCaps(preparsedData,&caps);
HIDP_BUTTON_CAPS hidpButtonCaps[caps.NumberInputButtonCaps];
HidP_GetButtonCaps(HIDP_REPORT_TYPE::HidP_Input,&hidpButtonCaps[0],&caps.NumberInputButtonCaps,preparsedData);
DWORD reportId = hidpButtonCaps[0].ReportID;
auto inputReportBufferLength = caps.InputReportByteLength+1;//+1 for report ID
BYTE inputReportBuffer[inputReportBufferLength];
while(true){
OVERLAPPED overlapped;
memset(&overlapped, 0, sizeof(overlapped));
if(ReadFileEx(deviceHandle, &inputReportBuffer[0], inputReportBufferLength, &overlapped, NULL)){
DWORD bytesTransferred;
if(GetOverlappedResult(deviceHandle, &overlapped, &bytesTransferred, FALSE)){
for(auto i=0;i