Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added acceleration property to GAAccessory

Updated readme
  • Loading branch information...
commit 92a1c94ef1455984bd4f5e49534b094ac6d697fd 1 parent 2e3e19e
Ronald Mannak authored
5 AirGuitarSDK/AirGuitarSDK/AGAccessory.h
View
@@ -8,6 +8,7 @@
#import <Foundation/Foundation.h>
#import <ExternalAccessory/ExternalAccessory.h>
+#import <CoreMotion/CoreMotion.h>
@class AGAccessory;
@@ -18,11 +19,9 @@
@interface AGAccessory : NSObject <NSStreamDelegate>
@property (nonatomic, weak) id <AGAccessoryProtocol> delegate;
-
-// Add XYZ acceleration data
-
@property (nonatomic, strong) EASession *session;
@property (nonatomic, weak) EAAccessory *accessory;
+@property (nonatomic, readonly) CMAcceleration acceleration;
- (id)initWithAccessory: (EAAccessory *)accessory protocol: (NSString *) protocolString;
30 AirGuitarSDK/AirGuitarSDK/AGAccessory.m
View
@@ -63,7 +63,6 @@ - (void)dealloc {
#pragma mark - Setting Air Guitar accessory
-
- (void) enableAccelerometerData:(BOOL)enable{
BoardMessage * message = [BoardMessage analogInLiveEnable:enable];
if ([[_session outputStream] hasSpaceAvailable]) {
@@ -92,22 +91,7 @@ - (void)_writeData {
// low level read method - read data while there is data and space available in the input buffer
- (void)_readData {
-
-/* #define EAD_INPUT_BUFFER_SIZE 128
- uint8_t buf[EAD_INPUT_BUFFER_SIZE];
- while ([[_session inputStream] hasBytesAvailable])
- {
- NSInteger bytesRead = [[_session inputStream] read:buf maxLength:EAD_INPUT_BUFFER_SIZE];
- if (_readData == nil) {
- _readData = [[NSMutableData alloc] init];
- }
- [_readData appendBytes:(void *)buf length:bytesRead];
- //NSLog(@"read %d bytes from input stream", bytesRead);
- }
- DLog(@"reading data: %@", _readData); */
-
-
-
+
u_int8_t buffer[MAX_MESSAGE_LENGTH];
NSInteger length = 0;
BoardMessage *message;
@@ -156,11 +140,12 @@ - (void) parseAccessoryAcceleremeterMessage: (BoardMessage *) message {
channelNumber = [boardMessage getByte:dataIndex++];
z=([boardMessage getByte:dataIndex++]<<8) + [boardMessage getByte:dataIndex++];
- float rawX =(x-512.f)/64.f;
- float rawY =(y-512.f)/64.f;
- float rawZ =(z-512.f)/64.f;
+ // Store raw acceleration data in struct
+ _acceleration.x = (x-512.f)/64.f;
+ _acceleration.y = (y-512.f)/64.f;
+ _acceleration.z = (z-512.f)/64.f;
- [_delegate accessory: self x: rawX y:rawY z:rawZ];
+ [_delegate accessory: self x: _acceleration.x y:_acceleration.y z:_acceleration.z];
}
}
@@ -192,5 +177,6 @@ - (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode
@synthesize delegate = _delegate,
session = _session,
- accessory = _accessory;
+ accessory = _accessory,
+ acceleration = _acceleration;
@end
2  AirGuitarSDK/AirGuitarSDK/AGAccessoryManager.m
View
@@ -33,7 +33,7 @@ - (id)init {
_connectedAGAccessories = [[NSMutableDictionary alloc] initWithCapacity:3];
_compatibleProtocolStrings = [NSArray arrayWithObjects: AG_PROTOCOL_STRING, nil]; // Future addition
- // Check if an Air Guitar compatible device is already connected
+ // We don't receive a notification if Air Guitar Move was already connected when the app started or view was loaded, so check for already connected accessories
for (EAAccessory *connectedAccessory in [EAAccessoryManager sharedAccessoryManager].connectedAccessories) {
if ([[connectedAccessory protocolStrings] containsObject:AG_PROTOCOL_STRING]) {
2  AirGuitarSDK/AirGuitarSDK/BoardMessage.h
View
@@ -52,7 +52,7 @@
+ (id) analogInEnable: (u_int8_t) analogInEnableValues;
+ (id) counterLimit: (int) limit;
-- (u_int8_t) writeBytesToMessage: (u_int8_t *)bytesToWrite :(u_int8_t)numBytes;
+//- (u_int8_t) writeBytesToMessage: (u_int8_t *)bytesToWrite :(u_int8_t)numBytes;
- (u_int8_t) length;
- (void) buildMessage: (u_int8_t) d ;
BIN  ...SDKDemo.xcodeproj/project.xcworkspace/xcuserdata/ronaldmannak.xcuserdatad/UserInterfaceState.xcuserstate
View
Binary file not shown
212 readme.md
View
@@ -1,159 +1,149 @@
-Air Guitar SDK -
+Air Guitar SDK for Air Guitar Move
===
-## What it does
-The Made for iPhone accessory Air Guitar Move was developed for the Air Guitar Move game. I received many requests from developers to use the Air Guitar Move hardware. Before submitting apps using Air Guitar SDK to the App Store, see note below.
+## What's new
+
+###1.1 (August 10, 2012)
+* Added acceleration property to AGAccessory (of type CMAccelerometer) as alternative to delegate
+* Corrected error in read me (thanks [Alex](https://github.com/minichrispy)!)
-## Features
-* Handles connecting and deconnecting Air Guitar accessories
+###1.0 (iOSDevCamp San Jose, CA July 22, 2012)
+* Handles connecting and disconnecting Air Guitar accessories
* Sends raw accelerometer data to your app
-## Todo
-* high pass and low pass filters
-* predefined air guitar motions
+## What it does
+
+![](http://www.airguitarmove.com/images/github/airguitar.png)
+In the summer of 2012 we launched Air Guitar Move, a rhythm game and iPhone accessory. I received many requests from developers who wanted to use the Air Guitar Move hardware in their own apps and games. With Air Guitar SDK it's now possible to add support for the Air Guitar Move hardware to any app.
+
+Before submitting to the App Store, please see the note below.
##System Requirements
-* Air Guitar Move accessory. If you don't have one, see our [online store](https://www.wepay.com/stores/airguitar)
+* Air Guitar Move accessory. ([Buy online](https://www.wepay.com/stores/airguitar))
* iOS 4 or higher for using the library in you apps
* iOS 5 to run the included demo app
-## How to use it
-### iOS
+## Building the Demo App
-#### Demo app:
-* Open AirGuitarSDKDemo.xcodeproj and build the app for iPhone or iPod touch. Make sure AirGuitarSDKDemo is selected in the scheme selection (and not AirGuitarSDK).
+Open AirGuitarSDKDemo.xcodeproj and build the app for iPhone or iPod touch. Make sure AirGuitarSDKDemo is selected in the scheme selection (and not AirGuitarSDK).
-#### Using AirGuitarSDK in your own projects:
-* By building the demo app in the previous step, libAirGuitarSDK.a was be created in AirGuitarSDK.xproj -> Products (see Xcode Project Navigator). In case the file is red, repeat previous step.
+![](http://www.airguitarmove.com/images/github/builddemo.png)
-* Either create a new project, open an existing project.
+## Using AirGuitarSDK in your own projects:
+Before you start you will need:
-* Drag libAirGuitarSDK.a to your project and make sure libAirGuitarSDK.a is listed in your Project -> Target -> Link Binary With Libraries
+* libAirGuitarSDK.a (created in AirGuitarSDK.xproj -> Products. See Building the Demo App above. If the filename is red, repeat building the demo app)
+* AirGuitarSDK.h, AGAccessory.h and AGAccessoryManager.h (AirGuitarSDK -> frameworks)
-* Press the + sign in the Link Binary With Libraries and add ExternalAccessory.framework
+![Create libAirGuitarSDK.a and locate header files](http://www.airguitarmove.com/images/github/products.png)
-* Drag AirGuitarSDK.h, AGAccessory.h and AGAccessoryManager.h (under Framworks) to your project. (You don't need to copy AGMotionManager.h , that is still a work in progress)
+1. Add libAirGuitarSDK.a to your project by dragging the file from the demo project to your project.
-* Go to Project -> Target -> Info. Right click anywhere in the list and Add Row. Enter 'Supported External Accessory Protocol' and add 'com.yobble.me' as protocol
+ ![Add libAirGuitarSDK.a](http://www.airguitarmove.com/images/github/libairguitar.png)
-#### Adding code in a view controller
+* Add Apple's ExternalAccessory.framework to your project by going to Project -> Target -> Link Binary With Libraries and press the + button (note that libAirGuitarSDK.a we added in step 1 should also listed here)
-(See AGViewController for example code)
+ ![Add ExternalAccessory.framework](http://www.airguitarmove.com/images/github/externalframework.png)
-* Handling connecting and deconnecting accessories:
-AirGuitarSDK sends notifications when an Air Guitar compatible accessory connects and disconnects. In case an Air Guitar accessory was already connected before the view loaded or app started, we need to check the already connected devices in viewDidLoad or init.
-
-* Getting accelerometer data:
-Set delegate of AGAccessory to view controller t
+* Drag AirGuitarSDK.h, AGAccessory.h and AGAccessoryManager.h (under Framworks) to your project. (You don't need to copy AGMotionManager.h , that is still a work in progress)
-In header file or class extension:
-@property (nonatomic, strong) AGAccessoryManager *airGuitarManager;
+ ![Add header files to project](http://www.airguitarmove.com/images/github/headerfiles.png)
-In .m file:
+* Edit the info.plist by going to Project -> Target -> Info. Right click anywhere in the list and Add Row. Enter 'Supported External Accessory Protocol' and add 'com.yobble.airguitar' as protocol
-@synthesize airGuitarManager = _airGuitarManager;
+ ![Add Supported External Accessory Protocol in info.plist](http://www.airguitarmove.com/images/github/protocol1.png)
+ ![Add com.yobble.airguitar to Supported External Accessory Protocol](http://www.airguitarmove.com/images/github/protocol2.png)
-- (void)viewDidLoad {
- [super viewDidLoad];
-
- // Set up Air Guitar accessory
- _airGuitarManager = [AGAccessoryManager sharedAccessoryManager];
+* Add delegate and notification observer in your code
+
+ Your app needs to implement:
+ 1. A delegate to receive accelerometer data from Air Guitar Move
+ 2. A notification observer to receive connect and disconnect notifications
-}
+ In header file or class extension:
+
+ @property (nonatomic, strong) AGAccessoryManager *airGuitarManager;
-- (void)viewWillAppear:(BOOL)animated {
+ In .m file (e.g. ViewController or AppDelegate):
- // Handling connecting and deconnecting accessories
-
- // Receive notifications when Air Guitar connects or deconnects
- _airGuitarManager.shouldSendNotifications = YES;
-
- // Check if Air Guitar Move compatible devices are already connected
- if ([_airGuitarManager.connectedAGAccessories count]) {
- NSArray *accessories = [_airGuitarManager.connectedAGAccessories allValues];
- for (AGAccessory *accessory in accessories) {
- accessory.delegate = self;
- }
- }
+ - (void)viewDidLoad {
+ [super viewDidLoad];
- // Register for Air Guitar connect and disconnect notifications
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accessoryDidConnect:) name:@"AGAccessoryDidConnect" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accessoryDidDisconnect:) name:@"AGAccessoryDidDisconnect" object:nil];
-}
+ // Set up Air Guitar accessory
+ _airGuitarManager = [AGAccessoryManager sharedAccessoryManager];
+ }
-- (void)viewWillDisappear:(BOOL)animated {
+ - (void)viewWillAppear:(BOOL)animated {
+
+ // Receive notifications when Air Guitar connects or disconnects
+ _airGuitarManager.shouldSendNotifications = YES;
- _iPhoneAccelerometer.delegate = nil;
- if ([_airGuitarManager.connectedAGAccessories count]) {
- NSArray *accessories = [_airGuitarManager.connectedAGAccessories allValues];
-
- for (AGAccessory *accessory in accessories) {
- accessory.delegate = nil;
- }
- }
+ // We don't receive a notification if Air Guitar Move was already connected when the app started or view was loaded,
+ // so check for already connected accessories
+
+ if ([_airGuitarManager.connectedAGAccessories count]) {
+ NSArray *accessories = [_airGuitarManager.connectedAGAccessories allValues];
+ for (AGAccessory *accessory in accessories) {
+ accessory.delegate = self;
+ }
+ }
- [[NSNotificationCenter defaultCenter] removeObserver:self];
+ // Register for Air Guitar connect and disconnect notifications
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(accessoryDidConnect:)
+ name:@"AGAccessoryDidConnect"
+ object:nil];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(accessoryDidDisconnect:)
+ name:@"AGAccessoryDidDisconnect"
+ object:nil];
+ }
+
+ - (void)viewWillDisappear:(BOOL)animated {
-}
+ if ([_airGuitarManager.connectedAGAccessories count]) {
+ NSArray *accessories = [_airGuitarManager.connectedAGAccessories allValues];
+ for (AGAccessory *accessory in accessories) accessory.delegate = nil;
+ }
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ }
-- (void) accessory: (AGAccessory *) accessory x: (double) x y: (double) y z: (double) z {
+ #pragma mark - Air Guitar Delegate
- // delegate method gets called every time the iPhone receives data from the Air Guitar accessory. Raw data only for now.
-
- NSLog(@"%f, %f, %f", x, y, z);
-}
+ - (void) accessory: (AGAccessory *)accessory x:(double)x y:(double)y z:(double)z {
-// ------------------------------------
-#pragma mark - Air Guitar Notifications
+ // delegate method gets called every time the iPhone receives data from the Air Guitar accessory.
+
+ NSLog(@"%f, %f, %f", x, y, z);
+ }
-- (void)accessoryDidConnect: (NSNotification *)notification {
-
- AGAccessory *connectedAccessory = (AGAccessory *) notification.object;
- connectedAccessory.delegate = self;
-}
+ #pragma mark - Air Guitar Notifications
-- (void)accessoryDidDisconnect: (NSNotification *)notification {
+ - (void)accessoryDidConnect: (NSNotification *)notification {
+ AGAccessory *connectedAccessory = (AGAccessory *) notification.object;
+ connectedAccessory.delegate = self;
+ }
- // Do something, like pause the game
-}
+ - (void)accessoryDidDisconnect: (NSNotification *)notification {
+ // Air Guitar was disconnected, pause the game
+ }
+## Problems & Bugs
+Air Guitar SDK was built in one weekend at the iOSDevCamp hackathon. There will be bugs. Please use the [Github Issue tracker](https://github.com/ronaldmannak/AirGuitarSDK/issues) to commit bugs.
-#### Android
-Go to shop. Buy iPhone. Air Guitar SDK is iPhone and iPod touch only for now.
+## Author and Contributors
+Air Guitar SDK was developed at [iOSDevCamp 2012](http://iodevcamp.org) in San Jose by [Ronald Mannak](https://github.com/ronaldmannak)
+BoardMessage code by [Colin Karpfinger](https://github.com/colinkarpfinger)
-#### Commodore 64
-Change Project -> Build Settings -> Architectures setting to MOS 6502
-Force Air Guitar accessory in any port
-Enter:
-10 PRINT "Air Guitar is working. Really"
-20 PRINT INT(RND(1)*10)
-30 GOTO 20
+## Used in
+* DogFight (iOS game developed by [Sage Herron](https://github.com/Drekknni) at [iOSDevCamp 2012](http://iodevcamp.org))
-#### ZX Spectrum
-Change Project -> Build Settings -> Architectures setting to Z80A
-Force Air Guitar accessory in any port
-Enter:
-10 PRINT "Air Guitar is working. Really"
-20 PRINT RND*10
-30 GOTO 20
+## BEFORE SUBMITTING YOUR APP TO THE APP STORE
-## Problems & Bugs
-Air Guitar SDK was built in one weekend at the iOSDevCamp hackathon. There will be bugs.Please use the [Github Issue tracker](https://github.com/ronaldmannak/AirGuitarSDK/issues) to commit bugs
+You can use Air Guitar SDK in any way you like. However, Apple might have additional requirements when submitting an Air Guitar enabled app to the App Store, such as that your app must be a guitar app. Please contact the author before submitting apps.
## License
Air Guitar SDK is licensed under the [Apache Software License, 2.0 ("Apache 2.0")](http://www.apache.org/licenses/LICENSE-2.0)
-## Author
-Air Guitar SDK was developed at [iOSDevCamp 2012](http://iodevcamp.org) in San Jose by [Ronald Mannak](https://github.com/ronaldmannak)
-
-## Contributors
-BoardMessage code by [Colin Karpfinger](https://github.com/colinkarpfinger)
-
-## Used by
-* DogFight (iOS game developed at [iOSDevCamp 2012](http://iodevcamp.org)
-* Soon to used in Air Guitar Move game, our original Air Guitar Game
-
-## IMPORTANT NOTICE BEFORE SUBMITTING YOUR APP TO THE APP STORE
-You are free to use Air Guitar SDK in any developer version of your app. No third party apps using Air Guitar SDK have been submitted to the App Store yet, and there is no guarantee Apple will approve apps using the SDK. Please contact the author before submitting apps.
-
Please sign in to comment.
Something went wrong with that request. Please try again.