My static website generator using poole https://www.xythobuz.de
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2015_12_20_serialgamepad.md 7.7KB

title: Blog post: Flysky Mac OS X joystick driver date: 2015-12-20 comments: true flattr: true github: https://github.com/xythobuz/SerialGamepad parent: projects

position: 50

{{ page[“post”] }}

Hardware

In the last couple of months I’ve finally built a FPV capable Quadcopter. Fortunately, I could use the Transmitter I already had for a number of years. It’s a Modelcraft MP-26-DT, a rebranded Flysky FS-CT6x Transmitter. There are many different versions of this Transmitter on the market, all basically the same, like the HobbyKing HK-T6A.

As you can see, in the back is a small transmitter PCB (in green) marked with FlySky. That’s how I found out it’s just a rebranding. This module only has 4 pins, +5V, GND, PPM Signal and a connection for the bind button. This means you can replace it with most other modules, as I did with the (discontinued) Fr-Sky DHT.

This line of Transmitters also has a PC-Link port in the back (a 4-pin mini-DIN connector), that’s simply a RS232 port (most probably in TTL logic). The packaging includes a USB-Serial adaptor with this connector and a Silicon Labs CP2102 or Prolific PL2303 chipset. You may need to install the driver for one of these. To find out which one, open the System Information App, find the USB device corresponding to the dongle and check its name.

A (pretty crappy) Visual Basic Windows Software is included to configure the transmitter, called T6config or TXsetup. There are some alternatives, like TurborixConfig for Mac OS X.

Software

With FPV flying becoming more prevalent, many users started connecting their transmitters to their PCs to use them as Joystick in FPV Simulator software like FPV Freerider, Liftoff or HOTPROPS. The most important thing for this to work is a driver so the Operating System can use the Transmitter as a Joystick. Of course, there’s no driver for my Transmitter or my Operating System…

Fortunately, the configuration software always displays the current stick positions, so the transmitter seems to be sending this continuously. I tried reverse-engineering the data stream myself, but quickly got stuck seeing strange repeating patterns every 12 bytes. Of course, this was later explained as I was using a baudrate of 9600 and the real one is 115200, exactly 12 times my rate. But I got lucky and found this forum post explaining the data format.

Experimentation revealed that the format slightly differs from the forum post, in that the “7th channel” is, in my case, always the throttle, even when CH3 is set to zero using a hardware switch (which makes more sense, to be honest).

So I wrote a little command line application displaying the current stick positions, called protocol.

The only thing left is creating a driver that emulates a Human Interface Device. This is where foohid comes to shine. This fantastic little piece of software is a Kernel Extension that allows Userspace applications to create a virtual HID. Exactly what I was looking for.

For this to work, I had to create a USB HID descriptor, as described here, using this Windows software:

static char report_descriptor[36] = {
    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x05,                    // USAGE (Game Pad)
    0xa1, 0x01,                    // COLLECTION (Application)
    0xa1, 0x00,                    //   COLLECTION (Physical)
    0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)
    0x09, 0x30,                    //     USAGE (X)
    0x09, 0x31,                    //     USAGE (Y)
    0x09, 0x32,                    //     USAGE (Z)
    0x09, 0x33,                    //     USAGE (Rx)
    0x09, 0x34,                    //     USAGE (Ry)
    0x09, 0x35,                    //     USAGE (Rz)
    0x16, 0x01, 0xfe,              //     LOGICAL_MINIMUM (-511)
    0x26, 0xff, 0x01,              //     LOGICAL_MAXIMUM (511)
    0x75, 0x10,                    //     REPORT_SIZE (16)
    0x95, 0x06,                    //     REPORT_COUNT (6)
    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
    0xc0,                          //     END_COLLECTION
    0xc0                           // END_COLLECTION
};

The result can be seen in the creatively-named command line app foohid. It work’s perfectly and is detected as Joystick in all Games I’ve tried. Flying in FPV Freerider or Liftoff is very fun!

The only thing left was packaging this into a nicer GUI application for ease-of-use. So, I present, SerialGamepad. Basically the same functionality as the command line apps, packaged into an Installer package including the foohid dependency, so Users only need to install a single package.

Creating the installer package was the last thing I never did before, but fortunately there’s a very good StackOverflow answer explaining the process. It boils down to some lines in the Makefile and a Distribution.xml file detailing the installation wizard contents.

And all my code is under the Beer-Ware license. I hope to get something in return some day :P

----------------------------------------------------------------------------
"THE BEER-WARE LICENSE" (Revision 42):
<xythobuz@xythobuz.de> wrote this file.  As long as you retain this notice
you can do whatever you want with this stuff. If we meet some day, and you
think this stuff is worth it, you can buy me a beer in return.   Thomas Buck
----------------------------------------------------------------------------