Xbox360ControllerManager 0.0.1

Xbox360ControllerManager 0.0.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Unclaimed.



  • By
  • halo

Work in Progress Note

Work is in progress. I've established basic connection with the Controllers and am working on the abstraction so that you can plug this cocoa pod into your project. I don't want you to have to deal with IOHIDDevices, but with real controller instances and proper Notifications.

Xbox 360 Controller Manager

This is a CocoaPod which provides a simple API for you to work with Xbox input devices such as controllers, guitars, and drumsets.

Requirements

  • You need at least Mountain Lion
  • Install the driver which allows you to connect Xbox input devices (Controllers, Guitars, Drumsets) to your Mac.

You're ready to roll with USB-cable devices! If you plan on using wireless devices, you'll have to buy one of those first:

Xbox 360 Wireless Receiver

Installation

Head over to cocoapods.org to learn more about how it works. Here's a quickie:

1. Download the repo next to your project:

git clone git://github.com/halo/Xbox360ControllerManager.git ~/some/where

2. Create a Gemfile in your project:

source :rubygems

gem 'cocoapods'

3. Create a Podfile in your project:

platform  :osx
xcodeproj 'YourProject'

pod 'Xbox360ControllerManager', '0.0.1', :local => '~/some/where'

4. Install and run bundler if you don't already have it:

gem install bundle
bundle install

4. Run the pod

pod install

Usage

This would be a minimal implementation of your Application Delegate:

#import "AppDelegate.h"

#import "Xbox360Controller.h"
#import "Xbox360ControllerManager.h"

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
  // Start listening for device activity
  [Xbox360ControllerManager sharedInstance];
  // Register to the notifications
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerAdded:) name:Xbox360ControllerAddedNotification object:NULL];
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerRemoved:) name:Xbox360ControllerRemovedNotification object:NULL];
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerActivity:) name:Xbox360ControllerActivityNotification object:NULL];
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerUpdated:) name:Xbox360ControllerUpdatedNotification object:NULL];
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerAction:) name:Xbox360ControllerActionNotification object:NULL];
}

- (void) controllerAdded:(NSNotification*)notification {
  NSLog(@"You added a controller: %@", [notification object]);
}

- (void) controllerRemoved:(NSNotification*)notification {
  NSLog(@"You removed a controller: %@", [notification object]);
}

- (void) controllerActivity:(NSNotification*)notification {
  NSLog(@"You pressed some buttons: %@", [notification object]);
}

- (void) controllerUpdated:(NSNotification*)notification {
  Xbox360Controller *controller = [notification object];
  NSLog(@"Controller updated: %d", controller.leftStickHorizontal);
}

- (void) controllerAction:(NSNotification*)notification {
  NSLog(@"Controller action: %@", [notification object]);
}

@end

If you are a little more low-level adventurous, you can also register to the Xbox360HIDAddedNotification, Xbox360HIDRemovedNotification, and Xbox360HIDActivityNotification after calling [Xbox360HIDManager sharedInstance]. Those will provide you with a IOHIDDeviceRef on activity.

Credits

  • Colin Munro is the genius behind the Mac OS driver routine.
  • Derek van Vliet had an inspiring project that had the same conceptual idea behind it - and the project name :)

License

MIT 2013 funkensturm. See MIT-LICENSE.