emulate xbox 360/one using a HID device - c++

I'm trying to emulate a xbox 360/one controller using a HID device that is already connected to the PC.
I can read data from it and I will have to map it to the XInput structure.
Is there another way to do this without building a virtual driver to simulate a game-pad and using a feeder to send in the input from my own HID device?
Development is done using Qt5.4 and C++.

Related

Pairing bluetooth mobile device and send data to windows application using c++ in visual studio

I am still new to c++ and winsock stuff. I want to make a MFC application in c++ language with functionality of connecting to a mobile device and transfer data between the PC and mobile device. I cannot find much information on the internet regarding this topic, or maybe is because I am too new this c++ and MFC application, thus having trouble implementing these libraries. I want to start from scanning and discovering nearby Bluetooth devices in an empty c++ console application. Previously done it in c# using the 32Feet.Net library. Do suggest me on how I can perform such task by using c++. Thanks for viewing this topic.

Why does XInput recognise DualSense controller over USB but not Bluetooth?

I can connect a Sony DualSense (PS5) controller to Windows via USB or Bluetooth.
The HTML5 Gamepad API recognises the DualSense whether I connect over USB and Bluetooth work with https://gamepad-tester.com/
However with XInput the DualSense only works over USB. Over Bluetooth, nothing happens. https://thatsmytrunks.itch.io/xinput-controller-tester
Why is that? And can it be fixed? I tested an Xbox controller with XInput, and it works over either USB or Bluetooth.
DualSense isn't recognized through XInput because it's not an XInput compatible game controller. XInput is a legacy interface for Xbox 360 and Xbox One controllers and isn't compatible with HID gamepads.
You can run software like DS4Windows that will create a virtual XInput device that mirrors the inputs from a compatible controller. DS4Windows works with DualShock4, DualSense, Switch Pro Controller, and Switch Joy-Cons.
Applications that don't need compatibility with versions of Windows earlier than Windows 10 should use the Windows.Gaming.Input API which has built-in support for HID gamepads (including DualSense).
DualSense works in Chrome because Chrome uses the Windows HID API to read inputs from HID gamepads like DualSense.

Creating a driver to translate HID-USB requests into HCI packets

So this may seem a little odd, but I'm rather limited by the hardware I have on hand.
I've got a device that consists of a TI CC2640R2 wired to a Silicon Labs CP2110 UART to USB-HID bridge. The basic premise of the device is to send Bluetooth HCI commands from the TI chip to the CP2110, which translates the UART data to an HID record, which can be read by application code on the host machine, and vice versa. What I'd like to do is to wire this device into the predefined HCI stack in Windows 10, so the desktop can use the device as a standard Bluetooth endpoint.
Normally, this wouldn't be a problem, as the device's USB chip would enumerate it as a Bluetooth device, which would cause the PnP manager in Windows to attach it to the system's Bluetooth stack. The HID device, however, complicates matters.
In order to make this work properly, I'd need to intercept HID records from the target device, unpack them, and forward them to the HCI stack so Windows Bluetooth would know what to do. I'd have to do the exact opposite going the other way - take an HCI command, package it into the appropriate HID record, and send the record to the target device.
I've managed to get the source code for the KMDF example of a Bluetooth Serial HCI Bus Driver, but I don't know the proper way to get the target device from the HID class driver, or if I'd need to do something with an HID minidriver to bridge the two driver stacks.
Is it possible to retrieve a pointer to an HID device from kernel mode, and if so, how would I go about doing that?
If not, and an HID minidriver is required to intercept and relay commands, what would be the best method of combining the HCI driver and the HID minidriver to allow the two to interoperate cleanly?

Is there is a way to read/write on a USB port using C++?(windows forms application)

I am kinda new to C++. Is there is a library or function that can be used to send or receive data through USB Port?
The format I need for sending the function would be something like this:
Write_Ex(Product ID,Vendor ID,Data);
I am using Windows form application using Visual Studio 2010.
Take a look at WinUSB. Or, if the device has FTDI interface, there's libftdi.

Read data from Wii-balanceboard

Im trying to get the output from a Wii Fit (balance board). I can find the device via the C++ Bluetooth enumerators but attempts to connect via a windows socket are failing.
Im wondering if anyone has had success in such a direction (C++, windows) I'd love to hear how you did it.
The Wii Balance Board is a HID device. To understand communications with the Balance Board, you need to know a little bit about Bluetooth HID. There's good information on WiiBrew about the Wiimote and the Wii Balance Board.
I don't think you can use Windows Sockets to connect to a HID device. The Windows Socket Bluetooth interface only allows you to connect to RFCOMM-based services. HID is based on L2CAP which is further down the Bluetooth protocol stack. There's some information at MSDN about that limitation.
If you're just looking to hack around with it, you can try Bluecove for Java. You may be able to do something using another stack (for example, Widcomm). If you're locked in to Windows and C++, you may have to look into writing an custom HID driver for the Balance Board.
As pwc said there is a limitation in the MS Bluetooth API, so with sockets you cannot have something else except RFCOMM, but this doesn't mean you cannot go down at L2CAP layer. What you have to do is to implement a client profile driver and you can use as starting point an article from MSDN: Creating a L2CAP Client Connection to a Remote Device and vice-versa: Accepting L2CAP Connections in a Bluetooth Profile Driver
Next of course as pwc said you have to study Bluetooth HID and WiiBrew for the communication protocol.
Also a good document to read is Bluetooth Wireless Technology FAQ - 2010 which states clear that it is possible to have L2CAP connections with Microsoft Bluetooth stack driver. Of course not with sockets.
When using HID on a Bluetooth device there is generally no need to create a L2CAP connection directly. All(???) of the Bluetooth stacks on Win32 have support for Bluetooth HID and provide access to the HID stream/control through the native Windows HID API. No (direct) L2CAP required! :-)
On WinCE there is built-in support for Bluetooth HID also, but I'm not sure there's a way to access a HID API.
That's how Brian Peek's wiimore library works -- it uses the HID API. The good thing about that is that one gets supports for all(?) the Bluetooth stacks that way -- they each support HID devices via the Windows HID API, whereas to use L2CAP directly one would have to support each of the stacks' APIs... (That's if they have one! BlueSoleil has no L2CAP API as far as I can see).
So, on Win32 one should just pair with the device and check that the HID checkbox is checked on its Bluetooth Service control panel tab (whichever Bluetooth stack is in use). In my 32feet.NET library one can discover the device and then ensure that HID is enabled for it with:
BluetoothDeviceInfo[] list = btCli.DiscoveryDevices();
var deviceInfo = list[n]; // Select the correct device
deviceInfo.SetServiceState(BluetoothService.HumanInterfaceDevice, true);
(That should work on MSFT and BlueSoleil; there's no API for that on Widcomm AFAIK -- although when paired it might be automatically enabled anyway).
The one possible exception case is that apparently some devices are not fully compliant with the Bluetooth/HID specs, I'm told the PS3 blu-ray controller is like that. Then one might want to try L2CAP connections directly -- however its likely that the stack's support for HID will interfere with third-party applications trying to provide the same service...