ofxJoypad - joypad addon built with OIS


We often need joystick support in our applications and since this is not natively included, I decided to go for an addon. It’s a simple wrapper to the joystick functionality of OIS. Out of the box it only works for os x, since I built the OIS library myself on OS X snow leopard. But it should work for linux and windows as well. You just have to grab the latest OIS source at http://www.wreckedgames.com/ and compile it yourself.

To use the addon you simply need one instance of ofxJoypad and register a listener that inherits ofxJoypadListener. A sample is included.

Since we’re working with PS3 controllers, there is an enum with all buttons and their ID. If anybody has another pad to try, I could include that as well. XBOX 360 is now included as well.

**The addon had a complete rewrite, is now called ofxGamepad and downloadable on github: https://github.com/underdoeg/ofxGamepad.**

Hope this is useful for anybody

cool that’s great!

I’ve used OIS before (with Ogre) and I can confirm that it works fine under Linux and Windows.

thanks grimus thats good to know.

Updated the download link in the original post. Dead zone, as well as getButtonPressed and getAxisValue work now. I also provided an enum for XBOX 360 controllers to easily find out wich button was pressed.
POVs however are not yet supported.

you can get the precompiled OIS library for vis c++ or MinGW at the Ogre source download page, http://www.ogre3d.org/download/source (look for ‘precompiled dependencies’)

I rewrote the library to use the more native <linux/joystick.h> interface and to handle multiple gamepads a little better. It’s now also called ofxGamepad and on github https://github.com/underdoeg/ofxGamepad

Nice addon.

Do you think could be possible to add the addon force feedback control to XBOX 360 joysticks? Basically turn off and on vibration motor of the joystick.

At least OIS supposedly has some feedback commands. As soon as I implemented it again, we can have a try. But it might be that the XBox controller only has all features available on windows. Would be interesting though. I’ll post when something happens.

I install the last joystick driver OSX xbox 360 from:

And I try your code ofxJoystickExample_v_0_2.zip with OIS work successfully in mac. Even seems to work fine with two joysticks connected.

The driver say that allow some of the effects in force feedback, not all. But I guess will be possible to use at least some simple effect of vibration even in OSX.

Ok great. Good to know it works. But please consider using the new version ofxGamepad. It handles multiple joysticks much better and I am currently working on the mac version. I’ll have it ready this evening and will also map the OIS feedback implementation.


Well, I see that the new addon looks more clean. But at the moment, I am reading code from OIS. I am really looking forward your changes. Let me know if I can help somehow.

I read you code and I did some changes (not much) in addon to have real-time detecting joysticks, not only when software is open. I would like to use for a project and flexible architecture. I can disconect joystick and connect again and the idea is to be auto-detected by software with a define timer.
(project in OF7 xcode)

Ah great. Thanks! Will implement your code in the new version. Having plug and play functionality is very high up on my to do list.

I just commited OIS support for mac to the new version. But I currently have no access to a gamepad, so I hope everything works ok :). Will try it when I get home with an actual gamepad. (I even have a XBOX 360 controller lying around somewhere…) and look at hotplugging…

You can help me by testing the new code and maybe fix what I have forgotten. (Since I don’t have a gamepad here…)

It just try and it works perfect in OSX 10.6 with two wireless xbox 360 controllers. But it not work with hotplugging yet. Can I help you in something else?

Here a screenshoot:

great. thanks for testing!

I’m at home now and can confirm it also works with other gamepads. Since the code is on github and if you want to help, just fork it and add something, when you need it. I also opened some issues on the github page. But don’t worry about hot plugging yet, I’m halfway thru implementing it…

I just read that OIS demo “FFConsoleDemo.cpp” is only test two devices: Logitech G25 Racing wheel, Logitech Rumble pad 2. I implemented the setup to get force feedback, but don´t get in xbox 360.

Hmm, too bad… But the os x driver by tattieboogie supports rumble, doesn’t it?

Yes, it the driver support it. In preferences when you press back buttons activate force-feedback.

I add code to my github fork. It is still no methods for activate force feedback.

Maybe I will try to use another library (https://github.com/elanthis/gamepad) or I was wondering if maybe in windows IOS could detect force feedback since is more native environment.

That feedback implementation looks great. Can you issue a pull request, so I can easily merge it into the master, if that’s ok?

I’m still working on hot plugging. It is strange that you have to destroy the whole system to find a new joystick. Still looking for a solution, so you can still keep your old gamepads without recreating them. I have uploaded the (not yet working) result to github in a new branch called hotplugging.

The other gamepad looks good as well. But I think it is only windows and linux? So if you have to use windows anyways, maybe you’re right and OIS Rumble with the XBox works there…

Actually it kind of works now, I did a really stupid mistake ;D Hotplugging is working now with OIS. Also unplugging. But it is not perfect, the joystick now just goes into pause until it is reconnected but doesn’t notify of this event. But I merged it into the master now.

I thing in updatePadList() you will be better to erase all vector and create again each time. Otherwise you can create some mistakes. Now is asume the order pads is always same, but randomly one or the other can go offline for battery issues or wherever other reason. And then can be produced some pads duplications or when size is small you never erase it. I tried before when decrease is not crashing, but you don’t have any information that one device is offline. Although when size change of update could be thought some POCO event.

I am not to good with git and don’t know how to pull to you now.

I just looked in the code and I noticed that OIS only have:
But no any class on the Mac folder for force feedback.

Ideally wanted to use osX, then actually don’t matter to me Linux or Windows, but I want to use simple vibration. Do you have other gamepad to try force-feedback? since is not working in xbox360 and it is the only gamepad I have here. And in order to make OIS to work on windows we need the windows dll, do you have it?

Yes, you’re right. That’s what I meant with it’s not perfect yet. The problem is, if you erase the vector every time, then any connection to an event of a gamepad would be deleted. So the system should somehow know, wich joystick has been removed and then delete the exact same from the list and trigger the on delete event. I think this has to be done with the vendor name and the position. But I haven’t come up with a good solution yet, because as far as I know OIS doesn’t give out a unique ID for every pad to identify it…

To make a pull request you can click on the “pull request” button on the top left corner in the web interface.