Accidentally step into Android development: tpmini with big eyes using the PS3 Bluetooth handle (4) Mining sixaxis communication protocols around linmctool

Source: Internet
Author: User

This is a set of serialized articles used to record the entire process of connecting a Bluetooth handle with big eyes. I would like to use this document to give my missing sleep that week. This article is equivalent to a (public) personal diary. Do not repost it without your permission.

 

As mentioned above, after linmctool is compiled, the connection to the handle is successful, and all buttons are responded. I can explore various sixaxis buttons.

During the test, I suddenly failed to connect. I am very depressed, no matter how it is adjusted. Finally, I found that the first successful connection was entirely due to the command hciconfig hci1 up and hciconfig hci1 piscan that I did not intend to input when studying Hidd. Since I have two bluetooth adapters, after the big eyes are started, the first Bluetooth adapter TO BE INSERTED is assigned to hci0. If another Bluetooth adapter is inserted when hci0 is valid, hci1. Big eyes seem to occupy hci0, which makes hci0 unable to be up all the time. My first connection was successful because a useless adapter hci0 was inserted first, and then the adapter hci1 paired with sixaxis was inserted. Hci0 is miserable. It was forced by a process in the big eyes, but hci1 was not robbed, and it was used by linmctool. However, once you restart your big eyes, change the order of the adapter, or insert only one Bluetooth adapter, the connection will fail. After repeated tests, to connect properly, two conditions are required: 1. The corresponding HCI can be successfully up; 2. The corresponding HCI must be enabled with pscan. In this case, the chance of being right is really small, and I am really lucky.

After many experiments, I found that the culprit in using hci0 is/system/bin/mongothd. It taught me how to use the ps command and kill command, but kill is still unable to kill it. After killing it, it will automatically start again. I had to rename it, so that the system could not find it. In the future, hci0 will no longer be able to be up.

Let's get down to the truth. Next we will study the sixaxis buttons and sensors.

Changed the code in linmctool. I asked it to display all the data from the handle.

After repeated tests, I was shocked.

I have never played with the PS3. I bought this handle for a moment. It seems that it has no line limitations to buy it. I really didn't think it was so powerful! In addition to the SELECT, START, L3, R3, and PS keys, all other keys can measure the intensity of the press! This is too difficult. After talking with the game control colleagues, I learned that when playing a game on the PS3, the speed of the direction keys is different from that of the re-running. I am going!

 

The following is a set of sample data obtained from the hcidump command:

> ACL data: handle 42 flags 0x02 dlen 54 L2CAP (d): cid 0x0041 len 50 [psm 19] HIDP: Data: Input report 0000: 01 00 00 00 00 00 7f 80 81 80 00 00 00 00 00 00 ................ 0010: 00 00 00 00 00 00 00 00 00 00 03 03 16 ................ 0020: ff b7 00 0e 33 a0 77 01 c0 01 fc 01 e7 01 8d 01 ?. 3 rows .???.. 0030: f0?

 

It can be seen that each handle sends 49 bytes to the host. After testing and comparison, we can find the rule:

Of the 49 bytes,

3rd bytes are 8 buttons, from low to high. The values are SELECT, L3, R3, START, top, right, bottom, and left. The pressure value of the first four buttons is between 11th and ~ 14th bytes, reading is always 0; the pressure values of the last four buttons are located in 15th ~ 18th bytes.

4th bytes are 8 buttons, from low to high, which are L2, R2, L1, R1, triangle, circle, cross, square. The pressure values of these 8 buttons are respectively located in 19th ~ 26th bytes.

The percentile of 5th bytes is the PS key. The pressure value of this key is at 27th bytes, And the reading value is always 0.

The value of bytes is the value of the X axis (horizontal direction of the Left joystick), and the value of the height is in the front.

The 44,45 byte is the value of the Y axis (vertical direction of the Left joystick), and the height byte is in front.

The value of bytes is the value of the Z axis (horizontal direction of the right joystick), and the height is in front.

The value of 48 to 49 bytes is the value of the GZ axis (vertical direction of the right joystick), and the height is in front.

 

Some other bytes are used to measure the acceleration, the inclination of the joystick, and some others that do not know what to do. They are not easy to test, so they are not carefully tested.

The above is enough for the moment.

 

OK. With these, we can start planning.

 

I have been using xperia play. This is a very good mobile phone. After pushing the handle, you can use the handle for various controls, not just playing games, but also system functions.

Preliminary Design: I plan to use sixaxis to implement various functions of the Controller in play. That is to say, the up and down arrow keys are used to control the cursor (not the mouse pointer), the cross key is determined, the circle key is returned, the L3 key is used as the menu key, the R3 key is used as the Home key, and the L2 and R2 keys are used as the volume key,

In addition, the triangle key is used for search, the left joystick controls the mouse pointer, the box key simulates the left mouse button, and the right joystick is used to simulate the screen by hand.

 

To implement these functions, our software serves as a bridge, connecting sixaxis at one end and simulating keyboard or mouse movements in the system.

Next, continue.

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.