123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|447|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Off Topic -> Hacking Controllers - Part 2

Page : 1 2 Next
Prev
Thu, 13 Mar 2014, 13:55
spinal
Over the past few days I have been trying to create an OUYA compatible game controller. Why? I hear you ask! Well, I had so much fun with that SNES controller, that I though it'd be fun to try something a little more complex, and let me tell you, OUYA (possibly Android in general) controller are nutty!

There has been a bit of talk about controller lag with the OUYA controllers, most people think that this is down to the OUYA being metal and the antennas on both the console and the controllers being crap. But I have a different idea. It seem that the OUYA controller, isn't just a controller, its also a keyboard and mouse as well as sending a pile of other info such as battery percent etc. I believe that the lag is caused by the controller sending too much info and causing a bottle neck.

Regardless, I want my controller to be just as functional as the OUYA one, so a SNES controller is just not good enough unfortunately. So this time, I went with an old PS2 Dualshock controller. Luckily this guy over here has created a nice little lib for decrypting PS2 controller data on an AVR. That part actually took a while to track down, there a loads of sites claiming to have all the right info on that, but most are wrong or crap.

Anyway, next step, find out what the hell is going on with that OUYA controller!
So, I rand a test app (OUYA Random Tests) on the OUYA, pressed a bunch of buttons, found out that they map to Android key events, which seem to be based on an xbox 360 style button layout, googled some HID descriptors that would match, tested them.... All the buttons were either mapped differently or way out of range. Confused, I synced the OUYA controller with my Windows laptop (I'll explain in a bit why my Mac was out of the question), discovered that it detects as a Keyboard, Mouse and Gamepad. Wow! So anyway, I checked in the joystick settings, we have 2 axis, a couple of z rotation dealies and a handful of buttons. No big deal. So I set about programming my PS2 buttons to match the button numbers given by Windows. So now both the OUYA controller and my PS2 controller both look identical in Windows! However, on the OUYA, they're completely different, just as before! ARGH!!!!!!!
At this point, I though it might be worth emailing team OUYA and ask for some help... "Why R my controller different!!!" had the email passed on to a guy who's doing something with HID support in some of the framework example (perhaps this might end up with all/most frameworks being able to use standard HID controllers instead of only OUYA, PS3 and 360??) anyway, that guy passed my request on to one of the hardware guys at OUYA.... No reply yet...

In the mean time, I googled some more hid descriptors, in hopes of emulating a controller already emulated by the OUYA, namely xbox 360 and PS3. Neither resulted in correct button mapping and to top if off, I managed to find nothing in the way of any information regarding using a d-pad as a d-pad instead of buttons. The d-pad was my main struggle throughout everything. I couldn't get anything near the results of the OUYA controller.
Somewhere along the way, can't remember where or when, but it occurred to me to plug in my spare keyboard and see if any of the keys matched what OUYA was expecting as d-pad buttons. Sure enough, the cursor keys were what the OUYA was using as the d-pad. So, back to the USB AVR examples to find a keyboard descriptor, set it up with the d-pad mapping to the cursor keys, flash the firmware, plug it into the OUYA and BAM! it worked! Only one problem, the rest of the controls needed to be gamepad buttons and analog sticks and worst of all, the OUYA maps keyboards to player 1 no matter what. So I had a controller detecting as player 2, but triggering button pressed on controller 1!!

So, a bit more research later, I found out that I can shoehorn random descriptor 'usage pages' any old place in the descriptor, just so long as the code stays valid.
So a bunch more googling later, I discovered that I can set individual keys in an hid descriptor, allowing me to use the keystrokes for the cursor keys only, without allowing for the rest of the keyboard. So thats what I did, So now I have a PS2 controller set up as a USB gamepad with 2 axis, a couple of throttles, a bunch of buttons and 4 cursor keys!

Now, back to the Mac. Anyone who as tried will tell you that you can't sync an OUYA controller on OS X. Or rather, you can, but the Mouse pointer goes nuts and you cant do anything! Some people are speculating that the touchpad descriptor on the OUYA controller is confusing OS X, because it doesn't know what to do with a Mouse that has analog sticks and keyboard keys on it. However, I'm getting the same screwed up results with my controller in its current state, that is, only a gamepad with cursor keys. So, I'll do some speculate a little myself and say the screwiness has nothing to do with the touchpad and everything to do with shoehorning cursor keys into a gamepad.

My next step, is to figure out how the menu (U) button is mapped, hopefully thats not as nuts as the cursor keys, then figure out how to read mouse scroll wheels on an AVR (I have a trackball addition in mind).

I'll keep you guys posted. Possibly even release the source code for this project also



- Update -

Here is the source code for my joypad

PSx_to_OUYA.zip

You'll need the lufa library to compile it, it's based on the KeyboardMouse example, with the keyboard stuff replaced by gamepad.

There are 3 'modes' which are changed by a button press, I replaced my 'Analog' button. Mode 1 is gamepad, Mode 2 is left analog mouse, mode 3 is right analog mouse.

It's wires as follows -





-=-=-
Check out my excellent homepage!
Thu, 13 Mar 2014, 14:25
Jayenkai
Bloody 'ell!!!

I can't even begin to imagine how you did any of that!!!!

As for system-button, monkey says that it acts as a toggle, not a simple button, so I imagine that'll be one tough tit to figure out...
Good luck.

-=-=-
''Load, Next List!''
Thu, 13 Mar 2014, 15:10
spinal
I've tracked the menu button down to "Main Menu" or "App Menu" usage in the hid descriptor. Can't remember which one it is now, but its 0x85. However on the OUYA button tester, the menu button (82) on the OUYA controller only seems to register the 'false' state, which makes no sense at all, if a button can't be pressed, how the hell can it know it's not pressed?

....Back to Google...

-=-=-
Check out my excellent homepage!
Thu, 13 Mar 2014, 15:53
rockford
This sounds more than a little interesting. I wonder why OUYA bodged the controller together like that.

Keep up the good work
Fri, 14 Mar 2014, 01:11
spinal
The main reason I think that sending so much data is the main reason for the lag is two fold. One, PS3 controllers show no lag, even when four are synced at once (apparently) and two, using a triple descriptor such as a full keyboard, gamepad and mouse over USB can cause lag. I really don't know why they need such a crazy controller, so far I've managed to have a functional controller using only a standard gamepad descriptor with four keyboard keys jammed into it.

-=-=-
Check out my excellent homepage!
Fri, 14 Mar 2014, 01:29
spinal
Hmmmm.....

From the OUYA site...

NOTE: Because the menu button press is emulated, the up and down events happen at once. This means you won't be able to detect it being pressed using the passive anytime state querying. It's much more reliable to detect the menu press in your onKeyUp/Down code.


How the hell am I going to send two button states at the same time?!!

-=-=-
Check out my excellent homepage!
Fri, 14 Mar 2014, 04:47
Jayenkai
Thinking in terms of keyboards, have you looked into Caps Lock at all?!

-=-=-
''Load, Next List!''
Sat, 15 Mar 2014, 01:27
spinal
I haven't...

I added mouse capability (but not the actual trackball yet) so right now, if I hold SELECT down, then the right stick will move the mouse pointer.

Still no further no the menu button. I even tried setting two buttons to the menu button, and only updating the first one, so that any button press would be canceled out in the same packet. That didn't work.

-=-=-
Check out my excellent homepage!
Sat, 15 Mar 2014, 17:41
spinal
I'm needing to do some dead-zone fixing, the sticks on this old controller are a little, well, old.

Anyone care to tell me how to convert a range from 0-255 (or rather -127 to 127) and chop out the middle 20 or so points ?

-=-=-
Check out my excellent homepage!
Sat, 15 Mar 2014, 18:09
Jayenkai
If Abs(value)<20 then value=0?
Sun, 16 Mar 2014, 02:08
spinal
but doing that on two axis, creates a huge + shape dead zone, rather than a dot in the middle.

also I loose any <20 value

-=-=-
Check out my excellent homepage!
Sun, 16 Mar 2014, 06:36
Jayenkai
The thing I really like about the "Abs()<Deadzone" solution is that you also end up having little "lock-zones" around the four main directions. It tends to work nicely when doing digital-controls using an analogue stick..

BlitzMax


I'm not sure how complicated you wanted your answer, as, to be honest, I've no idea how complicated the stuff you're using can get!
... But, if you can fathom your way around that, you might be able to wrangle it into the controller somehow!!

-=-=-
''Load, Next List!''
Sun, 16 Mar 2014, 13:44
spinal
without yet running the above code (not having blitz max, i think plus was the free one that time?) plus im on the mac. What I really need...


So i need 0 - 127 to take up less space than 0 - 127, but still be 0 - 127...

-=-=-
Check out my excellent homepage!
Sun, 16 Mar 2014, 14:35
Jayenkai
Look at the "ComplexAngle/ComplexDistance" bits.
Mon, 17 Mar 2014, 07:27
steve_ancell
Will this do?...

I know it's in Blitz, it was quicker to deal with that way, but it shouldn't be too hard to convert to Monkey-X if that's what you're using. All values inside the function are floats, best to keep it that way.


|edit| I tested this on an XBox 360 controller. |edit|



Tue, 18 Mar 2014, 02:10
spinal
Cheated...



-=-=-
Check out my excellent homepage!
Tue, 18 Mar 2014, 02:34
Jayenkai
Cheater!!!!!
Tue, 18 Mar 2014, 11:58
steve_ancell
That's a lot of numbers.
Wed, 19 Mar 2014, 05:18
spinal
Here's the progress report on getting the damn menu (U) button to work...

when holding any button down on the official controller, it will register true.
tapping the menu button never registers as true, but upon release will register false. No idea how it goes about doing this.
Here's the odd thing, hold a button down, it stays true, if you then hold the menu button, after a second ALL pressed buttons return false.
My controller, sends the menu button key event, the menu buttons shows true (note this doesn't happen with the real controller) when the button is released, it shows false. The weird part is, that none of my other buttons sill register until I press the menu button again.

argh!

-=-=-
Check out my excellent homepage!
Wed, 19 Mar 2014, 06:13
Jayenkai
Have you considered emailing Team OUYA and asking them? They've been fairly chatty, dev-wise.. perhaps their tech-team may be as forthcoming..?

-=-=-
''Load, Next List!''
Wed, 19 Mar 2014, 08:41
steve_ancell
spinal when holding any button down on the official controller, it will register true.
tapping the menu button never registers as true, but upon release will register false.

Could it be a faulty controller, or does it work OK when you play other games on it?.
Wed, 19 Mar 2014, 10:23
spinal
I think that's the usual behaviour where the menu button is concerned.

-=-=-
Check out my excellent homepage!
Wed, 19 Mar 2014, 10:32
Jayenkai
Yeah, the menu button's mental!!!
Wed, 19 Mar 2014, 15:05
spinal
According to a joystick tester I just ran on my mac, the ouya controller has 18 axis and 18 buttons!!!!11111

-=-=-
Check out my excellent homepage!
Wed, 19 Mar 2014, 15:34
steve_ancell
18 axis?, I thought a joystick only had two: x and y.
Wed, 19 Mar 2014, 15:58
Jayenkai
Left stick = 2
Right stick = 2 more
Each trigger is it's own axis, too, so that's another 2.
...

Nope, not counting 18!

-=-=-
''Load, Next List!''
Page : 1 2 Next
Prev