Sunday 3 July 2011

DirectInput - Logitech G940 support

Logitech have been really great in offering some hardware support, enabling me to add force-feedback into Combat-Helo. So thank you to Logitech for that.

Force-feedback support was not planned for first release. We were not using DirectInput, I had spent a  time working on improving a cross platform library which on the Windows platform used SDL (Simple Direct Media Layer). This has a number of caveats, namely support for limited number of axis per device and originally only 16 button support (which was extended to 32). Some throttle axis were not recognised under SDL due to the way the manufacturers drivers sample down the input mapping to fit the Windows Media library which SDL uses. If a HOTAS has 16 axis and you can only choose 5, some are going to get missed. It was going to be a problem later and I knew it.

Two things were going to happen, either I had to write a DirectInput interface or wait for the Khronos group that oversees the OpenGL specification to introduce their own cross-platform input/haptics library. Since the latter didn't look like it was happening anytime soon the former seemed inevitable.

Then someone on SimHQs forums asked a question about force-feedback support and in particular drew my attention to the G940. Let me quickly explain something about how helicopters with flight control systems work....

The cyclic (joystick) control commands the main rotors to provide more lift in the direction you move it (keeping it simple here, there's a whole can of physics whoop-ass behind this). To maintain a forward airspeed you might be required to physically hold the cyclic in one position for a length of time. With normal PC joysticks, those with strong self-centring springs this is impractical. Not only is it fatiguing to hold something against a strong force for any length of time it's not terribly realistic.

Since I tried to design the game to be adaptable to be playable on a wide variety of controllers, from XBOX 360 joypads (twin thumbsticks) to full floor standing cyclic replica controls (such as those created by Komodo Simulations Ltd.) a common solution was to implement a software trim system that was invisible to the end user. Auto-Trim would covertly position the virtual helicopter cyclic back to the centre position over time and part of the advanced flight model (AFM) provided by the HTR flight physics engine.

Then there's the manual trim option for joystick hardware that can provide either an electric clutch or force-feedback to hold the stick in place. This is where we run into problems using a library like SDL. It doesn't work too well here either.

It was the last straw. Time to make the change. Sadly I've been here before, MinGW (among the fastest compilers made) hates me and never liked compiling DirectX headers and linking the 3rd party libraries. So what I did was create a DirectInput interface using a DLL in VisualStudio2010. Now all advanced hardware is being detected, including 3DConnexion's Space Navigator 3D mouse which is a brilliant navigation device.

As it happens...

The provided software for the G940 installs an SDK for accessing extended features of the hardware.


What extended features? The split-throttle unit has 8 LED buttons (as it happens there are 8 bits in one byte). A small library is provided to Get/Set the red and green LED status as two single bytes. If both red and green bits are set you get orange. And you can remove the caps and put your own legends under them. Seems like a good idea to add warnings/status light mapping to these switches.


I'm just stoked that the problem of full input mapping is sorted. I'll be adding more of the force-feedback functions to the DLL over the next few days among some of the other avionics features that are currently being finished.

1 comment:

  1. ya know, thats great news flex... I never did like holding a stick forward for half an hour and yes it is tiring.

    very good news that your joystick mappings are going so well and will have a large stable of hardware available.

    ReplyDelete