Explorar el Código

Added SerialGamepad page

Thomas Buck hace 9 años
padre
commit
ac1ed7c682

+ 110
- 0
input/blog/2015/2015_12_20_serialgamepad.md Ver fichero

@@ -0,0 +1,110 @@
1
+title: Blog
2
+post: Flysky Mac OS X joystick driver
3
+date: 2015-12-20
4
+comments: true
5
+flattr: true
6
+twitter: xythobuz
7
+github: https://github.com/xythobuz/SerialGamepad
8
+parent: projects
9
+position: 50
10
+---
11
+
12
+## {{ page["post"] }}
13
+<!--%
14
+from datetime import datetime
15
+date = datetime.strptime(page["date"], "%Y-%m-%d").strftime("%B %d, %Y")
16
+print "*Posted at %s.*" % date
17
+%-->
18
+
19
+### Hardware
20
+
21
+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.
22
+
23
+<div class="yoxview">
24
+    <a href="img/flysky1.png" class="thumbnail">
25
+        <img src="img/flysky1.png" alt="Photo" title="FlySky FS-CT6A"">
26
+    </a>
27
+    <a href="img/flysky2.jpg" class="thumbnail">
28
+        <img src="img/flysky2_small.jpg" alt="Photo" title="HK-T6A">
29
+    </a>
30
+    <a href="img/flysky3.jpg" class="thumbnail">
31
+        <img src="img/flysky3_small.jpg" alt="Photo" title="MP-26-DT">
32
+    </a>
33
+    <a href="img/flysky4.jpg" class="thumbnail">
34
+        <img src="img/flysky4_small.jpg" alt="Photo" title="MP-26-DT back">
35
+    </a>
36
+    <a href="img/flysky5.jpg" class="thumbnail">
37
+        <img src="img/flysky5_small.jpg" alt="Photo" title="MP-26-DT mod">
38
+    </a>
39
+    <a href="img/flysky6.jpg" class="thumbnail">
40
+        <img src="img/flysky6_small.jpg" alt="Photo" title="MP-26-DT mod near">
41
+    </a>
42
+</div>
43
+
44
+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](http://www.frsky-rc.com/product/pro.php?pro_id=95).
45
+
46
+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 [Prolific PL2303](http://www.prolific.com.tw/US/ShowProduct.aspx?p_id=229&pcid=41) chipset. You may need to install the driver for this.
47
+
48
+A (pretty crappy) Visual Basic Windows Software is included to configure the transmitter, called T6config or TXsetup. There are [some alternatives](http://www.mycoolheli.com/t6Alternate.html), like [TurborixConfig for Mac OS X](http://www.zenoshrdlu.com/turborix/).
49
+
50
+### Software
51
+
52
+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](http://fpv-freerider.itch.io/fpv-freerider), [Liftoff](http://www.liftoff-game.com) or [HOTPROPS](http://hotprops-fpv-race.com). 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...
53
+
54
+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](http://www.rcgroups.com/forums/showpost.php?p=11384029&postcount=79).
55
+
56
+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).
57
+
58
+So I wrote a little command line application displaying the current stick positions, called [protocol](https://github.com/xythobuz/SerialGamepad/blob/master/src/protocol.c).
59
+
60
+The only thing left is creating a driver that emulates a Human Interface Device. This is where [foohid](https://github.com/unbit/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.
61
+
62
+For this to work, I had to create a USB HID descriptor, [as described here](http://eleccelerator.com/tutorial-about-usb-hid-report-descriptors/), using [this Windows software](http://www.usb.org/developers/hidpage#HID%20Descriptor%20Tool):
63
+
64
+<pre class="sh_c">
65
+static char report_descriptor[36] = {
66
+    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
67
+    0x09, 0x05,                    // USAGE (Game Pad)
68
+    0xa1, 0x01,                    // COLLECTION (Application)
69
+    0xa1, 0x00,                    //   COLLECTION (Physical)
70
+    0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)
71
+    0x09, 0x30,                    //     USAGE (X)
72
+    0x09, 0x31,                    //     USAGE (Y)
73
+    0x09, 0x32,                    //     USAGE (Z)
74
+    0x09, 0x33,                    //     USAGE (Rx)
75
+    0x09, 0x34,                    //     USAGE (Ry)
76
+    0x09, 0x35,                    //     USAGE (Rz)
77
+    0x16, 0x01, 0xfe,              //     LOGICAL_MINIMUM (-511)
78
+    0x26, 0xff, 0x01,              //     LOGICAL_MAXIMUM (511)
79
+    0x75, 0x10,                    //     REPORT_SIZE (16)
80
+    0x95, 0x06,                    //     REPORT_COUNT (6)
81
+    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
82
+    0xc0,                          //     END_COLLECTION
83
+    0xc0                           // END_COLLECTION
84
+};
85
+</pre>
86
+
87
+The result can be seen in the creatively-named command line app [foohid](https://github.com/xythobuz/SerialGamepad/blob/master/src/foohid.c). It work’s perfectly and is detected as Joystick in all Games I’ve tried. Flying in FPV Freerider or Liftoff is very fun!
88
+
89
+The only thing left was packaging this into a nicer GUI application for ease-of-use. So, I present, [SerialGamepad](https://github.com/xythobuz/SerialGamepad/blob/master/src/foohid.c). Basically the same functionality as the command line apps, packaged into [an Installer package](https://github.com/xythobuz/SerialGamepad/releases) including the foohid dependency, so Users only need to install a single package.
90
+
91
+<div class="yoxview">
92
+    <a href="img/serialgamepad1.png" class="thumbnail">
93
+        <img src="img/serialgamepad1_small.png" alt="Screenshot" title="SerialGamepad">
94
+    </a>
95
+    <a href="img/serialgamepad2.png" class="thumbnail">
96
+        <img src="img/serialgamepad2_small.png" alt="Screenshot" title="protocol CLI">
97
+    </a>
98
+</div>
99
+
100
+Creating the installer package was the last thing I never did before, but fortunately there’s a very good [StackOverflow answer](http://stackoverflow.com/a/11487658) explaining the process. It boils down to [some lines in the Makefile](https://github.com/xythobuz/SerialGamepad/blob/master/Makefile#L46-L66) and a [Distribution.xml file](https://github.com/xythobuz/SerialGamepad/blob/master/Resources/Distribution.xml) detailing the installation wizard contents.
101
+
102
+And all my code is under the Beer-Ware license. I hope to get something in return some day :P
103
+
104
+    ----------------------------------------------------------------------------
105
+    "THE BEER-WARE LICENSE" (Revision 42):
106
+    <xythobuz@xythobuz.de> wrote this file.  As long as you retain this notice
107
+    you can do whatever you want with this stuff. If we meet some day, and you
108
+    think this stuff is worth it, you can buy me a beer in return.   Thomas Buck
109
+    ----------------------------------------------------------------------------
110
+

BIN
static/img/flysky1.png Ver fichero


BIN
static/img/flysky2.jpg Ver fichero


BIN
static/img/flysky2_small.jpg Ver fichero


BIN
static/img/flysky3.jpg Ver fichero


BIN
static/img/flysky3_small.jpg Ver fichero


BIN
static/img/flysky4.jpg Ver fichero


BIN
static/img/flysky4_small.jpg Ver fichero


BIN
static/img/flysky5.jpg Ver fichero


BIN
static/img/flysky5_small.jpg Ver fichero


BIN
static/img/flysky6.jpg Ver fichero


BIN
static/img/flysky6_small.jpg Ver fichero


BIN
static/img/serialgamepad1.png Ver fichero


BIN
static/img/serialgamepad1_small.png Ver fichero


BIN
static/img/serialgamepad2.png Ver fichero


BIN
static/img/serialgamepad2_small.png Ver fichero


Loading…
Cancelar
Guardar